Updates for Videos

This commit is contained in:
Deon George
2019-12-15 23:34:42 +11:00
parent 075d31e9f4
commit 49933382f3
14 changed files with 376 additions and 254 deletions

View File

@@ -2,17 +2,16 @@
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;
use App\Models\{Person,Video,Tag};
use App\Traits\Files;
class VideoImport extends Command
{
use DispatchesJobs;
use \App\Traits\Files;
use Files;
/**
* The name and signature of the console command.
@@ -52,7 +51,11 @@ class VideoImport extends Command
*/
public function handle()
{
$files = $this->getFiles(['dir'=>$this->option('dir'),'file'=>$this->option('file')],'video');
$files = $this->getFiles([
'dir'=>$this->option('dir'),
'file'=>$this->option('file')
],'video');
if (! count($files))
exit;
@@ -64,22 +67,21 @@ class VideoImport extends Command
$t = $p = array();
// Tags
if ($this->option('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))
{
if (! $t OR count($t) != count($tags)) {
$this->error(sprintf('Tag [%s] dont exist',join('|',$tags)));
abort(501);
}
}
// People
if ($this->option('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)));
@@ -88,18 +90,15 @@ class VideoImport extends Command
}
$c = 0;
foreach ($files as $file)
{
foreach ($files as $file) {
$bar->advance();
if (preg_match('/@__thumb/',$file) OR preg_match('/\/._/',$file))
{
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')))
{
if (! in_array(strtolower(pathinfo($file,PATHINFO_EXTENSION)),config('video.import.accepted'))) {
$this->warn(sprintf('Ignoring [%s]',$file));
continue;
}
@@ -111,21 +110,21 @@ class VideoImport extends Command
$o = Video::where('filename',$file)->first();
if (is_null($o))
{
// The video doesnt exist
if (is_null($o)) {
$o = new Video;
$o->filename = $file;
}
if (! is_readable($o->file_path()))
{
if ($o->exists)
$this->warn(sprintf('%s [%s] already in DB: %s',$o->objectType(),$file,$o->id));
// Make sure we can read the video.
if (! is_readable($o->file_path())) {
$this->warn(sprintf('Ignoring [%s], it is not readable',$o->file_path()));
continue;
}
if ($o->exists)
$this->warn(sprintf('%s [%s] already in DB: %s',$o->objectType(),$file,$o->id));
$o->save();
if ($o->wasRecentlyCreated)