采集百度MP3TOP100和TOP500 列表歌曲文件URL的小程序!
<?
//session_save_path("tmp");
session_start();
$file="db.txt";
if(!isset($_SESSION["cai"])){
$_SESSION["cai"]=0;
}
if($_SESSION["cai"]==0 or !isset($_POST["xuanze"])){
echo <<<eot
<center>
<title>『夜无眠音乐采集』</title>
<font color=green>『夜无眠音乐采集』</font><br><br>
你要更新哪部分?
<form method=post action=''>
<input type=radio value=100 name="xuanze" checked>TOP100
<input type=radio value=500 name="xuanze">TOP500<br>
是否观看采集过程:<INPUT TYPE="checkbox" NAME="guankan" checked><br>
后台密码:<input type=password name="password"><br>
<input type=submit value=开始采集 checked>
</form>
<br><font color=red>程序开始采集后请勿随意刷新页面</font>
</center>
eot;
$_SESSION["cai"]=1;
die();
}
$_SESSION["cai"]=0;
if($_POST["password"]!="fzz"){
die("<script>alert('没有密码还想进来捣乱?')</script>");
}
//session_save_path("tmp");
session_start();
$file="db.txt";
if(!isset($_SESSION["cai"])){
$_SESSION["cai"]=0;
}
if($_SESSION["cai"]==0 or !isset($_POST["xuanze"])){
echo <<<eot
<center>
<title>『夜无眠音乐采集』</title>
<font color=green>『夜无眠音乐采集』</font><br><br>
你要更新哪部分?
<form method=post action=''>
<input type=radio value=100 name="xuanze" checked>TOP100
<input type=radio value=500 name="xuanze">TOP500<br>
是否观看采集过程:<INPUT TYPE="checkbox" NAME="guankan" checked><br>
后台密码:<input type=password name="password"><br>
<input type=submit value=开始采集 checked>
</form>
<br><font color=red>程序开始采集后请勿随意刷新页面</font>
</center>
eot;
$_SESSION["cai"]=1;
die();
}
$_SESSION["cai"]=0;
if($_POST["password"]!="fzz"){
die("<script>alert('没有密码还想进来捣乱?')</script>");
}
$i=0;
if($_POST["xuanze"]==100){
$ii=0;
$urltop=" http://list.mp3.baidu.com/list/newhits.html?id=1#top1";
$top=100;
}
else{
$ii=100;
$urltop=" http://list.mp3.baidu.com/topso/mp3topsong.html?id=1#top2";
$top=500;
}
$db=unserialize(@file_get_contents($file));
$input=file_get_contents($urltop);
preg_match_all("/(?:[0-9]{1,3}/.<//td>).*?<//td>/isS",$input,$a);
$ii=0;
$urltop=" http://list.mp3.baidu.com/list/newhits.html?id=1#top1";
$top=100;
}
else{
$ii=100;
$urltop=" http://list.mp3.baidu.com/topso/mp3topsong.html?id=1#top2";
$top=500;
}
$db=unserialize(@file_get_contents($file));
$input=file_get_contents($urltop);
preg_match_all("/(?:[0-9]{1,3}/.<//td>).*?<//td>/isS",$input,$a);
while($i<$top){
set_time_limit(30);
$name=preg_match_all("/blank>(.+?)</",$a[0][$i],$b);
$music=$b[1][0];
$name=$b[1][1];
if(isset($b[1][2])){
$name.="/".$b[1][2];
}
$music=preg_replace("/<b.*?>/is","",$music);
$word=urlencode("{$music}+{$name}");
$url_dqlb=" http://mp3.baidu.com/m?f=ms&rn=&tn=baidump3&ct=134217728&word={$word}&lm=-1";
$db_dqlb=file_get_contents($url_dqlb);
preg_match("/http:.+?word=(?:wma|mp3).+?/d{5}&lm=/d{8}/i",$db_dqlb,$url_r);
$url_last=str_replace(" ","%20",$url_r[0]);
$db_last=file_get_contents($url_last);
preg_match("/http:.+?/.(wma|mp3)(?=/")/i",$db_last,$url);
$url=$url[0];
$db[$ii+$i]=array(name=>$name,music=>$music,url=>$url);
$i++;
if($_POST[guankan]=="on"){
echo <<<fzz
<div>
<span style="width:30px">$i.</span><span>$music-$name</span>
</div>
<div>
<span style="width:30px"></span><span>$url</span>
</div><br>
fzz;
flush();
}
}
set_time_limit(30);
$name=preg_match_all("/blank>(.+?)</",$a[0][$i],$b);
$music=$b[1][0];
$name=$b[1][1];
if(isset($b[1][2])){
$name.="/".$b[1][2];
}
$music=preg_replace("/<b.*?>/is","",$music);
$word=urlencode("{$music}+{$name}");
$url_dqlb=" http://mp3.baidu.com/m?f=ms&rn=&tn=baidump3&ct=134217728&word={$word}&lm=-1";
$db_dqlb=file_get_contents($url_dqlb);
preg_match("/http:.+?word=(?:wma|mp3).+?/d{5}&lm=/d{8}/i",$db_dqlb,$url_r);
$url_last=str_replace(" ","%20",$url_r[0]);
$db_last=file_get_contents($url_last);
preg_match("/http:.+?/.(wma|mp3)(?=/")/i",$db_last,$url);
$url=$url[0];
$db[$ii+$i]=array(name=>$name,music=>$music,url=>$url);
$i++;
if($_POST[guankan]=="on"){
echo <<<fzz
<div>
<span style="width:30px">$i.</span><span>$music-$name</span>
</div>
<div>
<span style="width:30px"></span><span>$url</span>
</div><br>
fzz;
flush();
}
}
$dbstr=serialize($db);
file_put($file,$dbstr);
file_put($file,$dbstr);
function file_put ($file,$db){
$fp=fopen($file,"w+");
fwrite($fp,$db);
fclose($fp);
}
$fp=fopen($file,"w+");
fwrite($fp,$db);
fclose($fp);
}
?>
<SCRIPT LANGUAGE="JavaScript">
<!--
alert("本次采集任务完成,刷新当前页面继续!");
//-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!--
alert("本次采集任务完成,刷新当前页面继续!");
//-->
</SCRIPT>