<?php	
	if(!isset($_GET['track'])) die("No Input");
	$song = $_GET['track'];
	$directory = '/yuttadhammo/siri/static/diraudio/Yuttadhammo';
	$trackloc = $directory."/".$song.'.mp3';
error_log($trackloc);
if(!file_exists($trackloc)) die();
	// include getID3() library (can be in a different directory if full path is specified)
	require_once('/yuttadhammo/siri/static/getid3/getid3.php');

                // Initialize getID3 engine
                $getID3 = new getID3; 
                $ThisFileInfo = $getID3->analyze($trackloc);

                $myFileSize=filesize($trackloc);
                
                $mp3_title = @$ThisFileInfo['tags']['id3v2']['title'][0];
                
                if (!$mp3_title) $mp3_title = @$ThisFileInfo['tags']['id3v1']['title'][0];
                
                $mp3_comment = @$ThisFileInfo['tags']['id3v2']['comments'][1]; // comment from ID3v2

                $mp3_comment_extra = @$ThisFileInfo['tags']['id3v2']['comments'][0];
                if (!$mp3_comment || (isset($mp3_comment_extra) && strlen($mp3_comment_extra) > strlen($mp3_comment))) $mp3_comment = @$ThisFileInfo['tags']['id3v2']['comments'][0];
                if (!$mp3_comment) $mp3_comment = @$ThisFileInfo['tags']['id3v1']['comment'][0];

                $mp3_comment = utf8_encode(str_replace('&','&amp;',$mp3_comment));
                $mp3_title = utf8_encode(str_replace('&','&amp;',$mp3_title));
//              var_dump($ThisFileInfo['tags']);
        
                if ($mp3_title) $trackname = $mp3_title;
                else $trackname = preg_replace('/^.*\//','',$song);
                if($trackname == 'þ') $trackname = substr($song,7,-4);
                if (!$mp3_comment) $mp3_comment = $trackname;

                $ty = substr($song,0,2);
                $tm = substr($song,2,2);
                $td = substr($song,4,2);
                $dtime = strtotime($td.'-'.$tm.'-20'.$ty);
                
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<link rel="image_src" href="http://static.sirimangalo.org/images/portrait_square.jpg" />
<link rel="alternate" type="application/rss+xml" title="Truth Is Within &raquo; Audio Feed" href="http://static.sirimangalo.org/diraudio/Yuttadhammo/rss.php" />
<link rel='stylesheet' href='http://static.sirimangalo.org/css/mp3.css' type='text/css' media='all' />
<?php if ($mp3_comment) echo '<meta name="description" content="'.$mp3_comment.'" />
'; ?>
<title><?php
echo '(MP3) '.$trackname;
if ($mp3_comment) echo " - ".$mp3_comment;
?></title>
</head>
<body>
	<div id="content">
		<h1><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/8/87/Gnome-mime-sound-openclipart.svg/120px-Gnome-mime-sound-openclipart.svg.png" id="icon"/><?php
		echo $trackname;
		?></h1>
		<p id="comment"><?php
		echo $mp3_comment;
		?></p>
		<p id="player">
<?php if (!isset($_GET['test'])) { ?>
			<object type="application/x-shockwave-flash" data="http://flash-mp3-player.net/medias/player_mp3_maxi.swf" height="20" width="400">
				<param name="movie" value="http://flash-mp3-player.net/medias/player_mp3_maxi.swf"/>
				<param name="bgcolor" value="#ffffff"/>
				<param name="FlashVars" value="mp3=http%3A//static.sirimangalo.org/diraudio/Yuttadhammo/<?php echo $song; ?>.mp3&amp;width=400&amp;autoplay=1&amp;showstop=1&amp;showinfo=1&amp;showvolume=1&amp;buttonwidth=20&amp;volumewidth=40&amp;bgcolor1=00aa00&amp;bgcolor2=007700&amp;slidercolor2=aaaaaa&amp;sliderovercolor=ffff52"/>
			</object>
<?php } ?>
		</p>
		<p id="download">
			<a href="http://static.sirimangalo.org/diraudio/Yuttadhammo/<?php echo $song; ?>.mp3" target="_blank">Download MP3</a>
		</p>
		<p id="note">
			<i>This file can also be found, along with this site's whole collection of audio dhamma, at: <br/><br/><a href="http://static.sirimangalo.org/diraudio/Yuttadhammo/audio.php">http://static.sirimangalo.org/diraudio/Yuttadhammo/audio.php</a>
			</i>
		</p>
		<p id="subscribe">
			<i>
				You can also <a href="http://static.sirimangalo.org/diraudio/Yuttadhammo/rss.php">subscribe to the audio podcast rss feed here</a>.
			</i>
		</p>
	</div>
</body>
</html>


