-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud_music.php
181 lines (169 loc) · 4.95 KB
/
cloud_music.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
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 music_search($word, $type)
{
$url = "http://music.163.com/api/search/pc";
$post_data = array(
's' => $word,
'offset' => '0',
'limit' => '20',
'type' => $type,
);
$referrer = "http://music.163.com/";
$URL_Info = parse_url($url);
$values = [];
$result = '';
$request = '';
foreach ($post_data as $key => $value) {
$values[] = "$key=" . urlencode($value);
}
$data_string = implode("&", $values);
if (!isset($URL_Info["port"])) {
$URL_Info["port"] = 80;
}
$request .= "POST " . $URL_Info["path"] . " HTTP/1.1\n";
$request .= "Host: " . $URL_Info["host"] . "\n";
$request .= "Referer: $referrer\n";
$request .= "Content-type: application/x-www-form-urlencoded\n";
$request .= "Content-length: " . strlen($data_string) . "\n";
$request .= "Connection: close\n";
$request .= "Cookie: " . "appver=1.5.0.75771;\n";
$request .= "\n";
$request .= $data_string . "\n";
$fp = fsockopen($URL_Info["host"], $URL_Info["port"]);
fputs($fp, $request);
$i = 1;
while (!feof($fp)) {
if ($i >= 15) {
$result .= fgets($fp);
} else {
fgets($fp);
$i++;
}
}
fclose($fp);
return $result;
}
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_album($artist_id, $limit)
{
$url = "http://music.163.com/api/artist/albums/" . $artist_id . "?limit=" . $limit;
return curl_get($url);
}
function get_album_info($album_id)
{
$url = "http://music.163.com/api/album/" . $album_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_music_lyric($music_id)
{
$url = "http://music.163.com/api/song/lyric?os=pc&id=" . $music_id . "&lv=-1&kv=-1&tv=-1";
return curl_get($url);
}
function get_mv_info()
{
$url = "http://music.163.com/api/mv/detail?id=319104&type=mp4";
return curl_get($url);
}
function get_search($word,$limit){
$url = "http://music.163.com/api/search/get/web?csrf_token=";
$curl = curl_init();
$post_data = 'hlpretag=&hlposttag=&s='. $word . '&type=1&offset=0&total=true&limit=' . $limit;
curl_setopt($curl, CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
$header =array(
'Host: music.163.com',
'Origin: http://music.163.com',
'User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36',
'Content-Type: application/x-www-form-urlencoded',
'Referer: http://music.163.com/search/',
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
$src = curl_exec($curl);
curl_close($curl);
return $src;
}
#echo music_search("Moon Without The Stars", "1");
#get_music_info("28949444");
#echo get_artist_album("166009", "5");
#echo get_album_info("3021064");
#echo get_playlist_info("22320356");
#echo get_music_lyric("29567020");
#echo get_mv_info();
//echo get_search("pdd洪荒之力",1);
//$output=get_search("普通diso",1);
function get_musicid($word,$limit,$art){
$src=get_search($word,$limit);
$arr=json_decode($src,true);
$music_id=$arr['result']['songs'][0]['id'];
if($art==""){
return $music_id;
}
else{
for($i=0;$i<$limit;$i++)
{
$artist=$arr['result']['songs'][$i]['artists'][0]['name'];
if(strcasecmp($artist,$art)==0){
$music_id=$arr['result']['songs'][$i]['id'];
//var_dump($arr['result']['songs'][$i]['artists'][0]['name']);
break;
exit;
}
else $music_id="";
}
}
return $music_id;
}
function get_musicUrl($word,$limit,$art){
$musicUrl="";
$music_id=get_musicid($word,$limit,$art);
$music_info=get_music_info($music_id);
$music_info=json_decode($music_info,true);
//var_dump();
$musicUrl=$music_info['songs'][0]['mp3Url'];
return $musicUrl;
}
function get_artist($word,$limit,$art){
$src=get_search($word,$limit);
$arr=json_decode($src,true);
if($art==""){
$artist=$arr['result']['songs'][0]['artists'][0]['name'];
}
else $artist=$art;
//echo $src1;
return $artist;
}
//$reg='\"songs\":\[\{\"id\":(.*?)\"name\"';
//preg_match($reg,$output,$matches);
//$output=get_music_info("440353010");
//$output=$output[code];
//echo $output=get_musicUrl("普通disco",10,"葛平");
//$output=json_decode(get_search("玲珑",1),true);
//var_dump($output);
//echo $output['result']['songs'][0]['id'];
//echo $output=get_music_in('5250096');
?>