Skip to content

Commit

Permalink
Update album takestamps (#745)
Browse files Browse the repository at this point in the history
* Update album min/max takestamps

* Clean up selection criteria and diagnostics

* Don't duplicate the takedate functionality
  • Loading branch information
kamil4 authored Oct 7, 2020
1 parent 174c910 commit fa21ad8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 43 deletions.
39 changes: 28 additions & 11 deletions app/Console/Commands/ExifLens.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ public function handle()
set_time_limit($timeout);

// we use lens because this is the one which is most likely to be empty.
$photos = Photo::where('lens', '=', '')->whereNotIn('lens', $this->photoFunctions->getValidVideoTypes())->offset($from)->limit($argument)->get();
$photos = Photo::where('lens', '=', '')
->whereNotIn('type', $this->photoFunctions->getValidVideoTypes())
->offset($from)
->limit($argument)
->get();
if (count($photos) == 0) {
$this->line('No pictures requires EXIF updates.');

Expand All @@ -75,32 +79,45 @@ public function handle()
$url = Storage::path('big/' . $photo->url);
if (file_exists($url)) {
$info = $this->metadataExtractor->extract($url, $photo->type);
if ($photo->size == '') {
$updated = false;
if ($photo->size == '' && $info['size'] != '') {
$photo->size = $info['size'];
$updated = true;
}
if ($photo->iso == '') {
if ($photo->iso == '' && $info['iso'] != '') {
$photo->iso = $info['iso'];
$updated = true;
}
if ($photo->aperture == '') {
if ($photo->aperture == '' && $info['aperture'] != '') {
$photo->aperture = $info['aperture'];
$updated = true;
}
if ($photo->make == '') {
if ($photo->make == '' && $info['make'] != '') {
$photo->make = $info['make'];
$updated = true;
}
if ($photo->getAttribute('model') == '') {
if ($photo->getAttribute('model') == '' && $info['model'] != '') {
$photo->setAttribute('model', $info['model']);
$updated = true;
}
if ($photo->lens == '') {
if ($photo->lens == '' && $info['lens'] != '') {
$photo->lens = $info['lens'];
$updated = true;
}
if ($photo->shutter == '') {
if ($photo->shutter == '' && $info['shutter'] != '') {
$photo->shutter = $info['shutter'];
$updated = true;
}
if ($photo->focal == '') {
if ($photo->focal == '' && $info['focal'] != '') {
$photo->focal = $info['focal'];
$updated = true;
}
if ($photo->save()) {
$this->line($i . ': EXIF updated for ' . $photo->title);
if ($updated) {
if ($photo->save()) {
$this->line($i . ': EXIF updated for ' . $photo->title);
} else {
$this->line($i . ': Failed to update EXIF for ' . $photo->title);
}
} else {
$this->line($i . ': Could not get EXIF data/nothing to update for ' . $photo->title . '.');
}
Expand Down
29 changes: 12 additions & 17 deletions app/Console/Commands/Takedate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Console\Commands;

use App\Metadata\Extractor;
use App\ModelFunctions\PhotoFunctions;
use App\ModelFunctions\AlbumActions\UpdateTakestamps as AlbumUpdate;
use App\Models\Photo;
use Illuminate\Console\Command;
use Storage;
Expand All @@ -24,11 +24,6 @@ class Takedate extends Command
*/
protected $description = 'Make sure takedate is correct';

/**
* @var PhotoFunctions
*/
private $photoFunctions;

/**
* @var Extractor
*/
Expand All @@ -37,14 +32,12 @@ class Takedate extends Command
/**
* Create a new command instance.
*
* @param PhotoFunctions $photoFunctions
* @param Extractor $metadataExtractor
* @param Extractor $metadataExtractor
*/
public function __construct(PhotoFunctions $photoFunctions, Extractor $metadataExtractor)
public function __construct(Extractor $metadataExtractor)
{
parent::__construct();

$this->photoFunctions = $photoFunctions;
$this->metadataExtractor = $metadataExtractor;
}

Expand All @@ -60,8 +53,7 @@ public function handle()
$timeout = $this->argument('tm');
set_time_limit($timeout);

// we use lens because this is the one which is most likely to be empty.
$photos = Photo::where('make', '=', '')->whereNotIn('lens', $this->photoFunctions->getValidVideoTypes())->offset($from)->limit($argument)->get();
$photos = Photo::whereNull('takestamp')->offset($from)->limit($argument)->get();
if (count($photos) == 0) {
$this->line('No pictures requires takedate updates.');

Expand All @@ -73,13 +65,16 @@ public function handle()
$url = Storage::path('big/' . $photo->url);
if (file_exists($url)) {
$info = $this->metadataExtractor->extract($url, $photo->type);
if ($photo->takestamp == '') {
if ($info['takestamp'] != null) {
$photo->takestamp = $info['takestamp'];
}
if ($photo->save()) {
$this->line($i . ': Takestamp updated for ' . $photo->title);
if ($photo->save()) {
$this->line($i . ': Takestamp updated for ' . $photo->title);
AlbumUpdate::update_takestamps($photo->album, [$photo->takestamp], true);
} else {
$this->line($i . ': Failed to update takestamp for ' . $photo->title);
}
} else {
$this->line($i . ': Could not get Takestamp data/nothing to update for ' . $photo->title . '.');
$this->line($i . ': Could not get Takestamp data for ' . $photo->title . '.');
}
} else {
$this->line($i . ': File does not exist for ' . $photo->title . '.');
Expand Down
35 changes: 20 additions & 15 deletions app/Console/Commands/VideoData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Metadata\Extractor;
use App\ModelFunctions\PhotoFunctions;
use App\Models\Logs;
use App\Models\Photo;
use Illuminate\Console\Command;
use Storage;
Expand Down Expand Up @@ -67,7 +66,7 @@ public function handle()
)
);

$photos = Photo::where('type', 'like', 'video/%')
$photos = Photo::whereIn('type', $this->photoFunctions->getValidVideoTypes())
->where('width', '=', 0)
->take($this->argument('count'))
->get();
Expand All @@ -87,7 +86,7 @@ public function handle()
if (file_exists($thumb)) {
$urlBase = explode('.', $photo->url);
$thumbBase = explode('.', $photo->thumbUrl);
if ($urlBase !== $thumbBase) {
if ($urlBase[0] !== $thumbBase[0]) {
$photo->thumbUrl = $urlBase[0] . '.' . $thumbBase[1];
rename($thumb, Storage::path('thumb/') . $photo->thumbUrl);
$this->line('Renamed thumb to match the video file');
Expand All @@ -98,41 +97,47 @@ public function handle()
if (file_exists($url)) {
$info = $this->metadataExtractor->extract($url, $photo->type);

if ($info['width'] !== 0) {
$this->line('Extracted metadata');
$updated = false;
if ($photo->width == 0 && $info['width'] !== 0) {
$photo->width = $info['width'];
$updated = true;
}
if ($info['height'] !== 0) {
if ($photo->height == 0 && $info['height'] !== 0) {
$photo->height = $info['height'];
$updated = true;
}
if ($info['focal'] !== '') {
if ($photo->focal == '' && $info['focal'] !== '') {
$photo->focal = $info['focal'];
$updated = true;
}
if ($info['aperture'] !== '') {
if ($photo->aperture == '' && $info['aperture'] !== '') {
$photo->aperture = $info['aperture'];
$updated = true;
}
if ($info['takestamp'] !== null) {
$photo->takestamp = $info['takestamp'];
}
if ($info['latitude'] !== null) {
if ($photo->latitude == null && $info['latitude'] !== null) {
$photo->latitude = $info['latitude'];
$updated = true;
}
if ($info['longitude'] !== null) {
if ($photo->longitude == null && $info['longitude'] !== null) {
$photo->longitude = $info['longitude'];
$updated = true;
}
if ($updated) {
$this->line('Updated metadata');
}

if ($photo->thumbUrl === '' || $photo->thumb2x === 0 || $photo->small === '' || $photo->small2x === '') {
$frame_tmp = '';
try {
$frame_tmp = $this->photoFunctions->extractVideoFrame($photo);
} catch (\Exception $exception) {
Logs::error(__METHOD__, __LINE__, $exception->getMessage());
$this->line($exception->getMessage());
}
if ($frame_tmp !== '') {
$this->line('Extracted video frame for thumbnails');
if ($photo->thumbUrl === '' || $photo->thumb2x === 0) {
if (!$this->photoFunctions->createThumb($photo, $frame_tmp)) {
Logs::error(__METHOD__, __LINE__, 'Could not create thumbnail for video');
$this->line('Could not create thumbnail for video');
}
$urlBase = explode('.', $photo->url);
$photo->thumbUrl = $urlBase[0] . '.jpeg';
Expand Down

0 comments on commit fa21ad8

Please sign in to comment.