一个从baidu哪里抓歌的Class[垃圾Class]
时间:2007-11-08
来源:互联网
看源码吧,也是比较垃圾的,至少我是不满意的...通过给歌名从百度哪里读取:歌手,歌曲的专辑,歌词,歌曲的下载地址.
顺便发下求职信息,有哪家公司招初级phper的请联系我:[email protected]
[ 本帖最后由 lazy 于 2007-11-7 21:51 编辑 ]
复制PHP内容到剪贴板
<?php
/**
* Author:Lazy
* QQ:8820857
* Email:o0lazy0o @ gmail.com
* Version:0.2
* Copyright:none.
* 可任意使用但请保留此信息.
*/
require_once('http.php');
class baidu{
var $Handle;
var $URL;
var $Remote;
var $Song;
var $Singer;
var $Album;
var $Lyric;
var $LrcLink;
var $LinkList;
function baidu(){
$this->Handle = new http();
}
function parse_list($Force=true){
$Regexp = '/(?:<table.+(?:id=tbs|id=\'tbs\'|id="tbs")[^>]+>)(.*?)<\/table>/is';
preg_match($Regexp,$this->Remote,$Array);
$TmpList = strip_tags($Array[1],"<a><td>");
$Regexp = '/<td[^>]*>(.*?)<\/td>/is';
preg_match_all($Regexp,$TmpList,$Array);
$Array = array_pop($Array);
$Count = count($Array);
if(empty($this->Singer)){
for($Foo=0;$Foo<$Count;$Foo=$Foo+10){
$Tmp = str_replace(' ','',trim(strip_tags($Array[$Foo+2])));
$Temp = str_replace(' ','',trim(strip_tags($Array[$Foo+3])));
$Singer[md5($Tmp)]['Count']++;
$Album[md5($Temp)]['Count']++;
$Singer[md5($Tmp)]['Singer'] = $Tmp;
$Album[md5($Temp)]['Album'] = $Temp;
}
sort($Singer);
sort($Album);
$Tmp = array_pop($Singer);
$Temp = array_pop($Album);
$this->Singer = $Tmp['Singer'];
$this->Album = $Temp['Album'];
}
for($Foo=0;$Foo<$Count;$Foo=$Foo+10){
$Tmp = str_replace(' ','',trim(strip_tags($Array[$Foo+2])));
$Temp = trim(strip_tags($Array[$Foo+1]));
if($Force && $this->Singer == $Tmp && strtoupper($Temp) == strtoupper($this->Song)){
$Return[]=array('Album'=>str_replace(' ','',trim(strip_tags($Array[$Foo+3]))),'Lyric'=>$Array[$Foo+5],'Song'=>$Array[$Foo+1]);
}else{
if($this->Singer == $Tmp){
$Return[]=array('Album'=>str_replace(' ','',trim(strip_tags($Array[$Foo+3]))),'Lyric'=>$Array[$Foo+5],'Song'=>$Array[$Foo+1]);
}
}
}
return $Return;
}
function parse_lyric($URL){
$LinkType = "href";
$Regexp = '/[\\s]?(?:'.$LinkType.')[\\s]?=[\\s]?("(?:.+?)"|\'(?:.+?)\'|(?:.+?)[\\s>]?)(?:[\\s]+.*?)?>(.*?)<\/a>/sim';
preg_match($Regexp,$URL,$Array);
$URL = trim($Array[1]," '\"\t\n\r\0\x0B");
$Remote = $this->Handle->get($URL);
$Regexp = '/href=(.*\\.lrc)[^>]*>/i';
preg_match($Regexp,$Remote,$Array);
$this->LrcLink = trim($Array[1]," '\"\t\n\r\0\x0B");
if(empty($this->LrcLink)){
$this->LrcLink=false;
$this->Lyric=false;
}else{
$Remote = $this->Handle->get($this->LrcLink);
$this->Lyric = trim(preg_replace('/\[[^\]]+\]/','',$Remote));
}
}
function parse_song($List,$Force=true){
$LinkType = "href";
$Regexp = '/[\\s]?(?:'.$LinkType.')[\\s]?=[\\s]?("(?:.+?)"|\'(?:.+?)\'|(?:.+?)[\\s>]?)(?:[\\s]+.*?)?>(.*?)<\/a>/sim';
foreach($List as $Var){
preg_match($Regexp,$Var['Song'],$Array);
$URL = trim($Array[1]," '\"\t\n\r\0\x0B");
$Remote = $this->Handle->get($URL);
preg_match($Regexp,$Remote,$Array);
$URL = trim($Array[1]," '\"\t\n\r\0\x0B");
$this->LinkList[]=$URL;
if($this->Handle->head($URL)==true and $Force){
$this->LinkList[]=$URL;
}elseif($Force==false){
$this->LinkList[]=$URL;
}else{
continue;
}
}
}
function get($Song,$Singer=null,$Force=true,$ForceHead=true){
$this->Song = trim($Song);
$this->Singer = trim($Singer);
if(empty($this->Song)){ exit('Must Fill The Song Name'); }
//http://mp3.baidu.com/m?f=ms&rn=&tn=baidump3&ct=134217728&word=%C1%E3%CA%B1%C1%E3%B7%D6&lm=-1
$BaseURL = "http://mp3.baidu.com/m?f=ms&rn=&tn=baidump3&ct=134217728&word={$this->Song}&lm=-1";
$CacheFile = md5($BaseURL).'.cache';
$this->Remote = $this->Handle->get($BaseURL);
// if(!file_exists($CacheFile)){
// $this->Remote = $this->Handle->get($BaseURL);
// $Handle = fopen('./data/'.md5($BaseURL).'.cache','wb+');
// fwrite($Handle,$this->Remote);
// fclose($Handle);
// }else{
// $this->Remote = file_get_contents($CacheFile);
// }
$List = $this->parse_list();
$this->parse_lyric($List[0]['Lyric']);
$this->parse_song($List,$ForceHead);
return array('Song'=>$this->Song,'Singer'=>$this->Singer,'Album'=>$this->Album,'Lyirc'=>$this->Lyric,'LrcLink'=>$this->LrcLink,'LinkList'=>$this->LinkList);
}
}
//$Demo = new baidu();
//var_dump($T->$Demo('断点'));
?>
--------------------------------------------------------------------------------------------------------------------------PHP代码:
<?php
/**
* Author:Lazy
* QQ:8820857
* Email:o0lazy0o @ gmail.com
* Version:0.2
* Copyright:none.
* 可任意使用但请保留此信息.
*/
require_once('http.php');
class baidu{
var $Handle;
var $URL;
var $Remote;
var $Song;
var $Singer;
var $Album;
var $Lyric;
var $LrcLink;
var $LinkList;
function baidu(){
$this->Handle = new http();
}
function parse_list($Force=true){
$Regexp = '/(?:<table.+(?:id=tbs|id=\'tbs\'|id="tbs")[^>]+>)(.*?)<\/table>/is';
preg_match($Regexp,$this->Remote,$Array);
$TmpList = strip_tags($Array[1],"<a><td>");
$Regexp = '/<td[^>]*>(.*?)<\/td>/is';
preg_match_all($Regexp,$TmpList,$Array);
$Array = array_pop($Array);
$Count = count($Array);
if(empty($this->Singer)){
for($Foo=0;$Foo<$Count;$Foo=$Foo+10){
$Tmp = str_replace(' ','',trim(strip_tags($Array[$Foo+2])));
$Temp = str_replace(' ','',trim(strip_tags($Array[$Foo+3])));
$Singer[md5($Tmp)]['Count']++;
$Album[md5($Temp)]['Count']++;
$Singer[md5($Tmp)]['Singer'] = $Tmp;
$Album[md5($Temp)]['Album'] = $Temp;
}
sort($Singer);
sort($Album);
$Tmp = array_pop($Singer);
$Temp = array_pop($Album);
$this->Singer = $Tmp['Singer'];
$this->Album = $Temp['Album'];
}
for($Foo=0;$Foo<$Count;$Foo=$Foo+10){
$Tmp = str_replace(' ','',trim(strip_tags($Array[$Foo+2])));
$Temp = trim(strip_tags($Array[$Foo+1]));
if($Force && $this->Singer == $Tmp && strtoupper($Temp) == strtoupper($this->Song)){
$Return[]=array('Album'=>str_replace(' ','',trim(strip_tags($Array[$Foo+3]))),'Lyric'=>$Array[$Foo+5],'Song'=>$Array[$Foo+1]);
}else{
if($this->Singer == $Tmp){
$Return[]=array('Album'=>str_replace(' ','',trim(strip_tags($Array[$Foo+3]))),'Lyric'=>$Array[$Foo+5],'Song'=>$Array[$Foo+1]);
}
}
}
return $Return;
}
function parse_lyric($URL){
$LinkType = "href";
$Regexp = '/[\\s]?(?:'.$LinkType.')[\\s]?=[\\s]?("(?:.+?)"|\'(?:.+?)\'|(?:.+?)[\\s>]?)(?:[\\s]+.*?)?>(.*?)<\/a>/sim';
preg_match($Regexp,$URL,$Array);
$URL = trim($Array[1]," '\"\t\n\r\0\x0B");
$Remote = $this->Handle->get($URL);
$Regexp = '/href=(.*\\.lrc)[^>]*>/i';
preg_match($Regexp,$Remote,$Array);
$this->LrcLink = trim($Array[1]," '\"\t\n\r\0\x0B");
if(empty($this->LrcLink)){
$this->LrcLink=false;
$this->Lyric=false;
}else{
$Remote = $this->Handle->get($this->LrcLink);
$this->Lyric = trim(preg_replace('/\[[^\]]+\]/','',$Remote));
}
}
function parse_song($List,$Force=true){
$LinkType = "href";
$Regexp = '/[\\s]?(?:'.$LinkType.')[\\s]?=[\\s]?("(?:.+?)"|\'(?:.+?)\'|(?:.+?)[\\s>]?)(?:[\\s]+.*?)?>(.*?)<\/a>/sim';
foreach($List as $Var){
preg_match($Regexp,$Var['Song'],$Array);
$URL = trim($Array[1]," '\"\t\n\r\0\x0B");
$Remote = $this->Handle->get($URL);
preg_match($Regexp,$Remote,$Array);
$URL = trim($Array[1]," '\"\t\n\r\0\x0B");
$this->LinkList[]=$URL;
if($this->Handle->head($URL)==true and $Force){
$this->LinkList[]=$URL;
}elseif($Force==false){
$this->LinkList[]=$URL;
}else{
continue;
}
}
}
function get($Song,$Singer=null,$Force=true,$ForceHead=true){
$this->Song = trim($Song);
$this->Singer = trim($Singer);
if(empty($this->Song)){ exit('Must Fill The Song Name'); }
//http://mp3.baidu.com/m?f=ms&rn=&tn=baidump3&ct=134217728&word=%C1%E3%CA%B1%C1%E3%B7%D6&lm=-1
$BaseURL = "http://mp3.baidu.com/m?f=ms&rn=&tn=baidump3&ct=134217728&word={$this->Song}&lm=-1";
$CacheFile = md5($BaseURL).'.cache';
$this->Remote = $this->Handle->get($BaseURL);
// if(!file_exists($CacheFile)){
// $this->Remote = $this->Handle->get($BaseURL);
// $Handle = fopen('./data/'.md5($BaseURL).'.cache','wb+');
// fwrite($Handle,$this->Remote);
// fclose($Handle);
// }else{
// $this->Remote = file_get_contents($CacheFile);
// }
$List = $this->parse_list();
$this->parse_lyric($List[0]['Lyric']);
$this->parse_song($List,$ForceHead);
return array('Song'=>$this->Song,'Singer'=>$this->Singer,'Album'=>$this->Album,'Lyirc'=>$this->Lyric,'LrcLink'=>$this->LrcLink,'LinkList'=>$this->LinkList);
}
}
//$Demo = new baidu();
//var_dump($T->$Demo('断点'));
?>
顺便发下求职信息,有哪家公司招初级phper的请联系我:[email protected]
[ 本帖最后由 lazy 于 2007-11-7 21:51 编辑 ]
作者: lazy 发布时间: 2007-11-07
其中的http.php
见http://www.phpchina.com/bbs/view ... mp;extra=#pid305665
见http://www.phpchina.com/bbs/view ... mp;extra=#pid305665
作者: lazy 发布时间: 2007-11-07
作者: beluckly 发布时间: 2007-11-07
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28