Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save multiomer1997/85decef6e7b44ade9eaac783786ed1a8 to your computer and use it in GitHub Desktop.
Save multiomer1997/85decef6e7b44ade9eaac783786ed1a8 to your computer and use it in GitHub Desktop.
Parses enclosure urls from iTunes RSS feed
<?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