$value)
$string = str_replace($value[0], $value[1], $string);
return $string;
}
// some time calculations
function timestamp_to_human($timestamp, $hour, $min, $sec)
{
// for this there should be a php standard function *grrr*
$hour = floor($timestamp / (60*60));
$timestamp = $timestamp % (60*60);
$min = floor($timestamp / 60);
$sec = $timestamp % 60;
if($hour < 10) $hour = "0".$hour;
if($min < 10) $min = "0".$min;
if($sec < 10) $sec = "0".$sec;
}
// start
message($wget, "Starting Domian downloader...\r\n");
message($wget, $VERSION."\r\n");
set_time_limit(0);
// create needed dirs, if not already exist
$dir_array = array("/", "/hq", "/lq", "/inter");
foreach($dir_array as $key => $dir_add) {
if(!file_exists($wget["local_download_dir"].$dir_add)) mkdir($wget["local_download_dir"].$dir_add, 0777);
if(!file_exists($wget["local_download_dir"].$dir_add)) die("FATAL: could not create needed dir \"".$wget["local_download_dir"].$dir_add."\"\n");
}
// get downloads...
$archive_page = file($wget["remote_archive_page"]);
$interest_page = file($wget["remote_interest_page"]);
if(isset($downloads)) unset($_downloads);
// ... from archive page
if($wget["download_style"] != "nothing")
foreach($archive_page as $key => $line) {
if(strpos($line, ".mp3")) {
// split mp3 links
$temp = substr($line, strpos($line, ""));
// get quality
$quality = "";
if(strpos($temp, "/lq/")) $quality = "lq";
elseif(strpos($temp, "/hq/")) $quality = "hq";
// filter through $wget["download_style"]
if(($wget["download_style"] == "hq" && !strpos($temp, "/hq/")) || ($wget["download_style"] == "lq" && !strpos($temp, "/lq/"))) $temp = "";
// filter through recently downloaded files
if($temp != "") {
$file_name = unhtmlentities(substr($temp, strrpos($temp, "/")));
if(file_exists($wget["local_download_dir"]."/".$quality."/".$file_name)) $temp = "";
}
// wow, one file to download :-)
if($temp != "") {
$file_path = substr($temp, 0, strrpos($temp, "/"));
$downloads[] = $file_path.convert_to_unix_chars($file_name)."###".$quality;
}
}
}
// ... from interest page
if($wget["download_interest_stuff"] == "yes") {
$quality = "inter";
foreach($interest_page as $key => $line) {
if(strpos($line, ".mp3")) {
// split mp3 links
$temp = substr($line, strpos($line, ""));
// filter through recently downloaded files
if($temp != "") {
$file_name = unhtmlentities(substr($temp, strrpos($temp, "/")));
if(file_exists($wget["local_download_dir"]."/".$quality."/".$file_name)) $temp = "";
}
// wow, one file to download :-)
if($temp != "") {
$file_path = substr($temp, 0, strrpos($temp, "/"));
$downloads[] = $file_path.convert_to_unix_chars($file_name)."###".$quality;
}
}
}
}
// log count
$count_downloads = 0;
if(isset($downloads)) $count_downloads = count($downloads);
message($wget, "Found ".$count_downloads." new domian sequence(s).\r\n");
// sort
if(isset($downloads)) {
if($sort_method = "asc") sort($downloads);
elseif($sort_method = "desc") rsort($downloads);
}
// download the stuff
if(isset($downloads)) {
$i = 0;
foreach($downloads as $key => $line) {
$i++;
// build string
list($link, $quality) = split("###", $line);
$shell_command = build_wget_command($wget, $link, $quality);
$filename = substr($link, strrpos($link, "/")+1);
// execute
message($wget, "Downloading file \"".$filename."\" (".$i." of ".$count_downloads.")... ");
$starttime = time();
$ret_var = 0;
//echo $shell_command; // for debug
system($shell_command, $ret_var);
timestamp_to_human(time() - $starttime, &$hour, &$min, &$sec);
if($ret_var == 0)
message($wget, "finished (in ".$hour.":".$min.":".$sec.")!\r\n", 0);
else
message($wget, "ERROR (file does not exist or no internet connection available)!\r\n", 0);
}
}
message($wget, "Exiting Domian downloader.\r\n\r\n");
// EOF
?>