diff --git a/api/app/Http/Controllers/PodcastController.php b/api/app/Http/Controllers/PodcastController.php index c0c67be..5493c81 100644 --- a/api/app/Http/Controllers/PodcastController.php +++ b/api/app/Http/Controllers/PodcastController.php @@ -104,6 +104,9 @@ QUERY; '6FM Gemist - ' . $podcast->title . '.mp3'); } + /*** + * Stream een specifieke podcast (niet voor uitzending) + */ public function stream(Request $request, $id) { $queryResult = app('db')->select(self::$BASE_SQL . ' AND `podcast`.`id` = :id ' @@ -126,6 +129,48 @@ QUERY; self::streamFile($request, 'audio/mpeg', $content, $size); } + /*** + * Stream een specifieke uitzending + */ + public function complete(Request $r, $year, $month, $day, $hour, $duration) { + if($duration <= 0) { + return response()->abort(404); + } + + $currentHour = new \DateTime(); + $currentHour->setDate($year, $month, $day)->setTime($hour, 0, 0); + $files = []; + $size = 0; + while($duration--) { + $file = '/var/audio/uitzending/' . $currentHour->format('Ymd_Hi') . '.MP3'; + if(!file_exists($file)) { + return response()->abort(404); + } + + $size += filesize($file); + $files[] = $file; + $currentHour->add(\DateInterval::createFromDateString('1 hour')); + } + + return new StreamedResponse(function() use($files) { + // Open output stream + $output = fopen('php://output', 'w'); + foreach($files as $file) { + $fp = fopen($file, 'rb'); + while ($buf = fread($fp, 1024)) { + fwrite($output, $buf); + } + fclose($fp); + } + fclose($output); + }, 200, [ + 'Content-Type' => 'audio/mpg', + 'Content-Disposition' => sprintf( + 'attachment; filename="Radio_6FM_Uitzending_%02d-%02d-%04d_%02du00.MP3"', + $day, $month, $year, $hour) + ]); + } + // Provide a streaming file with support for scrubbing // Source: https://gist.github.com/widnyana/cd2bdda07dc02e9fce71 private static function streamFile(Request $r, $contentType, $stream, $fullsize ) { diff --git a/api/app/Http/Controllers/ProgramController.php b/api/app/Http/Controllers/ProgramController.php index 24cc9de..7e474c0 100644 --- a/api/app/Http/Controllers/ProgramController.php +++ b/api/app/Http/Controllers/ProgramController.php @@ -220,9 +220,9 @@ QUERY; foreach(array_reverse($past['schedule']) as $item) { if($item['program']->id == $id) { if($item['start'] > $now) { - array_unshift($program->next, ['start' => $item['start'], 'name' => $item['program']->name, 'nonstop' => $item['program']->nonstop, 'rerun' => $item['program']->rerun]); + array_unshift($program->next, ['starts' => $item['start'], 'ends' => $item['end'], 'name' => $item['program']->name, 'nonstop' => $item['program']->nonstop, 'rerun' => $item['program']->rerun]); } else if($item['program']->priority < 3 && $item['start'] < $now) { - $program->recent[] = ['start' => $item['start'], 'name' => $item['program']->name, 'nonstop' => $item['program']->nonstop, 'rerun' => $item['program']->rerun]; + $program->recent[] = ['starts' => $item['start'], 'ends' => $item['end'], 'name' => $item['program']->name, 'nonstop' => $item['program']->nonstop, 'rerun' => $item['program']->rerun]; } } } diff --git a/api/routes/web.php b/api/routes/web.php index 53ed84b..4e4a045 100644 --- a/api/routes/web.php +++ b/api/routes/web.php @@ -33,6 +33,7 @@ $app->get('programma/schema/week[/{shiftWeeks:-?\d+}]', 'ProgramController@sched $app->get('programma/details/{id:\d+}', 'ProgramController@details' ); $app->get('programma/schema/test/{from}/{to}', 'ProgramController@testSchedule' ); +$app->get('programma/download/{year:20\d\d}/{month:\d\d?}/{day:\d\d?}/{hour:\d\d?}/{duration:\d\d?}', 'PodcastController@complete'); // live/onair // live/stream diff --git a/common/classes/Program.php b/common/classes/Program.php index 2ad8c89..1f70686 100644 --- a/common/classes/Program.php +++ b/common/classes/Program.php @@ -24,12 +24,14 @@ class Program extends Model { if($this->recent && $this->recent) { foreach($this->recent as &$recent) { - parent::ConvertToDateTime($recent->start); + parent::ConvertToDateTime($recent->starts); + parent::ConvertToDateTime($recent->ends); } } if($this->next && $this->next) { foreach($this->next as &$next) { - parent::ConvertToDateTime($next->start); + parent::ConvertToDateTime($next->starts); + parent::ConvertToDateTime($next->ends); } }