用PHP写的百度音乐采集程序

采集百度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>");
}
$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);
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();
 }
}
$dbstr=serialize($db);
file_put($file,$dbstr);
function file_put ($file,$db){
 $fp=fopen($file,"w+");
 fwrite($fp,$db);
 fclose($fp);
}
?>
<SCRIPT LANGUAGE="JavaScript">
<!--
 alert("本次采集任务完成,刷新当前页面继续!");
//-->
</SCRIPT>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值