All pastes #466925 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-05-02 05:34 UTC
rendered paste body
<?php header('Content-type: text/html; charset=UTF-8'); ?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php
	function findMusic($artist, $album, $mainDir)
	{
		$dir = $mainDir.$artist;

		if (!empty($artist))
			$dir .= "/".$album;

		if (is_dir($dir))
		{
			if ($handle = opendir($dir))
			{
				$files = array();
				while(($file = readdir($handle)) !== false)
				{
					if ($file != "." && $file != ".." && $file != ".DS_Store" && $file != "Movies" && $file != "TV Shows")
					{
						if (!empty($artist) && !empty($album))
						{
							if (strstr($file, ".mp3"))
							{
								$audio = ereg_replace(".mp3", "", $file);
								$albumInfo = '&album='.$album;
								$artistInfo = $artist;
								$audioInfo = '&song='.$audio.'.mp3';
								echo $audio.'<br />';
								//echo '<a href="music.php?artist='.$artistInfo.$albumInfo.$audioInfo.'">'.$audio.'</a><br />';
							} else {
								$file = str_replace('.mpg', '', $file);
								$file = str_replace('.mpeg', '', $file);
								$file = str_replace('.aiff', '', $file);
								echo $file.'<br />';
							}
						} else {
							if (!empty($artist))
							{
								$albumInfo = '&album='.$file;
								$artistInfo = $artist;
							} else {
								$artistInfo = $file;
							}
							echo '<a href="music.php?artist='.$artistInfo.$albumInfo.'">'.$file.'</a><br />';
						}
					}
				}
			}
		}
	}

	function playMusic($artist, $album, $song, $mainDir)
	{
		$dir = $mainDir.$artist."/".$album."/";
		$file = $song;
		echo $dir.$file;
		if ($contents = file_get_contents($dir.$file))
		{
			header("Content-type: audio/mpeg");
			die($contents);
		}
	}

	$artist = $_GET['artist'];
	$album = $_GET['album'];
	$song = $_GET['song'];

	if (strstr($artist, ".."))
		die('No ".." please.');
	if (strstr($album, ".."))
		die('No ".." please.');

	$mainDir = "/Volumes/Firefly/iTunes Music/";

	if (!empty($artist) && !empty($album) && !empty($song))
	{
		//playMusic($artist, $album, $song, $mainDir);
		die("Playing music is currently incomplete");
	} else {
		findMusic($artist, $album, $mainDir);
	}
?>