<?php print '<?xml version="1.0" encoding="utf-8"?>'; ?>

<?php
function dir_list($dir)
{
	if ($dir[strlen($dir)-1] != '/') $dir .= '/';
	
	if (!is_dir($dir)) return array();
	
	$dir_handle  = opendir($dir);
	$dir_objects = array();
	while ($object = readdir($dir_handle))
	if (!in_array($object, array('.','..','.html')))
	{
		$filename = $dir . $object;
		$name = split(".mp4", $object);
		$url = urlencode($object);
		$url = str_replace('%2F54', '/', $url);
		$url = str_replace('+' , '%20' , $url);
	  if (sizeof($name) > 1) {
			$file_object = array(
															'url' => $url,
															'name' => $name[0],
															'size' => filesize($filename),
															'time' => filemtime($filename)
													);
			$dir_objects[filemtime($filename)] = $file_object;
	  }
	}

	return $dir_objects;
}
?>

<?php
 function print_video_item($file, $pubdate_formatted) { ?>
	<item>
  	<itunes:author>jonny moiree</itunes:author>
		<title><?php print $file['name']; ?></title>
    <category>Podcasts</category>
		<description>Music video: <?php print $file['name']; ?></description>
		<link>http://jonnymoiree.com/videos/<?php print $file['url']; ?></link>
		<author>jonny@jonnymoiree.com (Jonny Moiree)</author>
		<enclosure url="http://jonnymoiree.com/videos/<?php print $file['url']; ?>" length="<?php print $file['size']; ?>" type="video/mp4" />
		<guid isPermaLink="false">http://jonnymoiree.com/videos/<?php print $file['url']; ?></guid>
		<pubDate><?php print $pubdate_formatted; ?></pubDate>
		<source url="http://jonnymoiree.com/">dj jonny moiree</source>
	</item>
  <?php
  }
?>

<?php
// Sun, 30 Mar 2008 22:37:44 -0700
// $today = date("D, j M Y G:i:s O");
$midnight = mktime(0, 0, 0);
$midnight_formatted = date("D, j M Y H:i:s O", $midnight);
$files = dir_list('videos');
ksort($files);
?>

<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">

<channel>
	<title>dj jonny moiree - music videos</title>
	<description>daily dance music videos for your ipod/iphone!  iphone users: view under "videos" not "podcasts"!  internationally worshipped, often imitated and ridiculously stalked, dj jonny moiree is no stranger to the hedonistic globetrotting hero-worship deejay culture. always fresh, never predictable, he&apos;s a surprisingly shy figure on the dance music scene.</description>
	<link>http://jonnymoiree.com/</link>
	<itunes:author>jonny moiree</itunes:author>
  <language>en-gb</language>
	<copyright>2008 jonny moiree</copyright>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<itunes:summary>daily dance music videos for your ipod/iphone!  iphone users: view under "videos" not "podcasts"!  internationally worshipped, often imitated and ridiculously stalked, dj jonny moiree is no stranger to the hedonistic globetrotting hero-worship deejay culture. always fresh, never predictable, he&apos;s a surprisingly shy figure on the dance music scene.</itunes:summary>
	<itunes:owner>
				 <itunes:name>jonny moiree</itunes:name>
				 <itunes:email>jonny@jonnymoiree.com</itunes:email>
	</itunes:owner>
	<itunes:explicit>No</itunes:explicit>
	<itunes:image href="http://jonnymoiree.com/mixes/jonny.gif"/>
	<itunes:category text="Music"></itunes:category>

	<lastBuildDate><?php 
		// midnight earlier today
		print $midnight_formatted;
	?></lastBuildDate>
	<managingEditor>jonny@jonnymoiree.com</managingEditor>
	
	<pubDate><?php 
		// midnight earlier today
		print $midnight_formatted;
	?></pubDate>
	<webMaster>jonny@jonnymoiree.com</webMaster>
	
	<?php
	$count = 0;	
	foreach($files as $timestamp => $file) {
	  // Set timestamp to be April 24, 2008 + $count number of days.
	  $pubdate = mktime(0, 0, 0, 4, 24 + $count, 2008);
	  $pubdate_formatted = date("D, j M Y 00:00:00 O", $pubdate);
	  
	  if ($pubdate < $midnight) { 
			print_video_item($file, $pubdate_formatted);
			$count++;
	  }
	}
?>

</channel>
</rss>