From eb71f5a9538bff76aea208cf821308ffc2eedfb3 Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Fri, 12 Jun 2020 17:37:44 +0200 Subject: [PATCH] Studiocam ingebouwd --- .../Http/Controllers/ProgramController.php | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/api/app/Http/Controllers/ProgramController.php b/api/app/Http/Controllers/ProgramController.php index 192b28e..aa697c2 100644 --- a/api/app/Http/Controllers/ProgramController.php +++ b/api/app/Http/Controllers/ProgramController.php @@ -30,7 +30,7 @@ QUERY; // } - public function addToSchedule(&$schedule, $start, $end, $program) { + public function addToSchedule(&$schedule, $start, $end, $program, $scheduleid) { if($start == $end) { return; } @@ -43,7 +43,7 @@ QUERY; } else { - $schedule[] = ['start' => clone $start, 'end' => clone $end, 'program' => new \Model\Program($program)]; + $schedule[] = ['id' => $scheduleid, 'start' => clone $start, 'end' => clone $end, 'program' => new \Model\Program($program)]; } } @@ -146,7 +146,7 @@ QUERY; if($activeProgram == null || $priority < $activeProgram->priority) { if(($activeProgram != null) && ($item[1] > $start)) { if($DEBUG) print "{$activeProgramStart->format('d-m-Y H:i')} -- {$item[1]->format('d-m-Y H:i')}: {$activeProgram->name} (reason: {$item[2]->name} starts).
"; - $this->addToSchedule($schedule, $activeProgramStart, $item[1], $activeProgram); + $this->addToSchedule($schedule, $activeProgramStart, $item[1], $activeProgram, $item[2]->scheduleid); } $activeProgramStart = ($item[1] < $start) ? $start : clone $item[1]; @@ -168,7 +168,7 @@ QUERY; // In addition, when the ending program was the active program, we need to schedule it and find the new currently active program if($activeProgram == $item[2]) { if($DEBUG) print "{$activeProgramStart->format('d-m-Y H:i')} -- {$item[1]->format('d-m-Y H:i')}: {$activeProgram->name} {$activeProgram->suffix} (reason: {$item[2]->name} ends).
"; - $this->addToSchedule($schedule, $activeProgramStart, $item[1], $activeProgram); + $this->addToSchedule($schedule, $activeProgramStart, $item[1], $activeProgram, $item[2]->scheduleid); $activeProgram = null; foreach($active as $newPriority => $newActive) { @@ -188,7 +188,7 @@ QUERY; if(($activeProgram != null) && ($activeProgramStart != $end)) { if($DEBUG) print "{$activeProgramStart->format('d-m-Y H:i')} -- {$end->format('d-m-Y H:i')}: {$activeProgram->name} {$activeProgram->suffix} (reason: schedule finished).
"; - $this->addToSchedule($schedule, $activeProgramStart, $end, $activeProgram); + $this->addToSchedule($schedule, $activeProgramStart, $end, $activeProgram, $activeProgram->scheduleid); } return ['startdate' => $start, 'enddate' => $end, 'schedule' => $schedule]; @@ -252,6 +252,23 @@ QUERY; return new \Model\Track($data[0]); } + private function isStreamEnabled($schedule_id) { + if(!($stream = env('STUDIO_STREAM'))) { + return true; + } + $enableCameraQuery = app('db')->select("SELECT COUNT(*) AS is_enabled FROM `programs_schedule_webcam` WHERE `programs_schedule` = " . (int)$schedule_id); + if($enableCamera = $enableCameraQuery[0]->is_enabled) { + $isStreamDisabled = 1; + $output = []; + exec("ffprobe -v quiet -show_streams '$stream'", $output, $isStreamDisabled); + if(!$isStreamDisabled) { + return true; + } + } + + return false; + } + /** * Programmas nu en straks (24 uur vooruit) */ @@ -272,9 +289,10 @@ QUERY; $current = $next; } - return response()->json(['inProgram' => false, 'current' => $current, 'program' => $program]); + return response()->json(['inProgram' => false, 'stream' => false, 'current' => $current, 'program' => $program]); } else { - return response()->json(['inProgram' => true, 'program' => $program]); + $canStream = $this->isStreamEnabled($schema['schedule'][0]['id']); + return response()->json(['inProgram' => true, 'stream' => $canStream, 'program' => $program]); } }