Re: PHP, MySQL and XML for IPodCasting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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>
	<title>Put your title here [{_dateCheck_}]</title>
<link>Link to your site/the page that explains what this podcast is all about.</link> <description>This is the description... it will show-up in iTunes... yadda yadda...</description>
	<language>en-us</language>
	<copyright>Copyright Info</copyright>
	<lastBuildDate>{_dateLong_}</lastBuildDate>
	<webMaster>Your name here</webMaster>
	<ttl>1</ttl>
	<item>
<title>Name of MP3 podcast - Hour 01, {_dateCheck_}, {_dateSlashes_}</title> <description>Hour 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>
<title>Name of MP3 podcast - Hour 02, {_dateCheck_}, {_dateSlashes_}</title> <description>Hour 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>
<title>Name of MP3 podcast - Hour 03, {_dateCheck_}, {_dateSlashes_}</title> <description>Hour 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( )*1000000);
	$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 "<h1>Please 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux