Hele uitzending terugluisteren

This commit is contained in:
2017-08-08 21:39:42 +02:00
parent f48e5c7faf
commit da44b6bf3a
4 changed files with 52 additions and 4 deletions

View File

@@ -104,6 +104,9 @@ QUERY;
'6FM Gemist - ' . $podcast->title . '.mp3'); '6FM Gemist - ' . $podcast->title . '.mp3');
} }
/***
* Stream een specifieke podcast (niet voor uitzending)
*/
public function stream(Request $request, $id) { public function stream(Request $request, $id) {
$queryResult = app('db')->select(self::$BASE_SQL $queryResult = app('db')->select(self::$BASE_SQL
. ' AND `podcast`.`id` = :id ' . ' AND `podcast`.`id` = :id '
@@ -126,6 +129,48 @@ QUERY;
self::streamFile($request, 'audio/mpeg', $content, $size); 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 // Provide a streaming file with support for scrubbing
// Source: https://gist.github.com/widnyana/cd2bdda07dc02e9fce71 // Source: https://gist.github.com/widnyana/cd2bdda07dc02e9fce71
private static function streamFile(Request $r, $contentType, $stream, $fullsize ) { private static function streamFile(Request $r, $contentType, $stream, $fullsize ) {

View File

@@ -220,9 +220,9 @@ QUERY;
foreach(array_reverse($past['schedule']) as $item) { foreach(array_reverse($past['schedule']) as $item) {
if($item['program']->id == $id) { if($item['program']->id == $id) {
if($item['start'] > $now) { 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) { } 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];
} }
} }
} }

View File

@@ -33,6 +33,7 @@ $app->get('programma/schema/week[/{shiftWeeks:-?\d+}]', 'ProgramController@sched
$app->get('programma/details/{id:\d+}', 'ProgramController@details' ); $app->get('programma/details/{id:\d+}', 'ProgramController@details' );
$app->get('programma/schema/test/{from}/{to}', 'ProgramController@testSchedule' ); $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/onair
// live/stream // live/stream

View File

@@ -24,12 +24,14 @@ class Program extends Model {
if($this->recent && $this->recent) { if($this->recent && $this->recent) {
foreach($this->recent as &$recent) { foreach($this->recent as &$recent) {
parent::ConvertToDateTime($recent->start); parent::ConvertToDateTime($recent->starts);
parent::ConvertToDateTime($recent->ends);
} }
} }
if($this->next && $this->next) { if($this->next && $this->next) {
foreach($this->next as &$next) { foreach($this->next as &$next) {
parent::ConvertToDateTime($next->start); parent::ConvertToDateTime($next->starts);
parent::ConvertToDateTime($next->ends);
} }
} }