diff options
Diffstat (limited to 'app/Console/Commands')
-rw-r--r-- | app/Console/Commands/ScrapeFile.php | 31 | ||||
-rw-r--r-- | app/Console/Commands/ScrapeFiles.php | 33 | ||||
-rw-r--r-- | app/Console/Commands/ScrapeUrl.php | 40 | ||||
-rw-r--r-- | app/Console/Commands/ScrapeUrlFile.php | 48 | ||||
-rw-r--r-- | app/Console/Commands/ScrapeYoutube.php | 47 | ||||
-rw-r--r-- | app/Console/Commands/SyncVideos.php | 74 | ||||
-rw-r--r-- | app/Console/Commands/TestTor.php | 23 |
7 files changed, 56 insertions, 240 deletions
diff --git a/app/Console/Commands/ScrapeFile.php b/app/Console/Commands/ScrapeFile.php index 45beda9..564cf00 100644 --- a/app/Console/Commands/ScrapeFile.php +++ b/app/Console/Commands/ScrapeFile.php @@ -9,35 +9,9 @@ use Illuminate\Support\Facades\Storage; class ScrapeFile extends Command { - /** - * The name and signature of the console command. - * - * @var string - */ protected $signature = 'scrape:file { filename }'; - - /** - * The console command description. - * - * @var string - */ protected $description = 'Scrape a file for data'; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } - - /** - * Execute the console command. - * - * @return mixed - */ public function handle() { $filename = $this->argument('filename'); @@ -48,12 +22,11 @@ class ScrapeFile extends Command } $raw_data = Storage::disk('local')->get($filename); + $tournament_name = 'Six Nations ' . explode('-', explode('.txt', $filename)[0])[1]; - $service = new Service(new SixnationsrugbyAdapter($raw_data, 'Six Nations ' . explode('-', explode('.txt', $filename)[0])[1])); - + $service = new Service(new SixnationsrugbyAdapter($raw_data, $tournament_name)); $service->save(); return Command::SUCCESS; } - } diff --git a/app/Console/Commands/ScrapeFiles.php b/app/Console/Commands/ScrapeFiles.php index 05b7176..e80e9e2 100644 --- a/app/Console/Commands/ScrapeFiles.php +++ b/app/Console/Commands/ScrapeFiles.php @@ -9,35 +9,9 @@ use Illuminate\Support\Facades\Storage; class ScrapeFiles extends Command { - /** - * The name and signature of the console command. - * - * @var string - */ protected $signature = 'scrape:files { directory }'; - - /** - * The console command description. - * - * @var string - */ protected $description = 'Scrape a file for data'; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } - - /** - * Execute the console command. - * - * @return mixed - */ public function handle() { $directory = $this->argument('directory'); @@ -48,17 +22,16 @@ class ScrapeFiles extends Command } $files = Storage::disk('local')->files($directory); - - foreach ($files as $file) { - $tournament = 'Six Nations ' . explode('-', explode('.txt', $file)[0])[1]; + $this->info('Starting file: ' . $file); $raw_data = Storage::disk('local')->get($file); + $tournament = 'Six Nations ' . explode('-', explode('.txt', $file)[0])[1]; + $service = new Service(new SixnationsrugbyAdapter($raw_data, $tournament)); $service->save(); } return Command::SUCCESS; } - } diff --git a/app/Console/Commands/ScrapeUrl.php b/app/Console/Commands/ScrapeUrl.php index c02080e..06091bf 100644 --- a/app/Console/Commands/ScrapeUrl.php +++ b/app/Console/Commands/ScrapeUrl.php @@ -7,55 +7,19 @@ use Goutte\Client; class ScrapeUrl extends Command { - /** - * The name and signature of the console command. - * - * @var string - */ protected $signature = 'scrape:url { url }'; - - /** - * The console command description. - * - * @var string - */ protected $description = 'Scrape a webpage for data'; - protected $client; - - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - $this->client = new Client(); - } - - /** - * Execute the console command. - * - * @return mixed - */ public function handle() { $url = $this->argument('url'); - if ($url != 'https://www.sixnationsrugby.com/fixtures/') { - $this->error('Url not supported'); - return; - } - - $crawler = $this->client->request('GET', $this->argument('url')); + $crawler = (new Client())->request('GET', $this->argument('url')); - $crawler->filter('div.fixtures__top-tier')->each( + $crawler->filter('title')->each( function ($node) { print $node->text()."\n"; } ); - - } } diff --git a/app/Console/Commands/ScrapeUrlFile.php b/app/Console/Commands/ScrapeUrlFile.php index f4f114b..e9472d2 100644 --- a/app/Console/Commands/ScrapeUrlFile.php +++ b/app/Console/Commands/ScrapeUrlFile.php @@ -9,35 +9,9 @@ use Illuminate\Support\Facades\Storage; class ScrapeUrlFile extends Command { - /** - * The name and signature of the console command. - * - * @var string - */ protected $signature = 'scrape:urls { filename } { 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() { $filename = $this->argument('filename'); @@ -48,23 +22,21 @@ class ScrapeUrlFile extends Command foreach ($urls as $url) { $service = new Service($url, $this->output); - if ($format == 'video') { - $service->downloadVideo('video'); - } elseif ($format == 'audio') { - $service->downloadAudio('audio'); + if ($service->modelExists($url)) { + $this->info("Skipping $url. Exists in db!"); + continue; } - $video_model = Video::create( - [ - 'path' => $service->getFullPath() - ] - ); + if ($service->createModel($format)) { + $this->info("Download {$service->getTitle()} from $url!"); + } else { + $this->info('Skipping ' . $url . '. ' . ucfirst($format) . ' file already exists!'); + continue; + } - $this->info('Download of ' . $service->getTitle() . ' complete!'); + $this->info("Download {$service->getTitle()} from $url!"); } - - return Command::SUCCESS; } 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; } diff --git a/app/Console/Commands/SyncVideos.php b/app/Console/Commands/SyncVideos.php index d29436d..4f9f800 100644 --- a/app/Console/Commands/SyncVideos.php +++ b/app/Console/Commands/SyncVideos.php @@ -9,48 +9,32 @@ use Illuminate\Support\Facades\Storage; class SyncVideos extends Command { - /** - * The name and signature of the console command. - * - * @var string - */ protected $signature = 'sync:videos'; - - /** - * The console command description. - * - * @var string - */ protected $description = 'Sync downloaded videos with existing matches'; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } - - /** - * Execute the console command. - * - * @return mixed - */ public function handle() { $videos = Model\Video::whereNull('match_id')->get(); + $this->info('Found ' . $videos->count() . ' videos!'); foreach ($videos as $video) { $filename = $video->getFilename(); + $this->info('Searching for match from filename: ' . $filename); + $tournaments = Model\Tournament::all()->filter( function ($object) use ($filename) { return $object->isMatch($filename); } ); + if (!$tournaments->count()) { + $this->info('Could not find tournament from filename: ' . $filename); + return; + } + + $this->info('Found Tournmament:' . $tournaments->first()->name); + $tournament_ids = $tournaments->pluck('id'); $teams = Model\Team::all()->filter( @@ -59,38 +43,40 @@ class SyncVideos extends Command } ); + if (!$teams->count()) { + $this->info('Could not find teams from filename: ' . $filename); + continue; + } + + if ($teams->count() == 1) { + $this->info('Could only find 1 team (' . $teams->first()->name . ') from filename: ' . $filename); + continue; + } + + $this->info('Found Teams:' . $teams->first()->name, $teams->slice(1, 1)->first()->name); + $team_ids = $teams->pluck('name')->toArray(); $matches = $tournaments->first()->matches; foreach ($matches as $match) { - if (in_array($match->homeTeam()->first()->name, $team_ids)) { - if (in_array($match->awayTeam()->first()->name, $team_ids)) { + if (in_array($match->getHomeTeam()->name, $team_ids)) { + if (in_array($match->getAwayTeam()->name, $team_ids)) { + + $this->info('Found Match for filename: ' . $filename); $match->videos()->save($video); Storage::disk('local')->move( 'youtube/video/' . $video->getFilename(), 'public/matches/' . $video->getFilename() ); + + continue 2; } } } - } - // $service = new Service($url, $this->output); - // - // if ($format == 'video') { - // $service->downloadVideo('video'); - // } elseif ($format == 'audio') { - // $service->downloadAudio('audio'); - // } - // - // $video_model = Video::create( - // [ - // 'path' => $service->getFullPath() - // ] - // ); - // - // $this->info('Download of ' . $service->getTitle() . ' complete!'); + $this->info('Failed to find Match for filename: ' . $filename); + } return Command::SUCCESS; } diff --git a/app/Console/Commands/TestTor.php b/app/Console/Commands/TestTor.php index 87f0050..5c4c296 100644 --- a/app/Console/Commands/TestTor.php +++ b/app/Console/Commands/TestTor.php @@ -7,43 +7,20 @@ use Illuminate\Support\Facades\Http; class TestTor extends Command { - /** - * The name and signature of the console command. - * - * @var string - */ protected $signature = 'test:tor { onion }'; - - /** - * The console command description. - * - * @var string - */ protected $description = 'Testing tor'; - /** - * Create a new command instance. - * - * @return void - */ public function __construct() { parent::__construct(); } - /** - * Execute the console command. - * - * @return mixed - */ public function handle() { $url = $this->argument('onion'); $response = Http::get($url); - dd($response->body()); - // $url = 'http://jhiwjjlqpyawmpjx.onion/'; // Note the addition of a semicolon. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |