\n".htmlspecialchars(trim($url))."\n
".htmlspecialchars(trim($tracktitle))."\n".htmlspecialchars(trim($artist))."\n".$duration."000\n";
}
$lines = explode("\n",file_get_contents('playlist.m3u'));
$currentline = 0;
$nblines = count($lines);
/* Example line:
#EXTINF:404,Jon Hopkins - The End
^ ^ ^ track title
^ ^ artist name
^ duration (in seconds)
The next line contains the URL.
This has to be transformed to:
*/
$tracks = array();
while ($currentline<$nblines ) {
$line = $lines[$currentline];
if (startsWith($line,'#EXTINF:')) {
$data = substr($line, 8); // Remove #EXTINF:
// Extract duration (in seconds)
$j = strpos($data,',');
$duration = intval(substr($data, 0, $j));
$data = substr($data, $j+1);
// Extract artist and track title
$k = strpos($data, ' - ');
$artist = substr($data, 0, $k);
$tracktitle = substr($data, $k+3);
// Get URL in next line
$url = $lines[$currentline+1];
$currentline = $currentline + 1;
$tracks[] = buildTrackXspf($artist,$tracktitle,$duration,$url); // Build XSPF XML for this track
}
$currentline = $currentline + 1;
}
shuffle($tracks);
echo <<
Alternative musics for Minecraft gameplay
XML;
foreach ($tracks as $track) {
echo $track;
echo "\n";
}
echo <<
XML;
?>