Os dejamos un pequeño script muy útil realizado por Skyflare para descargar canciones o álbumes de bandcamp.

ejemplo de canción: http://inspiredfligh…-always-takes-2
ejemplo de album: http://inspiredfligh…all-want-to-fly
ejemplo de uso: http://prntscr.com/2010i0

Por qué no hacerlo multihilo? multiproceso?
Por compatibilidad + es un script básico y posiblemente lo utilicen cuatro. lol.

Cambios:
– Añadida la posibilidad de descargar albumes completos.
– Cambio del auto-replace por compatibilidad con ‘ ‘ en vez de ‘_’.
– Cambio el tiempo de espera de 3 a 1 cuando la canción ha terminado de descargar.

<?php
set_time_limit(0);

if(!isset($argv[1]))
	exit("Usage: php downloader.php {TRACK_URL}\nEG: php downloader.php \"http://inspiredflight.bandcamp.com/track/it-always-takes-2\"");
	
if(!is_dir("downloads"))
	mkdir("downloads");
chdir("downloads");

$songs = array();

preg_match("/\/album\/([^.]+)/i", $argv[1], $album);
if(count($album) == 0) {
	$songs[substr($argv[1], strrpos($argv[1], 'track/') + 6)] = $argv[1];
} else {
	$alname = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), ' ', $album[1]);
	if(!is_dir($alname)) mkdir($alname);
	chdir($alname);
	$album = file_get_contents($argv[1]);
	$album = substr($album, strpos($album, "trackinfo :") + 13);
	$album = substr($album, 0, strpos($album, "],"));
	$album = json_decode('[' . $album . ']');
	foreach($album as $i => $u)
		$songs[$u->title] = substr($argv[1], 0, strrpos($argv[1], '/album/')) . $u->title_link;
}

print "Working Directory: " . getcwd() . PHP_EOL;


foreach($songs as $i => $u) {
	try {
		/* Get song information */
			$file = @file_get_contents($u);
			if($file === false)
				throw new Exception("We couldn't find a song at \"{$u[1]}\".");
			$trim  = substr($file, strpos($file, "trackinfo:") + 12);
			$trim  = substr($trim, 0, strpos($trim, "],"));
			$song  = json_decode($trim);
			print "Attempting to download: {$song->title}" . PHP_EOL;
			/* I know the title is in $i, but it's lowercased. */
			$song->title = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), ' ', $song->title);
		/* Get song download URL */
			$links = array_values((array) $song->file);
				$socket = fsockopen(substr($links[0], 7, strpos($links[0], '/', 7) - 7), 80);
				$write  = "GET " . (substr($links[0], strpos($links[0], "/d"))) . " HTTP/1.1\r\n";
				$write .= "Host: " . substr($links[0], 7, strpos(substr($links[0], 7), "/")) . "\r\n\r\n";
				fwrite($socket, $write);
				$header = fread($socket, 1204);
				fclose($socket);
		/* Download song */
			$dnld = substr($header, strpos($header, "Location: ") + 10);
			$dnld = substr($dnld, 0, strpos($dnld, "\r"));
				$socket = fsockopen(substr($dnld, 7, strpos($dnld, '/', 7) - 7), 80);
				$write  = "GET " . substr($dnld, strpos($dnld, "/", 7)) . " HTTP/1.1\r\n";
				$write .= "Host: " . substr($dnld, 7, strpos(substr($dnld, 7), "/")) . "\r\n\r\n";
				fwrite($socket, $write);
				touch("./{$song->title}.mp3");
				list($read, $null, $data, $clen, $fhandle) = array(array($socket), null, "", 0, fopen("./{$song->title}.mp3", "w"));
				$len = fread($read[0], 1204);
				$len = substr($len, strpos($len, "Content-L") + 16);
				$len = substr($len, 0, strpos($len, "\r"));
				while(@stream_select($read, $null, $null, 1) > 0) {
					$data = fread($read[0], 2048);
					if($data == "") break;
					fwrite($fhandle, $data);
					$clen += strlen($data);
					print "\rDownloaded " . number_format($clen / $len * 100, 2) . "%";
				}
		/* END fun stuffs */
		print PHP_EOL . "Download complete";
		print PHP_EOL . "Downloaded song was saved to " . getcwd() . str_repeat(PHP_EOL, 3);
	} catch(Exception $e) { print $e->getMessage(); }
}
print PHP_EOL . "Press Enter to continue."; fgets(STDIN);
exit;
?>