Podcast RSS fixed
This commit is contained in:
@@ -3,21 +3,20 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', true);
|
||||
|
||||
class PodcastController extends Controller
|
||||
{
|
||||
public static $BASE_SQL = <<<QUERY
|
||||
SELECT `podcast`.`id`, `podcast`.`soundfilename`,
|
||||
`podcast_meta`.`creationdt` AS `created`, `podcast_meta`.`title`, `podcast_meta`.`content`, `podcast_meta`.`program`, `podcast_meta`.`imagefile`, `podcast_meta`.`imagecaption`,
|
||||
SELECT `podcast`.`id`, `podcast`.`soundfilename`, `podcast`.`duration`,
|
||||
`podcast_meta`.`creationdt` AS `created`, `podcast_meta`.`title`, `podcast_meta`.`content`, `podcast_meta`.`program`,
|
||||
`podcast_meta`.`imagefile`, `podcast_meta`.`imagecaption`,
|
||||
`programs`.`longname` AS `program_name`, `programs`.`description` AS `program_description`
|
||||
FROM `podcast`
|
||||
INNER JOIN `podcast_meta` ON `podcast`.`id` = `podcast_meta`.`podcast`
|
||||
LEFT JOIN `programs` ON `podcast_meta`.`program` = `programs`.`id`
|
||||
WHERE `podcast_meta`.`active` = 1 AND `podcast_meta`.`title` <> '' AND `podcast_meta`.`content` <> ''
|
||||
WHERE `podcast_meta`.`active` = 1 AND `podcast_meta`.`public` = 1
|
||||
QUERY;
|
||||
|
||||
/**
|
||||
@@ -37,6 +36,39 @@ QUERY;
|
||||
return $this->getPodcastList($request, null, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* RSS-feed van alle podcasts
|
||||
*/
|
||||
public function rss(Request $request) {
|
||||
$page = (int)$request->get('page', 1);
|
||||
if($page <= 0) {
|
||||
return abort(400);
|
||||
}
|
||||
|
||||
$podcasts = $this->retrievePodcasts($page, $count = 20, $filter = null, $params = []);
|
||||
$view = view('rss.podcasts')->with('podcasts', $podcasts)->with('url', $request->url())->with('page', $page);
|
||||
return response($view)->header('Content-Type', 'application/xml');
|
||||
}
|
||||
|
||||
/**
|
||||
* RSS-feed van alle podcasts van een programma (bv. podcastserie)
|
||||
*/
|
||||
public function program_rss(Request $request, $program) {
|
||||
$page = (int)$request->get('page', 1);
|
||||
if($page <= 0) {
|
||||
return abort(400);
|
||||
}
|
||||
|
||||
$programQuery = app('db')->select('SELECT `programs`.`id` AS `id`, `programs`.`longname` AS `name`, `programs`.`description` AS `description`, `programs`.`tagline` AS `tagline`, `programs`.`description` AS `description`, `programs`.`email` FROM `programs` WHERE `programs`.`id` = :id', ['id' => $program]);
|
||||
$programDetails = new \Model\Program($programQuery[0]);
|
||||
|
||||
$filter = '`podcast_meta`.`program` = :program';
|
||||
$params = ['program' => (int)$program];
|
||||
$podcasts = $this->retrievePodcasts($page, $count = 1000, $filter, $params);
|
||||
$view = view('rss.podcasts')->with('program', $programDetails)->with('podcasts', $podcasts)->with('url', $request->url())->with('page', $page);
|
||||
return response($view)->header('Content-Type', 'application/xml');
|
||||
}
|
||||
|
||||
/**
|
||||
* Lijst van alle podcasts voor een specifiek programma
|
||||
*/
|
||||
@@ -70,22 +102,17 @@ QUERY;
|
||||
|
||||
public function findpodcast(Request $request, $query) {
|
||||
$page = (int)$request->get('pagina', 1);
|
||||
$count = (int)$request->get('aantal', 15);
|
||||
if($page <= 0) {
|
||||
return abort(400);
|
||||
}
|
||||
|
||||
$start = ($page - 1) * $count;
|
||||
$query = strip_tags(urldecode($query));
|
||||
$searchRange = [
|
||||
(new \DateTimeImmutable())->setDate(date('Y') + 1 - $page, 1, 1),
|
||||
(new \DateTimeImmutable())->setDate(date('Y') + 2 - $page, 1, 1)];
|
||||
|
||||
$podcasts = app('db')->select(self::$BASE_SQL
|
||||
. ' AND `podcast_meta`.`creationdt` >= :startRange AND `podcast_meta`.`creationdt` <= :endRange'
|
||||
. ' AND MATCH(`podcast_meta`.`title`, `podcast_meta`.`content`) AGAINST(:query IN BOOLEAN MODE)'
|
||||
. ' AND MATCH(`podcast_meta`.`title`, `podcast_meta`.`content`) AGAINST(:query IN NATURAL LANGUAGE MODE)'
|
||||
. ' ORDER BY `creationdt` DESC'
|
||||
. ' LIMIT 0, 20', [
|
||||
'startRange' => $searchRange[0]->format('Y-m-d'),
|
||||
'endRange' => $searchRange[1]->format('Y-m-d'),
|
||||
. ' LIMIT ' . $start . ', ' . $count, [
|
||||
'query' => $query
|
||||
]);
|
||||
|
||||
@@ -102,12 +129,18 @@ QUERY;
|
||||
|
||||
private function getPodcastList(Request $request, $filter, $params)
|
||||
{
|
||||
$count = (int)$request->get('aantal', 15);
|
||||
$page = (int)$request->get('pagina', 1);
|
||||
$count = (int)$request->get('aantal', 15);
|
||||
$page = (int)$request->get('pagina', 1);
|
||||
if($count <= 0 || $page <= 0) {
|
||||
return abort(400);
|
||||
}
|
||||
|
||||
$result = $this->retrievePodcasts($page, $count, $filter, $params);
|
||||
return response()->json(['page' => $page, 'count' => $count, 'podcasts' => $result]);
|
||||
}
|
||||
|
||||
private function retrievePodcasts($page, $count, $filter, $params)
|
||||
{
|
||||
$start = ($page - 1) * $count;
|
||||
$podcasts = app('db')->select(self::$BASE_SQL
|
||||
. ($filter ? ' AND (' . $filter . ')' : '')
|
||||
@@ -119,8 +152,8 @@ QUERY;
|
||||
foreach($podcasts as $podcast) {
|
||||
$result[] = new \Model\Podcast($podcast);
|
||||
}
|
||||
|
||||
return response()->json(['page' => $page, 'count' => $count, 'podcasts' => $result]);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,7 +173,7 @@ QUERY;
|
||||
}
|
||||
|
||||
return response()->download($podcast->getSoundfile(),
|
||||
'6FM Gemist - ' . str_replace('/', '-', $podcast->title) . '.mp3');
|
||||
'NH Gooi Gemist - ' . str_replace('/', '-', $podcast->title) . '.mp3');
|
||||
}
|
||||
|
||||
/***
|
||||
@@ -174,7 +207,7 @@ QUERY;
|
||||
public function latestNews(Request $request) {
|
||||
$filename = '/var/audio/regionieuws.mp3';
|
||||
return response()->download($filename,
|
||||
'6FM Regionieuws ' . date('d-m-Y') . '.mp3');
|
||||
'NH Gooi Regionieuws ' . date('d-m-Y') . '.mp3');
|
||||
|
||||
$size = filesize($filename);
|
||||
$content = fread($file, $size);
|
||||
@@ -196,14 +229,10 @@ QUERY;
|
||||
$files = [];
|
||||
$size = 0;
|
||||
while($duration--) {
|
||||
$file = '/var/audio/uitzending/' . $currentHour->format('Ymd_Hi');
|
||||
if(file_exists($file . '.mp3')) {
|
||||
$file .= '.mp3';
|
||||
} else if(file_exists($file . '.MP3')) {
|
||||
$file .= '.MP3';
|
||||
} else {
|
||||
return abort(404);
|
||||
}
|
||||
$file = '/var/audio/uitzending/' . $currentHour->format('Ymd_Hi') . '.mp3';
|
||||
if(!file_exists($file)) {
|
||||
return abort(404);
|
||||
}
|
||||
|
||||
$size += ($filesize = filesize($file));
|
||||
$files[] = [$file, $filesize];
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php header('Access-Control-Allow-Origin: *'); ?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?php header('Content-Type: text/xml'); ?>
|
||||
<{{ '' /* avoid PHP parsing this as short open tag */ }}?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0"
|
||||
xmlns:atom="http://www.w3.org/2005/Atom"
|
||||
xmlns:content="http://purl.org/rss/1.0/modules/content/"
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?php header('Access-Control-Allow-Origin: *'); ?>
|
||||
<?php header('Content-Type: text/xml'); ?>
|
||||
<{{ '' /* avoid PHP parsing this as short open tag */ }}?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0"
|
||||
xmlns:atom="http://www.w3.org/2005/Atom"
|
||||
xmlns:spotify="http://www.spotify.com/ns/rss"
|
||||
@@ -45,7 +47,9 @@
|
||||
<itunes:duration>{{$podcast->formatDuration()}}</itunes:duration>
|
||||
<itunes:explicit>no</itunes:explicit>
|
||||
@if($podcast->image)
|
||||
<itunes:image href="https://nhgooi.nl{{$podcast->image->url}}"/>
|
||||
<itunes:image href="https://nhgooi.nl{{$podcast->image->url}}"/>
|
||||
@elseif($podcast->program && $podcast->program->image)
|
||||
<itunes:image href="https://nhgooi.nl{{$podcast->program->image->url}}"/>
|
||||
@endif
|
||||
</item>
|
||||
@endforeach
|
||||
|
||||
Reference in New Issue
Block a user