Public feed #727211

Something

public php v1 · immutable
Raw Edit
·published 2007-10-05 20:57 UTC
rendered paste body
<?phpfunction sourceforge_mirrors($url) {	$mirrors = array('jaist', 'nchc', 'optusnet', 'belnet', 'switch', 'mesh', 		'ovh', 'dfn', 'heanet', 'surfnet', 'kent', 'umn', 'easynews', 		'internap', 'superb-east', 'superb-west', 'ufpr');	if(!preg_match(		'@^http://(?:prdownloads|downloads|[a-z-]+\.dl)\.sourceforge\.net(?:/sourceforge)?/'.		'([a-zA-Z][a-zA-Z0-9-]*)/([a-zA-Z0-9_.-]+)(\?.*)?@',		$url, $m)	) {		return FALSE;	}	foreach($mirrors as $mirror) {		$urls[] = "http://$mirror.dl.sourceforge.net/sourceforge/$m[1]/$m[2]";	}	return $urls;}function mysql_mirrors($url) {	if(!preg_match(		'@^http://dev.mysql.com/get/Downloads/([A-Za-z0-9-_]+)/'.		'([a-zA-Z0-9_.-]+)/from/pick@',		$url, $m)	) {		return FALSE;	}	$dom = new DOMDocument();	$dom->loadHTML(file_get_contents($url));	$xpath = new DOMXPath($dom);	$list = $xpath->query("//div[@id='mirror_list']//a[text()='HTTP' or text()='FTP']");	foreach($list as $node) {		$urls[] = 'http://dev.mysql.com'.$node->getAttribute('href');	}	return $urls;}function chooseRandom($urls, $n=10) {	shuffle($urls);	$urls = array_slice($urls, 0, $n);	return $urls;}//try to guess the type of URL$url = $argv[1];$urls = sourceforge_mirrors($url);if ($urls === FALSE) {	$urls = mysql_mirrors($url);}if ($urls === FALSE) {	$urls = php_mirrors($url);}if ($urls === FALSE) {	die("URL not recognized");}print_r($urls);$cmd = 'aria2c --file-allocation=prealloc '.implode(' ', chooseRandom($urls));passthru($cmd);?>