回應清單
改為所有搜尋 function 一起跑
且多顯示歌詞前 5 行供人為判斷
ps:
pcntl_fork 子程序寫完才發現
我的 web server 沒支援
最近這台還有任務 , 所以不想動到系統環境
但 pcntl_fork 部分註解起來跑是 OK 的
<?php
session_id("lrcdirtmp");
session_start();
function unicode_decode($strs){
$restr='';
for($i=0;$i<strlen($strs);$i+=4){
$tmpstr=substr($strs,$i,4);
$tmpstr=chr(base_convert(substr($tmpstr,0,2),16,10)).chr(base_convert(substr($tmpstr,2,2),16,10));
$tmpstr=iconv('UCS-2', 'UTF-8', $tmpstr);
$restr.=$tmpstr;
}
return $restr;
}
function cutlines($strs){
$tmparr=explode("\n",$strs);
//$strs=preg_replace("/\[.*\]/","",preg_match("/00/",$strs));
//$strs=preg_match("/00/",$strs);
$showline=5;
$showdata='';
for($i=0;$i<count($tmparr);$i++){
if(preg_match("/\[00/",$tmparr[$i])){
$tmpstr=preg_replace("/\[.*\]/","",$tmparr[$i]);
if(strlen($tmpstr)>2){
$showdata.=$tmpstr.",";
$showline--;
if($showline<=0)break;
}
}
}
return $showdata;
}
function findlrc01($name,$song){
// 魔鏡歌詞網
$tmpstr='LANG=zh_TW.UTF-8;lynx --dump "$(lynx '."--dump 'http://www.google.com.tw/search?q=$name+$song+歌詞&gws_rd=ssl' | grep mojim | ".'head -1 | awk "{print \$1}")" | sed "s/^[ \t]*//g" | grep -E "^\\[ti:|^\\[ar:|^\\[al:|[00-59]:[00-59]" | grep "^\\["';
exec($tmpstr,$tmparr);
return implode("\n",$tmparr);
}
function findlrc02($name,$song){
$tmpp=file("http://www.google.com.tw/search?q=$name+$song+歌詞&gws_rd=ssl");
for ($i=0;$i<count($tmpp);$i++){
$buffer = strip_tags($tmpp[$i]);
$buffer = iconv("BIG5","UTF-8",$buffer);
if(strpos($buffer,"mojim.com/")){
$okurl="http://".preg_replace("/htm.*/","htm",strstr($buffer,"mojim.com/"));
break;
}
}
$showstr='';
$tmpp=file("$okurl");
foreach($tmpp as $key => $val){
//$buffer = strip_tags(preg_replace("/<br \/>/","\n",$val));
$buffer = explode("<br />",$val);
foreach($buffer as $a => $b){
if(preg_match("/^\[[00-59]?[00-59]/",strip_tags($b))){
$showstr.=strip_tags($b)."\n";
}
}
}
return $showstr;
}
$ffuns=2;
$reipid=$_SERVER["REMOTE_ADDR"];
$reipid=preg_replace("/\./","+",$reipid);
eval('$reipid=sprintf("%03d",'.$reipid.');');
if(@$_GET['dl?Id']!=""){
//限 10 位數字=時時分分秒秒(ip x 3)(function x 1)
//開頭數字不為零
echo $_SESSION['a'][$_GET['dl?Id']]['歌詞'];
}else{
@$tmpstr=(date("His")+100000).$reipid;
$counttime=time();
echo '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
echo '<result>'."\n";
// $children=array();
for($i=1;$i<=$ffuns;$i++){
// $pid=pcntl_fork();
// if($pid){
// $children[]=$pid;
// }else{
$tindex=$tmpstr.$i;
$_SESSION['a'][$tindex]['歌手']=iconv("BIG5","UTF-8",iconv("gb2312","BIG5",iconv("UTF-8","gb2312",preg_replace("/ /","+",unicode_decode($_GET['Title'])))));
$_SESSION['a'][$tindex]['歌名']=iconv("BIG5","UTF-8",iconv("gb2312","BIG5",iconv("UTF-8","gb2312",preg_replace("/ /","+",unicode_decode($_GET['sh?Artist'])))));
// 須收 utf8
$songstr="findlrc0".$i."('".$_SESSION['a'][$tindex]['歌手']."','".$_SESSION['a'][$tindex]['歌名']."');";
eval('$songstr='.$songstr);
$_SESSION['a'][$tindex]['歌詞']=$songstr;
$show=' 歌詞:'.cutlines($songstr);
echo ' <lrc id="'.$tindex.'" artist='.$_SESSION['a'][$tindex]['歌名'].' title="'.$_SESSION['a'][$tindex]['歌手'].$show.'"></lrc>'."\n";
// }
}
// foreach($children as $pid){
// pcntl_waitpid($pid, $status);
// }
echo '</result>'."\n";
echo 'use time: '.(time()-$counttime).' sec';
}
$oldist=array_keys($_SESSION['a']);
@$nowtimeu=(date("His")+100000);
for($i=0;$i<count($oldist);$i++){
if($nowtimeu-substr($oldist[$i],0,6)>100){ //1min
unset($_SESSION['a'][$oldist[$i]]);
}
}
?>