#!/usr/bin/php
<?
/*
*play.php for tetravex oggserv by Edd Barrett adapted by chris kimber
*hide@address.com
*/
include "conf.php";
//INITIALISE THE DATABASE
$dbinit="UPDATE oggserv_main SET playlist_progress=0";
mysql_query($dbinit,$link);
$drop="DELETE FROM oggserv_playlist";
mysql_query($drop,$link);
$track_no="1";
//This is here so that php dosent complain
$kill="8";
//do it...
function playlist(&$cheese){
include "conf.php";
$sql56="UPDATE oggserv_main SET random=0";
mysql_query($sql56,$link);
//This loop continues until no track can be found in mysql corresponding to $track_no
while($end!="1"){
//get the filename of the track we are going to ogg123
$sql2="SELECT media_id FROM oggserv_playlist WHERE play_id=$cheese";
$result=mysql_query($sql2,$link);
$row=mysql_fetch_array($result);
$media_id=$row['media_id'];
//See if that was the end of the list
if (!$media_id){
$end="1";
}
//If thats the last track then we dont need to exec anything
if ($end!="1"){
//Tell mysql what track is being played so that we can get it thru the web interface
$sql3="UPDATE oggserv_main SET current_track=$media_id,playlist_progress=$cheese";
mysql_query($sql3,$link);
//get the filename
$sql99="SELECT filename FROM oggserv_media WHERE media_id=$media_id";
$result=mysql_query($sql99,$link);
$row=mysql_fetch_array($result);
$filename=$row['filename'];
//Lets go! NOTE! back ticks execute!
`ogg123 $path$filename`;
//increment the track_no counter
$cheese+=1;
}
}
//Now thats the end of the playlist so we are going to reset the play pointer to 0 in mysql
//$sql4="UPDATE oggserv_main SET current_track=0";
//mysql_query($sql4,$link);
} //end playlist function
function random(){
include "conf.php";
//weve hit random play mode!
$sql5="UPDATE oggserv_main SET random=1 WHERE id=0";
mysql_query($sql5,$link);
//lets see how long the media table is.
$sql6="SELECT media_id FROM oggserv_media";
$result=mysql_query($sql6,$link);
$num_tracks=mysql_num_rows($result);
//take a random number
$track=rand(0,$num_tracks);
//put this track into the current playing field;
$sql7="SELECT * FROM oggserv_media WHERE media_id=$track";
$result=mysql_query($sql7,$link);
$row=mysql_fetch_array($result);
$fn=$row['filename'];
if (!$fn){
echo "\n\nNo Tracks Found\n\n";
exit();
}
$sql8="UPDATE oggserv_main SET current_track=$track where id=0";
mysql_query($sql8,$link);
//and execute
`ogg123 $path$fn`;
} //end random function
//MAIN STARTS HERE
echo "\n\n\n\n\n\n\n\n\n\n\nWelcome to Tetravex Oggserv:OggBox $vers\n\n";
echo "Config Dir=$path\n\n";
echo "OK! Lets Go!\n\n";
flush();
while ($kill!="1"){
$sql0="SELECT * FROM oggserv_playlist WHERE play_id=$track_no";
$result=mysql_query($sql0,$link);
$yesno=mysql_num_rows($result);
if (!$yesno){
echo "\n[RANDOM TRACK]\n";
random();
echo "\nOGG123 ENDED\n\n";
} else {
echo "\n[USER SELECTED TRACK]\n";
playlist($track_no);
echo "\nOGG123 ENDED\n";
}
}//end while
?>