Created
May 15, 2009 11:27
-
-
Save rduarte/112176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('default_charset', 'utf-8'); | |
header('Content-type: application/xml'); | |
$html = utf8_encode(file_get_contents("http://www.clicrbs.com.br/atlantidafm/jsp/default.jsp?uf=1&local=1&template=3343.dwt&pSection=726§ion=12")); | |
// Tenho vergonha, mas foi o jeito para o lixo de HTML | |
preg_match_all(("/» Pretinho das (.*)<!-- Escutar--><!-- Baixar--> | <a/"), ($html), $matches); | |
$matches = explode("»", $matches[0][0]); | |
foreach ($matches as $match){ | |
// Pegando titulos | |
preg_match("/ (.*): </",$match, $matches); | |
if (!empty($matches[1])) $titulos[] = $matches[1]; | |
preg_match("/<a href=\"(.*)\">Escutar/",$match, $matches); | |
if (!empty($matches[1])) $arquivos[] = $matches[1]; | |
} | |
/* Criar array unificado */ | |
$data = "0"; | |
foreach($titulos as $id => $titulo){ | |
$headers = get_headers($arquivos[$id], 1); | |
if($headers[0] == 'HTTP/1.1 200 OK'){ | |
$programas[] = array('titulo' => $titulo, 'arquivo' => $arquivos[$id], 'headers' => $headers); | |
if(strtotime($headers['Last-Modified']) > $data){ | |
$data = strtotime($headers['Last-Modified']); | |
$last_modified = $headers['Last-Modified']; | |
} | |
} | |
} | |
unset($data); | |
unset($headers); | |
?> | |
<?php echo '<?xml version="1.0" encoding="UTF-8"?>' ?> | |
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> | |
<channel> | |
<title>Pretinho Básico - Rádio Atlântida</title> | |
<description>Na Rádio Atlântida, de segunda a sábado às 13h e às 18h. E aqui, a qualquer hora do dia ou da noite.</description> | |
<link>http://wp.clicrbs.com.br/pretinhobasico/</link> | |
<lastBuildDate><?php echo $last_modified; ?></lastBuildDate> | |
<pubDate><?php echo $last_modified; ?></pubDate> | |
<copyright>Copyright© <?php echo date("Y"); ?> - Grupo RBS</copyright> | |
<language>pt-br</language> | |
<generator>Ricardo Antonio Duarte - ricardo@ricardoduarte.com</generator> | |
<atom:link href="http://feeds2.feedburner.com/PretinhoBasico" rel="self" type="application/rss+xml" /> | |
<?php | |
foreach($programas as $programa){ | |
?> | |
<item> | |
<title><?php echo $programa['titulo']; ?></title> | |
<description><?php echo $programa['titulo']; ?></description> | |
<link><?php echo $programa['arquivo']; ?></link> | |
<enclosure url="<?php echo $programa['arquivo']; ?>" length="<?php echo $programa['headers']['Content-Length']; ?>" type="<?php echo $programa['headers']['Content-Type']; ?>"/> | |
<guid isPermaLink="true"><?php echo $programa['arquivo']; ?></guid> | |
<pubDate><?php echo $programa['headers']['Last-Modified']; ?></pubDate> | |
</item> | |
<?php | |
} | |
?> | |
</channel> | |
</rss> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment