PHP实例:PHP采集百度音乐程序_[PHP教程]
采集百度MP3TOP100和TOP500 列表歌曲文件URL的小程序!
/* 作者:夜无眠 QQ:27262681 本程序将百度的新歌TOP100和热歌TOP500列表里的音乐随机采集一个mp3或wma文件URL与歌手、歌名一起组成二维数组,并序列化保存在db.txt里 开启采集时要输入密码,防止恶作剧。密码是fzz */ //session_save_path("tmp"); //密码:fzz session_start(); file="db.txt"; if(!isset(_SESSION["cai"])){ _SESSION["cai"]=0; } if(_SESSION["cai"]==0 or !isset(_POST["xuanze"])){ echo << 『夜无眠音乐采集』 『夜无眠音乐采集』
你要更新哪部分?
程序开始采集后请勿随意刷新页面 eot; _SESSION["cai"]=1; die(); } _SESSION["cai"]=0; if(_POST["password"]!="fzz"){//这里的fzz就是密码,可以改。 die(""); }
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}.
).*?
/isS",input,a);
while(i 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("//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 <<
i.music-name
url
fzz; flush(); } }
dbstr=serialize(db);//序列化数组 file_put(file,dbstr);
function file_put (file,db){ fp=fopen(file,"w+"); fwrite(fp,db); fclose(fp); }
?>
|