Location: PHPKode > projects > Axis Groupware > musiclib/unused/tunez/tunezd.php
#!/usr/bin/php -q

<?
#$debug = true;
// Make mysql_pconnection
mysql_pconnect("localhost", "tunez", "tun3z");
mysql_select_db("tunez");

function playsong($song_id, $is_random)
{
	global $mode;

	mysql_query("DELETE FROM np");

	$result = mysql_query("SELECT filename FROM songs WHERE song_id = $song_id");
	$row = mysql_fetch_array($result);
	$filename = $row[0];

	mysql_query("INSERT INTO np VALUES('$song_id')");

        //$filename = addslashes($filename);
	

	if ($is_random == 0) // song not randomly chosen
	{
		mysql_query("DELETE FROM queue WHERE song_id = $song_id");
		mysql_query("UPDATE songs SET timesPlayed=timesPlayed + 1 WHERE song_id = $song_id");
	}

	if ($mode=="stream")
	{
		$cmd = "shout localhost -P tun3z -x -n 'This is Tunez' '$filename' > /dev/null 2> /dev/null";
	}
	else
	{
		$cmd = "/usr/local/bin/mpg123 \"$filename\" >/tmp/tunezlog 2>/tmp/tunezlog2";
	}
	exec($cmd);
}

while(1+1) { // Eternal loop

	$queue = mysql_query("SELECT *, count(*) AS votes FROM queue LEFT JOIN songs ON queue.song_id=songs.song_id GROUP BY filename ORDER BY votes DESC, timestamp");
	$entries = mysql_numrows($queue);

	if ($entries == 0) 
	{
//		$max_id = mysql_result( mysql_query("SELECT max(song_id) as max_id from songs"),0,max_id);
//		srand((double)microtime()*1000000);
//		$song_id = rand(0,$max_id); //doesnt take empty ones into account

		$song_id = mysql_result( mysql_query("select * from songs WHERE playInRandomMode = 1 ORDER BY RAND() limit 1"),0,song_id);
		

		playsong($song_id, 1);
	}
	else
	{
		$song_id = mysql_result( mysql_query("SELECT queue.song_id, count(*) AS votes FROM queue LEFT JOIN songs ON queue.song_id=songs.song_id GROUP BY filename ORDER BY votes DESC,timestamp"),0,song_id);

		playsong($song_id, 0);
	}

}

mysql_close();

?>


Return current item: Axis Groupware