Optimised scanning and importing
This commit is contained in:
@@ -4,13 +4,14 @@ namespace App\Console\Commands;
|
||||
|
||||
use Log;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use App\Model\Video;
|
||||
use App\Model\Tag;
|
||||
use App\Model\Person;
|
||||
|
||||
class VideoImport extends Command
|
||||
{
|
||||
|
||||
use DispatchesJobs;
|
||||
use \App\Traits\Files;
|
||||
|
||||
/**
|
||||
@@ -108,91 +109,42 @@ class VideoImport extends Command
|
||||
|
||||
$c++;
|
||||
|
||||
$vo = Video::where('filename',$file)->first();
|
||||
$o = Video::where('filename',$file)->first();
|
||||
|
||||
if (is_null($vo))
|
||||
if (is_null($o))
|
||||
{
|
||||
$vo = new Video;
|
||||
$vo->filename = $file;
|
||||
$o = new Video;
|
||||
$o->filename = $file;
|
||||
}
|
||||
|
||||
if (! is_readable($vo->file_path()))
|
||||
if (! is_readable($o->file_path()))
|
||||
{
|
||||
$this->warn(sprintf('Ignoring [%s], it is not readable',$vo->file_path()));
|
||||
$this->warn(sprintf('Ignoring [%s], it is not readable',$o->file_path()));
|
||||
continue;
|
||||
}
|
||||
|
||||
$vo->date_created = strtotime($vo->property('creationdate'));
|
||||
$vo->signature = $vo->property('signature');
|
||||
if ($o->exists)
|
||||
$this->warn(sprintf('%s [%s] already in DB: %s',$o->objectType(),$file,$o->id));
|
||||
|
||||
$vo->make = $vo->property('make');
|
||||
$vo->model = $vo->property('model');
|
||||
$o->save();
|
||||
|
||||
$vo->height = $vo->property('height');
|
||||
$vo->width = $vo->property('width');
|
||||
$vo->type = $vo->property('type');
|
||||
$vo->length = $vo->property('length');
|
||||
$vo->codec = $vo->property('codec');
|
||||
$vo->audiochannels = $vo->property('audiochannels');
|
||||
$vo->channelmode = $vo->property('channelmode');
|
||||
$vo->samplerate = $vo->property('samplerate');
|
||||
|
||||
$vo->gps_lat = $vo->property('gps_lat');
|
||||
$vo->gps_lon = $vo->property('gps_lon');
|
||||
$vo->gps_altitude = $vo->property('gps_altitude');
|
||||
|
||||
// If this is a duplicate
|
||||
$x = Video::whereIN('id',$vo->list_duplicate())->get();
|
||||
if (count($x)) {
|
||||
$skip = FALSE;
|
||||
|
||||
foreach ($x as $o) {
|
||||
// We'll only ignore based on the same signature.
|
||||
if ($vo->signature != $o->signature AND ! $vo->exists)
|
||||
continue;
|
||||
|
||||
if ($this->option('ignoredupe'))
|
||||
{
|
||||
$skip = TRUE;
|
||||
$this->warn(sprintf("Ignoring file [%s], it's the same as [%s] with id %s",$vo->file_path(),$o->filename,$o->id));
|
||||
break;
|
||||
|
||||
}
|
||||
elseif ($this->option('deletedupe') AND ($vo->filename != $o->filename))
|
||||
{
|
||||
$skip = TRUE;
|
||||
$this->error(sprintf("Deleting file [%s], it's the same as [%s] with id %s and signature [%s]\n",$vo->file_path(),$o->filename,$o->id,$vo->signature));
|
||||
unlink($vo->file_path());
|
||||
}
|
||||
}
|
||||
|
||||
if ($skip)
|
||||
continue;
|
||||
|
||||
$vo->duplicate = '1';
|
||||
$this->warn(sprintf('Video [%s] marked as a duplicate',$file));
|
||||
}
|
||||
|
||||
if ($vo->exists)
|
||||
$this->warn(sprintf('Video [%s] already in DB: %s',$file,$vo->id));
|
||||
|
||||
$vo->save();
|
||||
|
||||
if ($vo->wasRecentlyCreated)
|
||||
$this->info(sprintf('Video [%s] stored in DB: %s',$file,$vo->id));
|
||||
if ($o->wasRecentlyCreated)
|
||||
$this->info(sprintf('%s [%s] stored in DB: %s',$o->objectType(),$file,$o->id));
|
||||
|
||||
// Record our people and tags
|
||||
if ($p)
|
||||
$vo->People()->sync($p);
|
||||
$o->People()->sync($p);
|
||||
if ($t)
|
||||
$vo->Tags()->sync($t);
|
||||
$o->Tags()->sync($t);
|
||||
|
||||
$this->dispatch((new \App\Jobs\CatalogScan($o))->onQueue('scan'));
|
||||
|
||||
if ($this->option('dumpid3'))
|
||||
dd($vo->dump());
|
||||
dd($o->dump());
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
|
||||
return $this->info(sprintf('Video processed: %s',$c));
|
||||
return $this->info(sprintf('Videos processed: %s',$c));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user