Planet Metax - Chaos & Logik
Proxy für Podcast-Formate
26. Jul 2010 Proxy für Podcast-Formate

Hapi Podcast
Ich hatte leider mit der App Hapi Podcast einige Probleme mit den Kabarett-Feeds von Bayern2.
Das Feed-Format wurde leider nicht akzeptiert, obwohl die XML-Datei eigentlich gut aussah. Vermutlich gibt es einige ITunes-spezifischen Tags, die die App nicht verarbeiten konnte.
Daher habe ich eine kleine PHP-Anwendung geschrieben, die das Problem beheben soll.
Dazu wird ein beliebiger (gültiger) Podcast-Feed eingelesen und in eine funktionierende Vorlage gesteckt.
Damit haben auch die Feeds von Bayern2 auf meinem Smartphone funktioniert.
Falls jemand ähnliche Probleme hat, stelle ich hier das Script zum Download bereit:
Vorlage: podcast.inc.php
<?php
function xmlentities ( $string ) {
return trim ( str_replace ( array ( '&', '"', "'", '<', '>' ), array ( '&' , '"', ''' , '<' , '>' ), $string ) );
}
function http_get($url) {
$url_stuff = parse_url($url);
$port = isset($url_stuff['port']) ? $url_stuff['port'] : 80;
$fp = fsockopen($url_stuff['host'], $port);
$query = 'GET ' . $url_stuff['path'] . " HTTP/1.0\n";
$query .= 'Host: ' . $url_stuff['host'];
$query .= "\n\n";
fwrite($fp, $query);
while ($tmp = fread($fp, 1024))
{
$buffer .= $tmp;
}
$parts = split("\n\r\n", $buffer, 2);
return $parts[1];
}
$feed = http_get($feedurl);
header('Content-Type: text/xml; charset: utf-8');
$xml = simplexml_load_string($feed);
$channel = $xml->channel;
$entries = $xml->xpath('//item');
$itunes = $channel->children('itunes', true);
echo '<?xml version="1.0" encoding="UTF-8" ?>';
?>
<rss version="2.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" >
<channel>
<title><?=xmlentities($channel->title)?></title>
<link><?=xmlentities($channel->link)?></link>
<description><?=xmlentities($channel->description)?></description>
<language><?=xmlentities($channel->language)?></language>
<generator>metax-podcastproxy</generator>
<copyright><?=xmlentities($channel->copyright)?></copyright>
<image>
<url><?=xmlentities($channel->image->url)?></url>
<title><?=xmlentities($channel->image->title)?></title>
<link><?=xmlentities($channel->image->link)?></link>
</image>
<ttl><?=xmlentities($channel->ttl)?></ttl>
<category><?=xmlentities($channel->category)?></category>
<lastBuildDate><?=xmlentities($channel->lastBuildDate)?></lastBuildDate>
<pubDate><?=xmlentities($channel->pubDate)?></pubDate>
<itunes:summary><?=xmlentities($itunes->summary)?></itunes:summary>
<itunes:keywords>Comedy, lachen, lustig, Satire, Witz</itunes:keywords>
<itunes:image href="<?=xmlentities($itunes->image->attributes())?>"/>
<itunes:author><?=xmlentities($itunes->author)?></itunes:author>
<itunes:owner>
<itunes:name><?=xmlentities($itunes->owner->name)?></itunes:name>
<itunes:email><?=xmlentities($itunes->owner->email)?></itunes:email>
</itunes:owner>
<itunes:explicit><?=xmlentities($itunes->explicit)?></itunes:explicit>
<?php foreach ($entries as $entry) { ?>
<item>
<title><?=xmlentities($entry->title)?></title>
<pubDate><?=xmlentities($entry->pubDate)?></pubDate>
<description><?=xmlentities($entry->description)?></description>
<guid><?=xmlentities($entry->guid)?></guid>
<enclosure url="<?=xmlentities($entry->enclosure['url'])?>" length="<?=xmlentities($entry->enclosure['length'])?>" type="<?=xmlentities($entry->enclosure['type'])?>" />
<link><?=xmlentities($entry->link)?></link>
<itunes:keywords><?=xmlentities($entry->children('itunes', true)->keywords)?></itunes:keywords>
<itunes:summary><?=xmlentities($entry->children('itunes', true)->summary)?></itunes:summary>
</item>
<?php } ?>
</channel>
</rss>
Aufruf: radiospitzen.podcast.php
<?php
$feedurl = 'http://download.br-online.de/podcast/radiospitzen/cast.xml';
require('podcast.inc.php');
?>
podcast.inc.php
PHP Quell-DateiGröße: 3.0 Kilobyte |
radiospitzen.podca st.php
PHP Quell-DateiGröße: 109 Byte |
Es sind noch keine Kommentare vorhanden
Kommentar schreiben: