首页 > php教程 > php手册 > 正文

从千千静听服务器获取的lrc歌词

WBOY
发布: 2016-08-04 08:54:59
原创
2026 人浏览过

从千千静听服务器获取的lrc歌词的PHP代码 无 源码与演示: 源码出处演示出处 ?phperror_reporting(0);function ConvertUrlEncode($text){$textUrl = htmlspecialchars(urlencode($text));return $textUrl;}$Type=substr($name,-4);$name1=str_replace($Type,"

从千千静听服务器获取的lrc歌词的PHP代码

源码与演示:源码出处 演示出处

<?php
error_reporting(0);
function ConvertUrlEncode($text)
{
$textUrl = htmlspecialchars(urlencode($text));
return $textUrl;
}
$Type=substr($name,-4);
$name1=str_replace($Type,"",$name);
$name2=str_replace("-","",$name1);
$uk=ConvertUrlEncode($name2);
$str=file_get_contents('http://music.baidu.com/search/lrc?key='.$uk);
  preg_match_all('/<p id="lyricCont-0">(.*?)<\/p>/is',$str, $arr);
  foreach ($arr[1] as $k => $v){
       }
if($v){
echo $v;
      }else{
echo '很抱歉,百度都没找到'.$name.'的歌词,这歌曲也太给力了吧~!';
      }
?>
登录后复制
从千千静听服务器获取的lrc歌词
<?
//转载请注明出处 uenucom
function SingleDecToHex($dec) 
{ 
$tmp=""; 
$dec=$dec%16; 
if($dec<10) return $tmp.$dec; 
$arr=array("A","B","C","D","E","F"); 
return $tmp.$arr[$dec-10]; 
} 
function SetToHexString($str) 
{ 
if(!$str) return false; 
$tmp=""; 
for($i=0;$i<strlen($str);$i++) 
{ 
$ord=ord($str[$i]); 
$tmp.=SingleDecToHex(($ord-$ord%16)/16); 
$tmp.=SingleDecToHex($ord%16); 
} 
return $tmp; 
} 
function qianqian_code($str) 
{ 
$s=strtolower($str); 
$s=str_replace(" ","",$s); 
$s=str_replace("'","",$s); 
return SetToHexString(iconv('GBK','UTF-16LE',$s));} 

function conv($num) 
{ 
$tp = bcmod($num,4294967296); 

if(bccomp($num,0)>=0 && bccomp($tp,2147483648)>0) 
$tp=bcadd($tp,-4294967296); 
if(bccomp($num,0)<0 && bccomp($tp,2147483648)<0) 
$tp=bcadd($tp,4294967296); 

return $tp; 
} 
function CodeFunc($Id,$artist,$title) 
{ 
$Id=(int)$Id; 
$utf8Str=SetToHexString(iconv('GBK','UTF-8',$artist.$title)); 

$length=strlen($utf8Str)/2; 
for($i=0;$i<=$length-1;$i++) 
eval('$song['.$i.'] = 0x'.substr($utf8Str,$i*2,2).';'); 

$tmp2=0; 
$tmp3=0; 

$tmp1 = ($Id & 0x0000FF00) >> 8; //右移8位后为0x0000015F 
//tmp1 0x0000005F 
if ( ($Id & 0x00FF0000) == 0 ) { 
$tmp3 = 0x000000FF & ~$tmp1; //CL 0x000000E7 
} else { 
$tmp3 = 0x000000FF & (($Id & 0x00FF0000) >> 16); //右移16位后为0x00000001 
} 
$tmp3 = $tmp3 | ((0x000000FF & $Id) << 8); //tmp3 0x00001801 
$tmp3 = $tmp3 << 8; //tmp3 0x00180100 
$tmp3 = $tmp3 | (0x000000FF & $tmp1); //tmp3 0x0018015F 
$tmp3 = $tmp3 << 8; //tmp3 0x18015F00 
if ( ($Id & 0xFF000000) == 0 ) { 
$tmp3 = $tmp3 | (0x000000FF & (~$Id)); //tmp3 0x18015FE7 
} else { 
$tmp3 = $tmp3 | (0x000000FF & ($Id >> 24)); //右移24位后为0x00000000 
} 

$i=$length-1; 
while($i >= 0){ 
$char = $song[$i]; 
if($char >= 0x80) $char = $char - 0x100; 

$tmp1 = ($char + $tmp2) & 0x00000000FFFFFFFF; 
$tmp2 = ($tmp2 << ($i%2 + 4)) & 0x00000000FFFFFFFF; 
$tmp2 = ($tmp1 + $tmp2) & 0x00000000FFFFFFFF; 
$i -= 1; 
} 

$i=0; 
$tmp1=0; 
while($i<=$length-1){ 
$char = $song[$i]; 
if($char >= 128) $char = $char - 256; 
$tmp7 = ($char + $tmp1) & 0x00000000FFFFFFFF; 
$tmp1 = ($tmp1 << ($i%2 + 3)) & 0x00000000FFFFFFFF; 
$tmp1 = ($tmp1 + $tmp7) & 0x00000000FFFFFFFF; 

$i += 1; 
} 

$t = conv($tmp2 ^ $tmp3); 
$t = conv(($t+($tmp1 | $Id))); 
$t = conv(bcmul($t , ($tmp1 | $tmp3))); 
$t = conv(bcmul($t , ($tmp2 ^ $Id))); 

if(bccomp($t , 2147483648)>0) 
$t = bcadd($t ,- 4294967296); 
return $t;} 

$artist="央金兰泽"; 
$title="遇上你是我的缘"; 
$doc = new DOMDocument(); 
$doc->load("http://lrccnc.ttplayer.com/dll/lyricsvr.dll?sh?Artist=".qianqian_code($artist)."&Title=".qianqian_code($title)."&Flags=0"); 

$lrcNode = $doc->getElementsByTagName("lrc"); 
foreach($lrcNode as $lrc) 
{ 
$id=$lrc->getAttribute("id"); 
$artist=iconv('UTF-8','GBK',$lrc->getAttribute("artist")); 
$title=iconv('UTF-8','GBK',$lrc->getAttribute("title")); 
$code=CodeFunc($id,$artist,$title); 
$lrcstr=iconv('UTF-8','GBK',file_get_contents("http://lrccnc.ttplayer.com/dll/lyricsvr.dll?dl?Id=".$id."&Code=".$code)); 
echo $lrcstr; 
break; 
} 

?>
登录后复制
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板