From 9cd0234665ea66dff172d94b9c1b4cb61b1d25b1 Mon Sep 17 00:00:00 2001 From: Fbenas Date: Sun, 21 Jun 2020 17:58:23 +0100 Subject: Improve robustness of all scripts and add more to sync command --- app/Console/Commands/ScrapeYoutube.php | 47 +++++++--------------------------- 1 file changed, 9 insertions(+), 38 deletions(-) (limited to 'app/Console/Commands/ScrapeYoutube.php') diff --git a/app/Console/Commands/ScrapeYoutube.php b/app/Console/Commands/ScrapeYoutube.php index de620d4..b848ecb 100644 --- a/app/Console/Commands/ScrapeYoutube.php +++ b/app/Console/Commands/ScrapeYoutube.php @@ -2,41 +2,15 @@ namespace App\Console\Commands; -use App\Rugby\Model\Video; + use App\Youtube\Service; use Illuminate\Console\Command; class ScrapeYoutube extends Command { - /** - * The name and signature of the console command. - * - * @var string - */ protected $signature = 'scrape:youtube { url } { format }'; - - /** - * The console command description. - * - * @var string - */ protected $description = 'Scrape a youtube for videos'; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } - - /** - * Execute the console command. - * - * @return mixed - */ public function handle() { $url = $this->argument('url'); @@ -44,19 +18,16 @@ class ScrapeYoutube extends Command $service = new Service($url, $this->output); - if ($format == 'video') { - $service->downloadVideo('video'); - } elseif ($format == 'audio') { - $service->downloadAudio('audio'); + if ($service->modelExists($url)) { + $this->info('Video already exists in db'); + return Command::FAILURE; } - $video_model = Video::create( - [ - 'path' => $service->getFullPath() - ] - ); - - $this->info('Download of ' . $service->getTitle() . ' complete!'); + if ($service->createModel($format)) { + $this->info('Download of ' . $service->getTitle() . ' complete!'); + } else { + $this->info(ucfirst($format) . ' file already exists'); + } return Command::SUCCESS; } -- cgit v1.2.3