Podcasts
This commit is contained in:
@@ -5,7 +5,6 @@ namespace App\Http\Controllers;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', true);
|
||||
|
||||
@@ -36,6 +35,22 @@ QUERY;
|
||||
* Lijst van alle podcasts
|
||||
*/
|
||||
public function overview(Request $request) {
|
||||
return $this->getPodcastList($request, null, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lijst van alle podcasts voor een specifiek programma
|
||||
*/
|
||||
public function program(Request $request, $program) {
|
||||
if((int)$program <= 0) {
|
||||
return abort(404);
|
||||
}
|
||||
|
||||
return $this->getPodcastList($request, '`podcast_meta`.`program` = :program', ['program' => (int)$program]);
|
||||
}
|
||||
|
||||
private function getPodcastList(Request $request, $filter, $params)
|
||||
{
|
||||
$count = (int)$request->get('aantal', 15);
|
||||
$page = (int)$request->get('pagina', 1);
|
||||
if($count <= 0 || $page <= 0) {
|
||||
@@ -44,8 +59,10 @@ QUERY;
|
||||
|
||||
$start = ($page - 1) * $count;
|
||||
$podcasts = app('db')->select(self::$BASE_SQL
|
||||
. ($filter ? ' AND (' . $filter . ')' : '')
|
||||
. ' ORDER BY `podcast_meta`.`creationdt` DESC, `podcast_meta`.`id` DESC'
|
||||
. ' LIMIT ' . (int)$start . ', ' . (int)$count);
|
||||
. ' LIMIT ' . (int)$start . ', ' . (int)$count,
|
||||
$params);
|
||||
|
||||
$result = array();
|
||||
foreach($podcasts as $podcast) {
|
||||
@@ -58,11 +75,11 @@ QUERY;
|
||||
/**
|
||||
* Download specifieke podcast
|
||||
*/
|
||||
public function download(Request $request, int $id) {
|
||||
public function download(Request $request, $id) {
|
||||
$queryResult = app('db')->select(self::$BASE_SQL
|
||||
. ' AND `podcast`.`id` = :id '
|
||||
. ' LIMIT 0, 1',
|
||||
['id' => $id]);
|
||||
['id' => (int)$id]);
|
||||
|
||||
if(count($queryResult) == 0) { return abort(404); }
|
||||
|
||||
@@ -75,7 +92,7 @@ QUERY;
|
||||
'6FM Gemist - ' . $podcast->title . '.mp3');
|
||||
}
|
||||
|
||||
public function stream(Request $request, int $id) {
|
||||
public function stream(Request $request, $id) {
|
||||
$queryResult = app('db')->select(self::$BASE_SQL
|
||||
. ' AND `podcast`.`id` = :id '
|
||||
. ' LIMIT 0, 1',
|
||||
|
||||
@@ -25,9 +25,9 @@ $app->get('agenda/kalender[/{year:\d\d\d\d}/{month:\d\d?}]', 'AgendaController@c
|
||||
$app->get('agenda/details/{id:\d+}', 'AgendaController@item' );
|
||||
|
||||
$app->get('podcast/overzicht', 'PodcastController@overview' );
|
||||
// podcast/programma/1234[?aantal=&pagina=]
|
||||
$app->get('podcast/download/{id:\d+}/[{title}]', 'PodcastController@download' );
|
||||
$app->get('podcast/stream/{id:\d+}/[{title}]', 'PodcastController@stream' );
|
||||
$app->get('podcast/programma/{id:\d+}', 'PodcastController@program' );
|
||||
$app->get('podcast/download/{id:\d+}', 'PodcastController@download' );
|
||||
$app->get('podcast/stream/{id:\d+}', 'PodcastController@stream' );
|
||||
|
||||
$app->get('programma/schema/nustraks', 'ProgramController@comingup' );
|
||||
$app->get('programma/schema/week[/{shiftWeeks:-?\d+}]', 'ProgramController@schedule' );
|
||||
|
||||
@@ -12,6 +12,7 @@ class Podcast extends Model {
|
||||
public $created;
|
||||
public $program;
|
||||
public $url;
|
||||
public $auth;
|
||||
public $download;
|
||||
private $key;
|
||||
|
||||
@@ -19,11 +20,19 @@ class Podcast extends Model {
|
||||
parent::__construct($data);
|
||||
parent::ConvertToDateTime($this->created);
|
||||
|
||||
$this->key = sha1($this->id . ':' . session_id() . ':' . $this->soundfilename);
|
||||
$this->url = $this->id . '/' . parent::url_slug($this->title) . '?auth=' . $this->key;
|
||||
|
||||
if($this->program != 0) {
|
||||
$this->program = new \Model\Program(['id' => $this->program, 'name' => $data->program_name, 'description' => $data->program_description]);
|
||||
$this->url = $this->id . '/' . parent::url_slug($this->title);
|
||||
if($this->soundfilename) {
|
||||
// Only generate when not constructing from a JSON object
|
||||
$this->key = sha1($this->id . ':' . date('Y-m-d') . ':' . $this->soundfilename);
|
||||
$this->auth = $this->key;
|
||||
}
|
||||
|
||||
if($data->program) {
|
||||
if(is_object($data->program)) {
|
||||
$this->program = new \Model\Program($data->program);
|
||||
} else {
|
||||
$this->program = new \Model\Program(['id' => $this->program, 'name' => $data->program_name, 'description' => $data->program_description]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +41,7 @@ class Podcast extends Model {
|
||||
}
|
||||
|
||||
public function getSoundfile() {
|
||||
return '/tmp/podcast.mp3';
|
||||
return '/var/audio/podcast/' . $this->soundfilename;
|
||||
}
|
||||
|
||||
public function excerpt() {
|
||||
|
||||
@@ -25,7 +25,7 @@ class Program extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
if(($mailComma = strpos($data->email, ',')) !== false) {
|
||||
if(isset($data->email) && ($mailComma = strpos($data->email, ',')) !== false) {
|
||||
$this->email = substr($data->email, 0, $mailComma);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user