summaryrefslogtreecommitdiff
path: root/app/Console/Commands/ScrapeYoutube.php
blob: b848ecb5c056ec412c2312afcb7b4e6a3294d122 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

namespace App\Console\Commands;


use App\Youtube\Service;
use Illuminate\Console\Command;

class ScrapeYoutube extends Command
{
    protected $signature = 'scrape:youtube { url } { format }';
    protected $description = 'Scrape a youtube for videos';

    public function handle()
    {
        $url = $this->argument('url');
        $format = $this->argument('format');

        $service = new Service($url, $this->output);

        if ($service->modelExists($url)) {
            $this->info('Video already exists in db');
            return Command::FAILURE;
        }

        if ($service->createModel($format)) {
            $this->info('Download of ' . $service->getTitle() . ' complete!');
        } else {
            $this->info(ucfirst($format) . ' file already exists');
        }

        return Command::SUCCESS;
    }

}