Added Video
This commit is contained in:
@@ -10,7 +10,7 @@ use App\Model\Photo;
|
||||
use App\Model\PhotoTag;
|
||||
use App\Model\Tag;
|
||||
|
||||
class Import extends Command
|
||||
class PhotoImport extends Command
|
||||
{
|
||||
use \App\Traits\Files;
|
||||
|
||||
@@ -51,7 +51,7 @@ class Import extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$files = $this->getFiles(['dir'=>$this->option('dir'),'file'=>$this->option('file')]);
|
||||
$files = $this->getFiles(['dir'=>$this->option('dir'),'file'=>$this->option('file')],'photo');
|
||||
if (! count($files))
|
||||
exit;
|
||||
|
||||
@@ -106,6 +106,12 @@ class Import extends Command
|
||||
$po->filename = $file;
|
||||
}
|
||||
|
||||
if (! is_readable($po->file_path()))
|
||||
{
|
||||
$this->warn(sprintf('Ignoring [%s], it is not readable',$po->file_path()));
|
||||
continue;
|
||||
}
|
||||
|
||||
$po->date_taken = strtotime($po->property('exif:DateTime') ? $po->property('exif:DateTime') : $po->property('exif:DateTimeOriginal'));
|
||||
$po->subsectime = $po->property('exif:SubSecTimeOriginal');
|
||||
|
@@ -7,7 +7,7 @@ use Log;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Model\Photo;
|
||||
|
||||
class Move extends Command
|
||||
class PhotoMove extends Command
|
||||
{
|
||||
use \App\Traits\Files;
|
||||
|
||||
@@ -66,35 +66,35 @@ class Move extends Command
|
||||
$bar->setRedrawFrequency(100);
|
||||
|
||||
$po->chunk(1,function($photo) use ($bar) {
|
||||
while ($po = $photo->shift())
|
||||
while ($o = $photo->shift())
|
||||
{
|
||||
if (($x = $po->moveable()) === TRUE) {
|
||||
Log::info(sprintf('%s: Moving (%s)[%s]',__METHOD__,$po->id,$po->filename));
|
||||
if (($x = $o->moveable()) === TRUE) {
|
||||
Log::info(sprintf('%s: Moving (%s)[%s]',__METHOD__,$o->id,$o->filename));
|
||||
|
||||
if ($this->makeParentDir(dirname($po->file_path(FALSE,TRUE))) AND rename($po->file_path(),$po->file_path(FALSE,TRUE)))
|
||||
if ($this->makeParentDir(dirname($o->file_path(FALSE,TRUE))) AND rename($o->file_path(),$o->file_path(FALSE,TRUE)))
|
||||
{
|
||||
// Convert the path to a relative one.
|
||||
$po->filename = $po->file_path(TRUE,TRUE);
|
||||
$o->filename = $o->file_path(TRUE,TRUE);
|
||||
|
||||
// @todo If the DB update failed, move it back.
|
||||
if (! $po->save()) # AND ! rename($path,$po->file_path()))
|
||||
if (! $o->save()) # AND ! rename($path,$o->file_path()))
|
||||
{
|
||||
$this->error(sprintf('Save after rename failed for (%s)',$po->id));
|
||||
$this->error(sprintf('Save after rename failed for (%s)',$o->id));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error(sprintf('Rename failed for (%s)',$po->id));
|
||||
$this->error(sprintf('Rename failed for (%s)',$o->id));
|
||||
continue;
|
||||
}
|
||||
|
||||
chmod($po->file_path(),0444);
|
||||
chmod($o->file_path(),0444);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($x > 0)
|
||||
$this->warn(sprintf('Unable to move (%s) [%s] to [%s], moveable returned (%s)',$po->id,$po->file_path(),$po->file_path(FALSE,TRUE),$x));
|
||||
$this->warn(sprintf('Unable to move (%s) [%s] to [%s], moveable returned (%s)',$o->id,$o->file_path(),$o->file_path(FALSE,TRUE),$x));
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ use Log;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Model\Photo;
|
||||
|
||||
class Update extends Command
|
||||
class PhotoUpdate extends Command
|
||||
{
|
||||
use \App\Traits\Files;
|
||||
|
198
app/Console/Commands/VideoImport.php
Normal file
198
app/Console/Commands/VideoImport.php
Normal file
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Log;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Model\Video;
|
||||
use App\Model\Tag;
|
||||
use App\Model\Person;
|
||||
|
||||
class VideoImport extends Command
|
||||
{
|
||||
|
||||
use \App\Traits\Files;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'video:import
|
||||
{--dir= : Directory to Parse}
|
||||
{--file= : File to Import}
|
||||
{--ignoredupe : Ignore duplicate files}
|
||||
{--deletedupe : Delete duplicate files}
|
||||
{--dumpid3 : Dump ID3 data}
|
||||
{--people= : People to reference in video}
|
||||
{--tags= : Add tag to video}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Import videos into the database';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$files = $this->getFiles(['dir'=>$this->option('dir'),'file'=>$this->option('file')],'video');
|
||||
if (! count($files))
|
||||
exit;
|
||||
|
||||
// Show a progress bar
|
||||
$bar = $this->output->createProgressBar(count($files));
|
||||
$bar->setFormat("%current%/%max% [%bar%] %percent:3s%% (%memory%) (%remaining%) ");
|
||||
|
||||
$tags = NULL;
|
||||
$t = $p = array();
|
||||
|
||||
// Tags
|
||||
if ($this->option('tags'))
|
||||
{
|
||||
$tags = explode(',',$this->option('tags'));
|
||||
$t = Tag::whereIn('tag',$tags)->pluck('id')->toArray();
|
||||
if (! $t OR count($t) != count($tags))
|
||||
{
|
||||
$this->error(sprintf('Tag [%s] dont exist',join('|',$tags)));
|
||||
abort(501);
|
||||
}
|
||||
}
|
||||
|
||||
// People
|
||||
if ($this->option('people'))
|
||||
{
|
||||
$tags = explode(',',$this->option('people'));
|
||||
$p = Person::whereIn('tag',$tags)->pluck('id')->toArray();
|
||||
if (! $p OR count($p) != count($tags))
|
||||
{
|
||||
$this->error(sprintf('People [%s] dont exist',join('|',$tags)));
|
||||
abort(501);
|
||||
}
|
||||
}
|
||||
|
||||
$c = 0;
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$bar->advance();
|
||||
|
||||
if (preg_match('/@__thumb/',$file) OR preg_match('/\/._/',$file))
|
||||
{
|
||||
$this->warn(sprintf('Ignoring file [%s]',$file));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! in_array(strtolower(pathinfo($file,PATHINFO_EXTENSION)),config('video.import.accepted')))
|
||||
{
|
||||
$this->warn(sprintf('Ignoring [%s]',$file));
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->option('verbose'))
|
||||
$this->info(sprintf('Processing file [%s]',$file));
|
||||
|
||||
$c++;
|
||||
|
||||
$vo = Video::where('filename',$file)->first();
|
||||
|
||||
if (is_null($vo))
|
||||
{
|
||||
$vo = new Video;
|
||||
$vo->filename = $file;
|
||||
}
|
||||
|
||||
if (! is_readable($vo->file_path()))
|
||||
{
|
||||
$this->warn(sprintf('Ignoring [%s], it is not readable',$vo->file_path()));
|
||||
continue;
|
||||
}
|
||||
|
||||
$vo->date_created = strtotime($vo->property('creationdate'));
|
||||
$vo->signature = $vo->property('signature');
|
||||
|
||||
$vo->make = $vo->property('make');
|
||||
$vo->model = $vo->property('model');
|
||||
|
||||
$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));
|
||||
|
||||
// Record our people and tags
|
||||
if ($p)
|
||||
$vo->People()->sync($p);
|
||||
if ($t)
|
||||
$vo->Tags()->sync($t);
|
||||
|
||||
if ($this->option('dumpid3'))
|
||||
dd($vo->dump());
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
|
||||
return $this->info(sprintf('Video processed: %s',$c));
|
||||
}
|
||||
}
|
113
app/Console/Commands/VideoMove.php
Normal file
113
app/Console/Commands/VideoMove.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use DB;
|
||||
use Log;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Model\Video;
|
||||
|
||||
class VideoMove extends Command
|
||||
{
|
||||
use \App\Traits\Files;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'video:move
|
||||
{--file= : Video File}
|
||||
{--id= : Video ID}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Moves Videos to their new location';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ($this->option('file'))
|
||||
{
|
||||
$vo = Video::notRemove()->notDuplicate()->where('filename',Video::path($this->option('file')));
|
||||
}
|
||||
elseif ($this->option('id'))
|
||||
{
|
||||
$vo = Video::notRemove()->notDuplicate()->where('id',$this->option('id'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$vo = Video::notRemove()->notDuplicate();
|
||||
}
|
||||
|
||||
if (! $vo)
|
||||
exit;
|
||||
|
||||
// Show a progress bar
|
||||
$bar = $this->output->createProgressBar($vo->count());
|
||||
$bar->setFormat("%current%/%max% [%bar%] %percent:3s%% (%memory%) (%remaining%) ");
|
||||
$bar->setRedrawFrequency(100);
|
||||
|
||||
$vo->chunk(1,function($video) use ($bar) {
|
||||
while ($o = $video->shift())
|
||||
{
|
||||
if (($x = $o->moveable()) === TRUE) {
|
||||
Log::info(sprintf('%s: Moving (%s)[%s]',__METHOD__,$o->id,$o->filename));
|
||||
|
||||
$fs = $o->file_size();
|
||||
$ft = $o->file_date('m');
|
||||
if ($this->makeParentDir(dirname($o->file_path(FALSE,TRUE))) AND copy($o->file_path(),$o->file_path(FALSE,TRUE)))
|
||||
{
|
||||
// If the copy worked, remove the original.
|
||||
if (file_exists($o->file_path(FALSE,TRUE)) AND $fs === filesize($o->file_path(FALSE,TRUE)))
|
||||
{
|
||||
touch($o->file_path(FALSE,TRUE),$ft);
|
||||
unlink($o->file_path());
|
||||
}
|
||||
|
||||
// Convert the path to a relative one.
|
||||
$o->filename = $o->file_path(TRUE,TRUE);
|
||||
|
||||
// @todo If the DB update failed, move it back.
|
||||
if (! $o->save()) # AND ! rename($path,$o->file_path()))
|
||||
{
|
||||
$this->error(sprintf('Save after rename failed for (%s)',$o->id));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error(sprintf('Rename failed for (%s)',$o->id));
|
||||
continue;
|
||||
}
|
||||
|
||||
chmod($o->file_path(),0444);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($x > 0)
|
||||
$this->warn(sprintf('Unable to move (%s) [%s] to [%s], moveable returned (%s)',$o->id,$o->file_path(),$o->file_path(FALSE,TRUE),$x));
|
||||
}
|
||||
}
|
||||
|
||||
$bar->advance();
|
||||
});
|
||||
}
|
||||
}
|
@@ -13,9 +13,11 @@ class Kernel extends ConsoleKernel
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
Commands\Import::class,
|
||||
Commands\Move::class,
|
||||
Commands\Update::class,
|
||||
Commands\PhotoImport::class,
|
||||
Commands\PhotoMove::class,
|
||||
Commands\PhotoUpdate::class,
|
||||
Commands\VideoImport::class,
|
||||
Commands\VideoMove::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user