2 function sendPodcastList()
4 $files = glob(__DIR__ . '/../var/podcasts/*.url');
5 if (count($files) == 0) {
6 sendMessage('Keine Podcasts');
11 foreach ($files as $file) {
12 $title = basename($file, '.url');
13 $listItems[] = '<Item>'
14 . '<ItemType>ShowOnDemand</ItemType>'
15 . '<ShowOnDemandName>' . htmlspecialchars($title) . '</ShowOnDemandName>'
16 . '<ShowOnDemandURL>http://radio567.vtuner.com/podcasts/' . urlencode(basename($file)) . '</ShowOnDemandURL>'
19 sendListItems($listItems);
22 function sendPodcast($file)
25 $file = substr(urldecode($file), 10);
26 if (strpos($file, '..') !== false) {
31 $path = __DIR__ . '/../var/podcasts/' . $file;
32 if (!file_exists($path)) {
33 return sendMessage('File does not exist: ' . $file);
36 $url = trim(file_get_contents($path));
38 $cacheFile = '/tmp/podcast-' . md5($file) . '.xml';
39 downloadIfNewer($url, $cacheFile);
41 $sx = simplexml_load_file($cacheFile);
43 foreach ($sx->channel->item as $item) {
44 $title = (string) $item->title;
45 $desc = (string) $item->description;
46 $url = $item->enclosure['url'];
48 $listItems[] = '<Item>'
49 . '<ItemType>ShowEpisode</ItemType>'
50 . '<ShowEpisodeName>' . utf8_decode(htmlspecialchars($title)) . '</ShowEpisodeName>'
51 . '<ShowEpisodeURL>http://radio567.vtuner.com/play-url?url=' . urlencode($url) . '</ShowEpisodeURL>'
52 //. '<ShowEpisodeURL>' . htmlspecialchars($url) . '</ShowEpisodeURL>'
53 . '<ShowDesc>' . utf8_decode(htmlspecialchars($desc)) . '</ShowDesc>'
54 . '<ShowMime>MP3</ShowMime>'
57 sendListItems($listItems);
61 function downloadIfNewer($url, $file)
64 if (file_exists($file)) {
65 $lastModified = filemtime($file);
68 $ctx = stream_context_create(
71 'header' => 'If-Modified-Since: ' . date('r', $lastModified)
75 $content = file_get_contents($url, false, $ctx);
76 //unfortunately, redirects require manual parsing of this array
77 for ($n = count($http_response_header) - 1; $n >= 0; --$n) {
78 if (substr($http_response_header[$n], 0, 5) == 'HTTP/') {
79 list(, $code) = explode(' ', $http_response_header[$n]);
84 file_put_contents($file, $content);