<?php
### Set MIME-Type

# Parameters:
# $mp3f:    mp3 file like "tr0xab10f90c-4.mp3"
# $playtp:  play method. 
#			  "rd" Redirect URL
#			  "df" Dynamically generate mp3 file
#			  "pr" Winamp m3u Playlist remote file (URL)
# $locpath: local path to mp3 directories like "E:\"

include "gdweb.php";
if(isset($mp3f)){
  $mp3path = full_mp3_fname($mp3f);
}

$httphost = $_SERVER["HTTP_HOST"];

### Dynamically send file
if (strcmp($playtp, "df")==0){
  header("Content-Type: audio/mp3");
  header("Content-Location: ".$mp3path);
  #header("Content-Disposition: filename=".$mp3path);
  if(!readfile($mp3path));
  exit; # if file doesn't exist, id3 tag is not correctly displayed in winamp!
}


##########################################################################
### Winamp Playlist remote file (URL / http)
if (strcmp($playtp, "pr")==0 && !isset($prAlbum)){
  $ds = mysql_connect();	
  $recset = mysql_db_query ("GiantDisc", "SELECT * FROM tracks WHERE id=".$id." ");
  if($row = mysql_fetch_array($recset)) {
    header("Content-disposition: inline; filename=foo.m3u");
    header("Content-Type: audio/x-mpegurl");
    header("Content-Location: foo.m3u");
    print "#EXTM3U\n";
    print "#EXTINF:".$row[length].",".$row[artist]." - ".$row[title]."\n";
    print "http://$httphost/~music/webint/".$mp3path."\n";
    mysql_free_result($recset);
  }

exit;
# Test
?>
#EXTM3U
#EXTINF:-1,tr0xb80d430f-3.mp3
http://192.168.1.1/~music/webint/musichome/00/tr0xb80d430f-3.mp3
<?php
exit;
}


##########################################################################
### Winamp Playlist for album (by Merlot)
if(isset($prAlbum))
{
  $ds = mysql_connect();
  $sql="SELECT * FROM tracks WHERE sourceid='".$albid."' ORDER BY tracknb ";
  $recset = mysql_db_query ("GiantDisc", $sql);

  header("Content-Type: audio/mpegurl");
  header("Content-Location: test.m3u");
  print "#EXTM3U\n";
  while($row = mysql_fetch_array($recset)) {
   print "#EXTINF:".$row[length].",".$row[artist]." - ".$row[title]."\n";
   print $mp3file;
   $mp3path = full_mp3_fname($row[mp3file]);
   print "http://$httphost/~music/webint/".$mp3path."\n";; 
}
   mysql_free_result($recset);
exit;
}

##########################################################################
### Redirect to mp3 file
if (strcmp($playtp, "rd")==0){
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Refresh" content="0; URL=<?php print $mp3path;?> "> 
<title>mp3 redirector</title>
</head>
<body>
mp3 redirector
<br>
download file <?php print $mp3f; ?>
</body>
</html>
<?php
}
?>

