Created
December 11, 2015 00:41
-
-
Save jasontucker/c5f9103f4e4a43aa2128 to your computer and use it in GitHub Desktop.
Parses enclosure urls from iTunes RSS feed
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 | |
/** | |
* mp3s.php | |
* Parses enclosure urls from itunes RSS feed | |
* @author Jason Tucker | |
*/ | |
?> | |
<html> | |
<head> | |
<title>List audio enclosures from podcast feed</title> | |
</head> | |
<body> | |
<?php | |
// Build our table | |
echo "<h2>Right click and copy the url</h2>\n\r"; | |
echo "<table>\n\r"; | |
echo "<tr>\n\r"; | |
echo "<th>name/url</th><th>size</th><th>duration</th>\n\r"; | |
echo "</tr>\n\r"; | |
// Replace the feed with your itunes RSS feed to parse | |
$rssfeed = 'http://feeds.soundcloud.com/users/soundcloud:users:181641184/sounds.rss'; | |
$rss = simplexml_load_file($rssfeed); | |
foreach ($rss->channel->item as $item) { | |
$namespace = $item->getNameSpaces(true); | |
$itunes = $item->children($namespace['itunes']); | |
echo "<tr>"; | |
if (isset($item->enclosure)) { | |
$url= $item->enclosure['url']; | |
$title = $item->title; | |
$size = $item->enclosure['length']; | |
$time = $itunes->duration; | |
$parsed = date_parse($time); | |
$duration = $parsed['hour'] * 3600 + $parsed['minute'] * 60 + $parsed['second']; | |
echo "<td><a href=\"$url\">$title</a></td><td>$size</td><td>$duration</td>"; | |
} | |
echo "</tr>"; | |
} | |
echo "<table>"; | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$itunes->image->attributes()->href