summaryrefslogtreecommitdiff
path: root/app/Console/Commands/ScrapeYoutube.php
diff options
context:
space:
mode:
authorFbenas <philbeansburton@gmail.com>2020-06-19 21:05:19 +0100
committerFbenas <philbeansburton@gmail.com>2020-06-19 21:05:19 +0100
commit897b68ac107f2fb0d4dc1d31ce96ce24c862eb27 (patch)
tree04afb344930042e15db812641592d7187456ea8f /app/Console/Commands/ScrapeYoutube.php
parentd1fe4536cc039450b540104e382db0d01d5cf886 (diff)
Add youtube video and audio scraping commands
Diffstat (limited to 'app/Console/Commands/ScrapeYoutube.php')
-rw-r--r--app/Console/Commands/ScrapeYoutube.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/app/Console/Commands/ScrapeYoutube.php b/app/Console/Commands/ScrapeYoutube.php
new file mode 100644
index 0000000..ce64d3f
--- /dev/null
+++ b/app/Console/Commands/ScrapeYoutube.php
@@ -0,0 +1,57 @@
+<?php
+
+namespace App\Console\Commands;
+
+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');
+ $format = $this->argument('format');
+
+ $service = new Service($url, $this->output);
+
+ if ($format == 'video') {
+ $video = $service->downloadVideo('video');
+ } elseif ($format == 'audio') {
+ $video = $service->downloadAudio('audio');
+ }
+
+ $this->info('Download of ' . $video->getTitle() . ' complete!');
+
+ return Command::SUCCESS;
+ }
+
+}