-
-
Notifications
You must be signed in to change notification settings - Fork 86
Add CLI and listeners to reverse geocode pictures' coordinates #1310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,19 +23,11 @@ | |
|
|
||
| namespace OCA\Photos\Album; | ||
|
|
||
| use OC\Metadata\FileMetadata; | ||
| use OCA\Photos\DB\PhotosFile; | ||
|
|
||
| class AlbumFile { | ||
| private int $fileId; | ||
| private string $name; | ||
| private string $mimeType; | ||
| private int $size; | ||
| private int $mtime; | ||
| private string $etag; | ||
| class AlbumFile extends PhotosFile { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review hint: extracted to |
||
| private int $added; | ||
| private string $owner; | ||
| /** @var array<string, FileMetadata> */ | ||
| private array $metaData = []; | ||
|
|
||
| public function __construct( | ||
| int $fileId, | ||
|
|
@@ -47,52 +39,19 @@ public function __construct( | |
| int $added, | ||
| string $owner | ||
| ) { | ||
| $this->fileId = $fileId; | ||
| $this->name = $name; | ||
| $this->mimeType = $mimeType; | ||
| $this->size = $size; | ||
| $this->mtime = $mtime; | ||
| $this->etag = $etag; | ||
| parent::__construct( | ||
| $fileId, | ||
| $name, | ||
| $mimeType, | ||
| $size, | ||
| $mtime, | ||
| $etag | ||
| ); | ||
|
|
||
| $this->added = $added; | ||
| $this->owner = $owner; | ||
| } | ||
|
|
||
| public function getFileId(): int { | ||
| return $this->fileId; | ||
| } | ||
|
|
||
| public function getName(): string { | ||
| return $this->name; | ||
| } | ||
|
|
||
| public function getMimeType(): string { | ||
| return $this->mimeType; | ||
| } | ||
|
|
||
| public function getSize(): int { | ||
| return $this->size; | ||
| } | ||
|
|
||
| public function getMTime(): int { | ||
| return $this->mtime; | ||
| } | ||
|
|
||
| public function getEtag(): string { | ||
| return $this->etag; | ||
| } | ||
|
|
||
| public function setMetadata(string $key, FileMetadata $value): void { | ||
| $this->metaData[$key] = $value; | ||
| } | ||
|
|
||
| public function hasMetadata(string $key): bool { | ||
| return isset($this->metaData[$key]); | ||
| } | ||
|
|
||
| public function getMetadata(string $key): FileMetadata { | ||
| return $this->metaData[$key]; | ||
| } | ||
|
|
||
| public function getAdded(): int { | ||
| return $this->added; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
| /** | ||
| * @copyright Copyright (c) 2022 Louis Chemineau <louis@chmn.me> | ||
| * | ||
| * @author Louis Chemineau <louis@chmn.me> | ||
| * | ||
| * @license AGPL-3.0-or-later | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
| namespace OCA\Photos\Command; | ||
|
|
||
| use OCP\IConfig; | ||
| use OCP\IUserManager; | ||
| use OCP\Files\IRootFolder; | ||
| use OCP\Files\Folder; | ||
| use OCA\Photos\Service\MediaLocationManager; | ||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Input\InputOption; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| class MapMediaToLocationCommand extends Command { | ||
| public function __construct( | ||
| private IRootFolder $rootFolder, | ||
| private MediaLocationManager $mediaLocationManager, | ||
| private IConfig $config, | ||
| private IUserManager $userManager, | ||
| ) { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| /** | ||
| * Configure the command | ||
| */ | ||
| protected function configure(): void { | ||
| $this->setName('photos:map-media-to-location') | ||
| ->setDescription('Reverse geocode media coordinates.') | ||
| ->addOption('user', 'u', InputOption::VALUE_REQUIRED, 'Limit the mapping to a user.', null); | ||
| } | ||
|
|
||
| /** | ||
| * Execute the command | ||
| */ | ||
| protected function execute(InputInterface $input, OutputInterface $output): int { | ||
| if (!$this->config->getSystemValueBool('enable_file_metadata', true)) { | ||
| throw new \Exception('File metadata is not enabled.'); | ||
| } | ||
|
|
||
| $userId = $input->getOption('user'); | ||
| if ($userId === null) { | ||
| $this->scanForAllUsers($output); | ||
| } else { | ||
| $this->scanFilesForUser($userId, $output); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| private function scanForAllUsers(OutputInterface $output): void { | ||
| $users = $this->userManager->search(''); | ||
|
|
||
| $output->writeln("Scanning all users:"); | ||
| foreach ($users as $user) { | ||
| $this->scanFilesForUser($user->getUID(), $output); | ||
| } | ||
| } | ||
|
|
||
| private function scanFilesForUser(string $userId, OutputInterface $output): void { | ||
| $userFolder = $this->rootFolder->getUserFolder($userId); | ||
| $output->write(" - Scanning files for $userId"); | ||
| $startTime = time(); | ||
| $count = $this->scanFolder($userFolder); | ||
| $timeElapse = time() - $startTime; | ||
| $output->writeln(" - $count files, $timeElapse sec"); | ||
| } | ||
|
|
||
| private function scanFolder(Folder $folder): int { | ||
| $count = 0; | ||
|
|
||
| // Do not scan share and other moveable mounts. | ||
| if ($folder->getMountPoint() instanceof \OC\Files\Mount\MoveableMount) { | ||
| return $count; | ||
| } | ||
|
|
||
| foreach ($folder->getDirectoryListing() as $node) { | ||
| if ($node instanceof Folder) { | ||
| $count += $this->scanFolder($node); | ||
| continue; | ||
| } | ||
|
|
||
| if (!str_starts_with($node->getMimeType(), 'image')) { | ||
| continue; | ||
| } | ||
|
|
||
| $this->mediaLocationManager->setLocationForFile($node->getId()); | ||
| $count++; | ||
| } | ||
|
|
||
| return $count; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.