From 8d6e8b306d7836e4075a13ad98617bfe5afaa1a0 Mon Sep 17 00:00:00 2001 From: Fbenas Date: Sat, 20 Jun 2020 21:07:45 +0100 Subject: Add new scripts for youtube downloading and syncing with existing matches --- app/Console/Commands/ScrapeFile.php | 2 +- app/Console/Commands/ScrapeUrlFile.php | 71 ++++++++++++++++++++++++ app/Console/Commands/ScrapeYoutube.php | 13 +++-- app/Console/Commands/SyncVideos.php | 98 ++++++++++++++++++++++++++++++++++ app/Console/Commands/TestTor.php | 65 ++++++++++++++++++++++ 5 files changed, 245 insertions(+), 4 deletions(-) create mode 100644 app/Console/Commands/ScrapeUrlFile.php create mode 100644 app/Console/Commands/SyncVideos.php create mode 100644 app/Console/Commands/TestTor.php (limited to 'app/Console') diff --git a/app/Console/Commands/ScrapeFile.php b/app/Console/Commands/ScrapeFile.php index 4cfef90..45beda9 100644 --- a/app/Console/Commands/ScrapeFile.php +++ b/app/Console/Commands/ScrapeFile.php @@ -49,7 +49,7 @@ class ScrapeFile extends Command $raw_data = Storage::disk('local')->get($filename); - $service = new Service(new SixnationsrugbyAdapter($raw_data, 'Six Nations')); + $service = new Service(new SixnationsrugbyAdapter($raw_data, 'Six Nations ' . explode('-', explode('.txt', $filename)[0])[1])); $service->save(); diff --git a/app/Console/Commands/ScrapeUrlFile.php b/app/Console/Commands/ScrapeUrlFile.php new file mode 100644 index 0000000..f4f114b --- /dev/null +++ b/app/Console/Commands/ScrapeUrlFile.php @@ -0,0 +1,71 @@ +argument('filename'); + $format = $this->argument('format'); + + $urls = include Storage::disk('local')->path($filename); + + foreach ($urls as $url) { + $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!'); + } + + + + return Command::SUCCESS; + } + +} diff --git a/app/Console/Commands/ScrapeYoutube.php b/app/Console/Commands/ScrapeYoutube.php index ce64d3f..de620d4 100644 --- a/app/Console/Commands/ScrapeYoutube.php +++ b/app/Console/Commands/ScrapeYoutube.php @@ -2,6 +2,7 @@ namespace App\Console\Commands; +use App\Rugby\Model\Video; use App\Youtube\Service; use Illuminate\Console\Command; @@ -44,12 +45,18 @@ class ScrapeYoutube extends Command $service = new Service($url, $this->output); if ($format == 'video') { - $video = $service->downloadVideo('video'); + $service->downloadVideo('video'); } elseif ($format == 'audio') { - $video = $service->downloadAudio('audio'); + $service->downloadAudio('audio'); } - $this->info('Download of ' . $video->getTitle() . ' complete!'); + $video_model = Video::create( + [ + 'path' => $service->getFullPath() + ] + ); + + $this->info('Download of ' . $service->getTitle() . ' complete!'); return Command::SUCCESS; } diff --git a/app/Console/Commands/SyncVideos.php b/app/Console/Commands/SyncVideos.php new file mode 100644 index 0000000..d29436d --- /dev/null +++ b/app/Console/Commands/SyncVideos.php @@ -0,0 +1,98 @@ +get(); + + foreach ($videos as $video) { + $filename = $video->getFilename(); + + $tournaments = Model\Tournament::all()->filter( + function ($object) use ($filename) { + return $object->isMatch($filename); + } + ); + + $tournament_ids = $tournaments->pluck('id'); + + $teams = Model\Team::all()->filter( + function ($object) use ($filename) { + return $object->isMatch($filename); + } + ); + + $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)) { + $match->videos()->save($video); + Storage::disk('local')->move( + 'youtube/video/' . $video->getFilename(), + 'public/matches/' . $video->getFilename() + ); + } + } + } + } + + // $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!'); + + return Command::SUCCESS; + } + +} diff --git a/app/Console/Commands/TestTor.php b/app/Console/Commands/TestTor.php new file mode 100644 index 0000000..87f0050 --- /dev/null +++ b/app/Console/Commands/TestTor.php @@ -0,0 +1,65 @@ +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); + curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1:9150"); // Note the address here is just `IP:port`, not an HTTP URL. + curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME); // Note use of `CURLPROXY_SOCKS5_HOSTNAME`. + $this->info("about to run"); + $output = curl_exec($ch); + $this->info("run"); + + $curl_error = curl_error($ch); + curl_close($ch); + + print_r($output); + print_r($curl_error); + + return Command::SUCCESS; + } + +} -- cgit v1.2.3