Skip to content

Instantly share code, notes, and snippets.

@jasontucker
Created December 11, 2015 00:41
Show Gist options
  • Save jasontucker/c5f9103f4e4a43aa2128 to your computer and use it in GitHub Desktop.
Save jasontucker/c5f9103f4e4a43aa2128 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>
@xwells001
Copy link

Hello Jason Tucker,
Thank you very much for this code. I really find it very useful.
The only problem I am facing is that I don't know how to get the itunes image url from the rss feed.
For example, consider the following rss feed item:

<itunes:image href="https://the-link-to-image.jpg"/>

I have tried the following code:

             $imageurl      = $itunes->image;  

but it didn't work. I also tried the following:

            $imageurl       = $itunes->image['href'];

it did not also work for me.

Could you please help me with the right code to get the itunes:image url from the rss feed.

Thanks alot.

@Slasiyal
Copy link

Hello Jason Tucker,
Thank you very much for this code. I really find it very useful.
The only problem I am facing is that I don't know how to get the itunes image url from the rss feed.
For example, consider the following rss feed item:

<itunes:image href="https://the-link-to-image.jpg"/>

I have tried the following code:

             $imageurl      = $itunes->image;  

but it didn't work. I also tried the following:

            $imageurl       = $itunes->image['href'];

it did not also work for me.

Could you please help me with the right code to get the itunes:image url from the rss feed.

Thanks alot.

$itunes->image->attributes()->href

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment