Location: PHPKode > projects > WINR - An iTunes Net Remote > WINR/scripts/getPlaylist.php
<?php
	////
	// 
	// getPlaylist.php
	// Fetch the current playlist's contents from iTunes and format it for the list box.
	// 
	// Copyright (c) 2006 Sean Healy, licensed under The BSD License
	//
	////


	// get the arrays we are working with ready
	// format:
	// <playlist name>
	// <songs in playlist>
	// 
	// <track#>
	// <track name>
	// <track time in sec>
	// <artist name>
	// <album name>
	// <db ID>
	// 
	// <track#>
	// <track name>
	// <track time in sec>
	// <artist name>
	// <db ID>
	// ...
	$info = trim(shell_exec("osascript ../appleScripts/getTracklistInCurrentPlaylist.scpt"));
	$info = explode("\n\n", $info);
	$tmptracks = array_slice($info, 1);
	$tracks = array();
	$info = $info[0];
	
	foreach($tmptracks as $track)
	{
		$tmp = explode("\n", $track);
		
		if($tmp[2] != 0)
		{
			foreach($tmp as $value)
				$value = trim($value);
			
			$min = floor($tmp[2]/60);
			$sec = $tmp[2]%60;
			if(strlen($sec) == 1) $sec .= "0";
			$tmp[2] = "$min:$sec";
			
			array_push($tracks, $tmp);
		}
	}
	
	// tracks is an array of 'track's
	// track structure:
	//   [0] number
	//   [1] name
	//   [2] time in min:sec
	//   [3] artist
	//   [4] album
	//   [5] database ID
		
	$html = '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
	foreach($tracks as $track)
	{
		if($track[0]%2 == 1) $evenOdd = "even"; else $evenOdd = "odd";
		
		$html .= "<tr id=\"$track[5]\" class=\"listItem-$evenOdd\" onclick=\"playTrack($track[0]);\">
					<td class=\"column-name\">$track[1]</td>
					<td class=\"column-time\">$track[2]</td>
					<td class=\"column-artist\">$track[3]</td>
					<td class=\"column-album\">$track[4]</td>
				</tr>";
	}
	$html .= "</table>";
	
	echo $html;
?>
Return current item: WINR - An iTunes Net Remote