<?php
error_reporting(-1);
echo '<?xml version="1.0" encoding="utf-8"?>';
echo "\r\n";
function cleanText($impText) {
$impText = strip_tags($impText);
$impText = htmlspecialchars($impText);
$impText = htmlspecialchars_decode($impText);
$impText = str_replace('&',"&", $impText);
$impText = str_replace('.',". ", $impText);
$impText = str_replace(' '," ", $impText);
return $impText;
}
$erVist = "";
?>
<rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
<?php
function DR_NU_FILESIZE($url) {
$remoteFile = $url;
$ch = curl_init($remoteFile);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($ch);
curl_close($ch);
$contentLength = 'unknown';
$status = 'unknown';
if (preg_match('/^HTTP\/1\.[01] (\d\d\d)/', $data, $matches)) {
$status = (int)$matches[1];
}
if (preg_match('/Content-Length: (\d+)/', $data, $matches)) {
$contentLength = (int)$matches[1];
}
return $contentLength;
}
$introXML = "";
$data = join('',file('http://www.dr.dk/nu/api/programseries/'.$_GET['ps'].'/videos'));
$data = json_decode($data);
while (list($a,$obj) = each($data)) {
$broadcastTime = $obj->{'formattedBroadcastTime'};
if (!$introXML) {
$podTitel = cleanText($obj->{'title'});
list($podTitel) = explode(" (",$podTitel);
list($podTitel) = explode(": ",$podTitel);
list($podTitel) = explode(" - ",$podTitel);
list($beskrivelse) = explode(". ", cleanText($obj->{'description'}));
echo " <title>".$podTitel."</title>\r\n";
echo " <itunes:category text=\"\">\r\n";
echo " </itunes:category>\r\n";
echo " <itunes:image href=\"http://www.dr.dk".$obj->{'webCmsImagePath'}."\">\r\n";
echo " </itunes:image>\r\n";
echo " <itunes:author>DR</itunes:author>\r\n";
echo " <itunes:explicit>no</itunes:explicit>\r\n";
echo " <itunes:subtitle>\r\n";
echo " </itunes:subtitle>\r\n";
echo " <itunes:summary>".$beskrivelse.".</itunes:summary>\r\n";
echo " <link>http://www.dr.dk</link>\r\n";
echo " <description>".$beskrivelse.".</description>\r\n";
echo " <language>da</language>\r\n";
echo " <copyright>DR</copyright>\r\n";
echo " <lastBuildDate>\r\n";
echo " </lastBuildDate>\r\n";
echo " <ttl>\r\n";
echo " </ttl>\r\n\r\n";
}
$timediff = time()-strtotime($obj->{'broadcastTime'});
if ($timediff < 5184000) {
$lokalFil = preg_replace("/[^A-Za-z0-9 ]/", '', $obj->{'videoManifestUrl'});
if (file_exists("videourls/".$lokalFil.".txt")) {
$mediaData = join('',file("videourls/".$lokalFil.".txt"));
list($mediaURL,$mediaSize) = explode("||",$mediaData);
} else {
$mediaURL = join('',file($obj->{'videoManifestUrl'}));
$mediaURL = str_replace('rtmp://vod.dr.dk/cms/mp4:', 'http://vodfiles.dr.dk/', $mediaURL);
$mediaSize = DR_NU_FILESIZE($mediaURL);
if ($mediaSize > 200) {
$fp = fopen("videourls/".$lokalFil.".txt", 'w');
fwrite($fp, $mediaURL."||".$mediaSize);
fclose($fp);
}
}
if ($mediaSize > 0 && @$erVist[$obj->{'title'}] != $obj->{'broadcastTime'}) {
list($besket, $beskto, $besktre) = explode(". ", cleanText($obj->{'description'}));
echo " <item>\r\n";
echo " <title>".cleanText($obj->{'title'})."</title>\r\n";
echo " <description>".$besket.". ".$beskto.". ".$besktre.".</description>\r\n";
echo " <link>".$mediaURL."</link>\r\n";
echo " <itunes:author>DR</itunes:author>\r\n";
echo " <itunes:duration>".$obj->{'duration'}."</itunes:duration>\r\n";
echo " <itunes:summary>".$besket.". ".$beskto.".</itunes:summary>\r\n";
echo " <itunes:subtitle>".$besket.".</itunes:subtitle>\r\n";
echo " <itunes:explicit>no</itunes:explicit>\r\n";
echo " <pubDate>".date("D, j M Y H:i:s O",strtotime($obj->{'broadcastTime'}))."</pubDate>\r\n";
echo " <enclosure url=\"".$mediaURL."\" length=\"".$mediaSize."\" type=\"video/mp4\" />\r\n";
echo " <guid isPermaLink=\"false\">DR".$obj->{'id'}."</guid>\r\n";
echo " </item>\r\n\r\n";
$introXML++;
}
$erVist[$obj->{'title'}] = $obj->{'broadcastTime'};
}
if ($introXML == 5) {
break;
}
}
?>
</channel>
</rss>