Created
June 3, 2017 07:47
-
-
Save chenxuuu/5e616f84ea2858ba5c941a2149479f20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<form action="" method="post"> | |
<p>一个简陋的点歌台23333</p> | |
<p>搜索结果来自网易云</p> | |
<p>输入歌曲名搜索歌曲:<input type="text" name="song" /></p> | |
<p><input type="submit" name="sub" value="搜索" /></p> | |
</form> | |
by 晨旭/chenxublog.com | running on Raspberry Pi 2 Model B<br/><br/><br/> | |
<?php | |
function netease_http($url) | |
{ | |
$refer = "http://music.163.com/"; | |
$header[] = "Cookie: " . "appver=1.5.0.75771;"; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); | |
curl_setopt($ch, CURLOPT_REFERER, $refer); | |
$cexecute = curl_exec($ch); | |
curl_close($ch); | |
if ($cexecute) | |
{ | |
$result = json_decode($cexecute, true); | |
return $result; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
function getStatus($url){ | |
if($headers = @get_headers($url)){ | |
$status = $headers[0]; | |
$statusno= false; | |
if(preg_match_all('%HTTP/1\.1 ([\d]{3})%i',$status,$matches)){ | |
$statusno = $matches[1][0]; | |
} | |
return $statusno; | |
} | |
return false; | |
} | |
if(!empty($_POST['song'])){ | |
$song=$_POST['song']; | |
echo '搜索关键词:'.$song.'<br/>=========================================================<br/>'; | |
$url = "http://s.music.163.com/search/get/?type=1&s=".$song; | |
$response = netease_http($url); | |
$counttemp=0; | |
for($counttemp=0;$counttemp<10;$counttemp++) | |
{ | |
if(getStatus($response['result']['songs'][$counttemp]['audio'])=='200') | |
{ | |
echo $response['result']['songs'][$counttemp]['name'].'<img src="'.$response['result']['songs'][$counttemp]['album']['picUrl'].'" height="100"/><a href="?down='.$response['result']['songs'][$counttemp]['audio'].'">就选这首了</a><br/>试听:<audio src="'.$response['result']['songs'][$counttemp]['audio'].'" controls="controls"></audio><br/>=========================================================<br/>'; | |
} | |
else | |
{ | |
echo '第'.($counttemp+1).'首歌曲获取失败(歌曲失效/版权问题/网络抽风)<br/>=========================================================<br/>'; | |
} | |
} | |
} | |
elseif(!empty($_GET['down']) && empty($_GET['write'])) | |
{ | |
echo '当前可供选择的空闲的序列:<br/>'; | |
$counttemp=0; | |
for($counttemp=1;$counttemp<31;$counttemp++) | |
{ | |
if($counttemp%5==0) | |
{ | |
echo '<br/>'; | |
} | |
if (!file_exists($counttemp.'.txt')) | |
{ | |
echo '<a href="?write='.$counttemp.'&down='.$_GET['down'].'">第'.$counttemp.'首歌</a>(空闲中)|'; | |
} | |
else | |
{ | |
echo '第'.$counttemp.'首歌(渲染中)|'; | |
} | |
} | |
} | |
elseif(!empty($_GET['write']) && !empty($_GET['down'])) | |
{ | |
if(!file_exists($_GET['write'].'.txt')) | |
{ | |
//file_put_contents('songs/'.$_GET['write'].'.txt', $_GET['down']); | |
$myfile = fopen($_GET['write'].'.txt', "w") or die("Unable to open file!"); | |
fwrite($myfile, $_GET['down']); | |
fclose($myfile); | |
echo '第'.$_GET['write'].'首歌曲的渲染请求提交成功!<a href="index.php">返回首页</a>'; | |
} | |
else | |
{ | |
echo '啊哦!这个序号已经有人选中了!正在渲染!'; | |
} | |
} | |
?> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment