diff options
Diffstat (limited to 'app/Console/Commands/SyncVideos.php')
-rw-r--r-- | app/Console/Commands/SyncVideos.php | 74 |
1 files changed, 30 insertions, 44 deletions
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; } |