[PHP] PHP, MySQL and XML for IPodCasting
Hi, I´ve got a web project that daily offers 4 o 5 mp3 files recorded by me. From an web based interface I populate a database with titles, descripcion, images and the path for the mp3 file in the server The cuestion is I would like to offer the content for Ipod, using ipodcasting. Then I have to produce a daily XML file in order the Ipods feed from that file How to proceed Should I create a script to make the well-formed XML file? (echoing to a file based into a template that I´ve got) or is there parser of something like that? which can help me to produce that file The scenario would be PHP 5, MySQL 5.x and Apache 2.0 Thank you in advance Rgards
Re: [PHP] PHP, MySQL and XML for IPodCasting
On Dec 9, 2005, at 3:45 AM, Danny wrote: How to proceed I recently set-up my first Podcast... Every week I have a script that grabs three MP3 files from a remote server and puts them on my own server... Then I have another script that generates the Podcast XML. I am using CRON jobs to do all the work for me... all I have to do is open iTunes and everything starts downloading automatically is nice. The way I generate my XML is via output buffering and a simple text-file template. Here is my template (template.txt): ?xml version=1.0? rss version=2.0 channel titlePut your title here [{_dateCheck_}]/title linkLink to your site/the page that explains what this podcast is all about./link descriptionThis is the description... it will show-up in iTunes... yadda yadda.../description languageen-us/language copyrightCopyright Info/copyright lastBuildDate{_dateLong_}/lastBuildDate webMasterYour name here/webMaster ttl1/ttl item titleName of MP3 podcast - Hour 01, {_dateCheck_}, {_dateSlashes_}/title descriptionHour 01 ({_dateSlashes_}) of this particular podcast./description pubDate{_dateLong_}/pubDate enclosure url=http://www.yoursite.com/location_of_podcast_mp3/mp3_name- {_dateShort_}.mp3 length=10800040 type=audio/mpeg/ guid isPermaLink=false{_randNumOne_}/guid /item item titleName of MP3 podcast - Hour 02, {_dateCheck_}, {_dateSlashes_}/title descriptionHour 02 ({_dateSlashes_}) of this particular podcast./description pubDate{_dateLong_}/pubDate enclosure url=http://www.yoursite.com/location_of_podcast_mp3/mp3_name- {_dateShort_}.mp3 length=10800040 type=audio/mpeg/ guid isPermaLink=false{_randNumTwo_}/guid /item item titleName of MP3 podcast - Hour 03, {_dateCheck_}, {_dateSlashes_}/title descriptionHour 03 ({_dateSlashes_}) of this particular podcast./description pubDate{_dateLong_}/pubDate enclosure url=http://www.yoursite.com/location_of_podcast_mp3/mp3_name- {_dateShort_}.mp3 length=10800040 type=audio/mpeg/ guid isPermaLink=false{_randNumThree_}/guid /item /channel /rss Here is my PHP (pod.php): ?php # Error checking: if((isset($_REQUEST['pass'])) ($_REQUEST['pass'] === 'let_me_in') (!empty($_REQUEST['pass']))) { # Begin date: $date_long = date('r'); // Example output: Mon, 21 Nov 2005 05:20:18 -0500 $date_short = date('mdy'); // Example output: 051121 $date_slashes = date('m/d/y'); // Example output: 11/21/05 $date_check = date('l'); #End date. function randNumb() { # Begin random # generation: srand ((double) microtime( )*100); $random_number = rand( ); return $random_number; # End random # generation. } $rand_num_one = randNumb(); $rand_num_two = randNumb(); $rand_num_three = randNumb(); // HTML to be written: ob_start(); readfile($_SERVER['DOCUMENT_ROOT'].'/template.txt'); $contents = ob_get_clean(); @ob_end_clean(); $contents = str_replace('{_dateLong_}',$date_long, $contents); $contents = str_replace('{_dateSlashes_}',$date_slashes, $contents); $contents = str_replace('{_dateShort_}',$date_short, $contents); $contents = str_replace('{_randNumOne_}',$rand_num_one, $contents); $contents = str_replace('{_randNumTwo_}',$rand_num_two, $contents); $contents = str_replace('{_randNumThree_}',$rand_num_three, $contents); $contents = str_replace('{_dateCheck_}',$date_check, $contents); # Now open the file and write contents of template: $fp = fopen($_SERVER['DOCUMENT_ROOT'].'/ path_to_place_where_you_store_the_xml_file/ xml_file_name'.$date_check.'.xml','wb'); // Open for writing only; If the file does not exist, attempt to create it. fwrite($fp, $contents); fclose($fp); } else { echo h1Please Leave Now!/h1; } ? I then use a cron to run the above script every week, like so: GET http://www.your_site.com/pod.php?pass=let_me_in /dev/null Or, instead of using the CRON, you can just got to the script via your browser like so: http://www.your_site.com/pod.php?pass=let_me_in And the XML file will generate itself. Please keep in mind, I quickly slapped this script together... It gets the job done for me... I am sure there are way better ways to do what I am doing... also, the XML template could be more robust (more meta-tags maybe?)... the PHP script could probably use something other than output buffering... If anyone has ideas/thoughts/suggestions for improvements please let me know. HTH, Cheers, Micky -- BCC for Privacy: http://www.cs.rutgers.edu/~watrous/bcc-for-privacy.html My del.icio.us: http://del.icio.us/mhulse -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP, MySQL and XML for IPodCasting
Simply Fantastic!. Thanks a lot! So for me the best solution I think, would be to read the MySQL Table, and produce the XML with a given template from a PHP Script. I will use Scheduled Task instead of CRON... (Sorry, working on windows ;-) ) [Off topic] Could it be tested without an IPod device? I´ve been googling around, but I don´t know much about those devices, and IPodCasters simulators for PC Thanks again, Best Regards. On 12/9/05, Michael Hulse [EMAIL PROTECTED] wrote: On Dec 9, 2005, at 3:45 AM, Danny wrote: How to proceed I recently set-up my first Podcast... Every week I have a script that grabs three MP3 files from a remote server and puts them on my own server... Then I have another script that generates the Podcast XML. I am using CRON jobs to do all the work for me... all I have to do is open iTunes and everything starts downloading automatically is nice. The way I generate my XML is via output buffering and a simple text-file template. Here is my template (template.txt): ?xml version= 1.0? rss version=2.0 channel titlePut your title here [{_dateCheck_}]/title linkLink to your site/the page that explains what this podcast is all about./link descriptionThis is the description... it will show-up in iTunes... yadda yadda.../description languageen-us/language copyrightCopyright Info/copyright lastBuildDate{_dateLong_}/lastBuildDate webMasterYour name here/webMaster ttl1/ttl item titleName of MP3 podcast - Hour 01, {_dateCheck_}, {_dateSlashes_}/title descriptionHour 01 ({_dateSlashes_}) of this particular podcast./description pubDate{_dateLong_}/pubDate enclosure url=http://www.yoursite.com/location_of_podcast_mp3/mp3_name- {_dateShort_}.mp3 length=10800040 type=audio/mpeg/ guid isPermaLink=false{_randNumOne_}/guid /item item titleName of MP3 podcast - Hour 02, {_dateCheck_}, {_dateSlashes_}/title descriptionHour 02 ({_dateSlashes_}) of this particular podcast./description pubDate{_dateLong_}/pubDate enclosure url= http://www.yoursite.com/location_of_podcast_mp3/mp3_name- {_dateShort_}.mp3 length=10800040 type=audio/mpeg/ guid isPermaLink=false{_randNumTwo_}/guid /item item titleName of MP3 podcast - Hour 03, {_dateCheck_}, {_dateSlashes_}/title descriptionHour 03 ({_dateSlashes_}) of this particular podcast./description pubDate{_dateLong_}/pubDate enclosure url= http://www.yoursite.com/location_of_podcast_mp3/mp3_name- {_dateShort_}.mp3 length=10800040 type=audio/mpeg/ guid isPermaLink=false{_randNumThree_}/guid /item /channel /rss Here is my PHP (pod.php): ?php # Error checking: if((isset($_REQUEST['pass'])) ($_REQUEST['pass'] === 'let_me_in') (!empty($_REQUEST['pass']))) { # Begin date: $date_long = date('r'); // Example output: Mon, 21 Nov 2005 05:20:18 -0500 $date_short = date('mdy'); // Example output: 051121 $date_slashes = date('m/d/y'); // Example output: 11/21/05 $date_check = date('l'); #End date. function randNumb() { # Begin random # generation: srand ((double) microtime( )*100); $random_number = rand( ); return $random_number; # End random # generation. } $rand_num_one = randNumb(); $rand_num_two = randNumb(); $rand_num_three = randNumb(); // HTML to be written: ob_start(); readfile($_SERVER['DOCUMENT_ROOT'].'/template.txt'); $contents = ob_get_clean(); @ob_end_clean(); $contents = str_replace('{_dateLong_}',$date_long, $contents); $contents = str_replace('{_dateSlashes_}',$date_slashes, $contents); $contents = str_replace('{_dateShort_}',$date_short, $contents); $contents = str_replace('{_randNumOne_}',$rand_num_one, $contents); $contents = str_replace('{_randNumTwo_}',$rand_num_two, $contents); $contents = str_replace('{_randNumThree_}',$rand_num_three, $contents); $contents = str_replace('{_dateCheck_}',$date_check, $contents); # Now open the file and write contents of template: $fp = fopen($_SERVER['DOCUMENT_ROOT'].'/ path_to_place_where_you_store_the_xml_file/ xml_file_name'.$date_check.'.xml','wb'); // Open for writing only; If the file does not exist, attempt to create it. fwrite($fp, $contents); fclose($fp); } else { echo h1Please Leave Now!/h1; } ? I then use a cron to run the above script every week, like so: GET http://www.your_site.com/pod.php?pass=let_me_in /dev/null Or, instead of using the CRON, you can just got to the script via your browser like so: http://www.your_site.com/pod.php?pass=let_me_in And the XML file will generate itself. Please keep in mind, I quickly slapped this script together... It gets the job done for me... I am sure there are way
Re: [PHP] PHP, MySQL and XML for IPodCasting
On Dec 9, 2005, at 1:45 PM, Danny wrote: Simply Fantastic!. Thanks a lot! Sure thing, I am glad that I was able to help/give you some ideas. :) So for me the best solution I think, would be to read the MySQL Table, and produce the XML with a given template from a PHP Script. I will use Scheduled Task instead of CRON... (Sorry, working on windows ;-)) That sounds like the perfect solution! :D [Off topic] Could it be tested without an IPod device? I´ve been googling around, but I don´t know much about those devices, and IPodCasters simulators for PC Great question! :) [Double OT:] Podcast/Podcasting, IMHO, is about the worst name the founders could have given this technology... To me, POD sounds like a proprietary APPLE technology/product - maybe only to be used with an iPod? When, in all actuality, Podcasts/Podcasting can be used/played by many different apps on many different platforms - and no need for an iPod! Also, it is not restricted to iPods, I think just about any contemporary MP3 player can import Podcasts... Well, that is my two cents on this OT subject. :) [/Double OT] To answer your question: iPodder (PC) is probably what you are looking for: http://www.ipodder.org/ Here is a nice tutorial on how to download streams: http://www.jakeludington.com/archives/000406.html I am sure that the latest/next version of Windows Media Player will probably let you download Podcasts... Not too sure though, I am on a Mac. A few notes: -- What is Podcasting? Podcasting (iPod + broadcasting) is a new kind of radio for your computer and/or MP3 player. Podcasting allows you to save and listen to your favorite radio programs when and where you want. -- How Podcasting works. A broadcaster makes digital audio files available on the Internet. Listeners subscribe to these programs using podcasting software. The listener's computer automatically downloads the audio files, which can then be listened to on the computer or transferred to a portable MP3 audio player. -- How do you get started? In order to receive podcasts you need a computer, an Internet connection, and podcasting software. To take a podcast with you, an iPod or any portable MP3 player is also needed. The podcasting software includes programs that allow your computer to automatically receive audio files of specified broadcast programs over the Internet. Then you can either listen to the programs on your computer or have them downloaded to your portable audio player. Hope that helps! Good luck, Cheers, Micky -- ¸.·´¯`·.¸¸(((º`·.¸¸.·´¯`·.¸¸º ·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸º `·.¸¸º¸.·´¯`·.¸¸º -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php