-
Notifications
You must be signed in to change notification settings - Fork 0
/
hexo.php
67 lines (64 loc) · 2.03 KB
/
hexo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
header("Content-type:application/json;charset=utf-8");
function curl_get($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);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
function get_music_info($music_id)
{
$url = "http://music.163.com/api/song/detail/?id=" . $music_id . "&ids=%5B" . $music_id . "%5D";
return curl_get($url);
}
function get_artist_info($artist_id)
{
$url = "http://music.163.com/api/artist/" . $artist_id;
return curl_get($url);
}
function get_playlist_info($playlist_id) {
$url = "http://music.163.com/api/playlist/detail/?id=" . $playlist_id;
return curl_get($url);
}
function get_album_info($album_id)
{
$url = "http://music.163.com/api/album/" . $album_id;
return curl_get($url);
}
function batch_get($id, $type)
{
if($type) {
$result = json_decode(get_album_info($album_id), true);
$result = $result["album"]["songs"];
} else {
$result = json_decode(get_playlist_info($playlist_id),true);
$result = $result['result']['tracks'];
}
$song_list = "[";
foreach ($result as $key => $song) {
$result = json_decode(get_music_info($song['id']), true);
$result = $result['songs'][0];
$info = "{";
$music_name = $result['name'];
$artist_name = $result['artists'][0]['name'];
$music_url = $result['mp3Url'];
$music_pic = $result['album']['picUrl'];
$info .= "title:'" .$music_name . "',author:'" . $artist_name . "',url:'" .$music_url . "',pic:'" . $music_pic . "'},";
$song_list .= $info;
}
$song_list = rtrim($song_list,",");
$song_list .= "]";
return $song_list;
}
// example
// $id = $_GET['id'];
// $result = batch_get($id);
// print_r($result);