My own RSS for music files from PHP
If you have read the previous post about the Website Music Player than you should be able to understand a little more about what is said in this post.
I was searching for hours and hours the other day and found some snippets of code to generate my music RSS and wow I love IT! I used PHP and xml to generate the RSS format.
I first had thought about how I generated the .xml code from the media player list and then found some things that could help in order to generate the correct information for the RSS feed.
So here is the code that I made that works:
(put this code in a music_rss.php file)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | <?php $dir = "mp3"; $url = "http://www.thomasnorberg.com/mediaplayer/playerMultipleMenuPackage"; $email = "tnorberg at thomasnorberg dott com (Thomas Norberg)"; $name = "Tom's Blog"; $n = 0; $playlist = array(); $fdir = opendir($dir); while($i = readdir($fdir)) { // if a .mp3 string is found, add the file to the array if (strpos(strtolower($i),".mp3") !== false){ $playlist[$n] = $i; $n++; } } //sort($playlist); //shuffle($playlist); //array_multisort($playlist); $ttl = 1440; $music_rss = "$url/playlist22.php"; header('Content-type: application/xml'); $rss_output = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\n"; $rss_output .= "<rss xmlns:atom='http://www.w3.org/2005/Atom/' version='2.0'>\n"; $rss_output .= "<channel>\n\n"; $rss_output .= "<atom:link href='$music_rss' rel='self' type='application/rss+xml' />\n"; $rss_output .= "<title>$name Music RSS</title>\n"; $rss_output .= "<description>Where anything is everything</description>\n"; $rss_output .= "<link>$url/$dir</link>\n"; $rss_output .= "<language>en-us</language>\n"; $rss_output .= "<ttl>$ttl</ttl>\n"; for ($j=$n-1; $j>$n-11; $j--) { $title = str_replace(".mp3","", $playlist[$j]); $title = str_replace("_", " ", $title); $other = str_replace(" ", "%20", $playlist[$j]); $files = "$dir{$playlist[$j]}"; $filetime = filectime($files); $size = filesize($files); $rss_output .= "\n<item>\n\n"; $rss_output .= "<title>$title</title>\n"; $rss_output .= "<link>$url/$dir/{$other}</link>\n"; $rss_output .= "<pubDate>" . date ("r", $filetime); $rss_output .= "</pubDate>\n"; $rss_output .= "<enclosure url='$url/$dir/{$other}' type='audio/mpeg' length='$size' />\n"; $rss_output .= "<guid>$url/$dir/{$other}</guid>\n"; $rss_output .= "<author>$email</author>\n"; $rss_output .= "</item>\n"; } $rss_output .= "</channel>\n</rss>\n"; echo $rss_output; closedir($fdir); ?> |
This is what it should look like. Of course you have to change all the appropriate titles and everything or your won’t have anything to show on your RSS feed, such as the top three lines of code in the music_rss.php file:
1 2 3 4 5 6 | <?php $dir = "mp3"; $url = "http://www.thomasnorberg.com/mediaplayer/playerMultipleMenuPackage"; $email = "tnorberg at thomasnorberg dott com (Thomas Norberg)"; $name = "Tom's Blog"; |
And as always if you have any questions or comments please fell free to ask.
Popularity: 1%
Related Posts
- MP3 Player v1.2.1 added and extras I have added the new mp3 Player plugin v1.2.1 It...
- Top 15 wordpress 2.7.1 plugins There is a lot of "stuff" on my page and...
- Website Music Player I am finally able to sit down and tell you...
- Javascript Confirmation and variations Regular confirmation java <script type="text/javascript"> <!-- function confirmation() { var...
- Top 20 BlackBerry Mobile Apps for Organization and Productivity [/caption] iPhone this, G1 that, where is all of the...
- The Crawling Chaos of EffectiveCleanse Introduction ...which is Jake's Hollywood Workout. It's actually a male-focussed...
- SEO Principles for WordPress Blogs WordPress is a relatively SEO friendly blogging tool to begin...
- More traffics with Digg Button on your blog This is a step-by-step guide to automatically place a real-time...


Firefox