2024年1月7日发(作者:)

网易云音乐常用API浅析–Moonlib

话不多说

PC客户端抓包而来

0.说明

关于头部信息

Cookie: os=pc;

deviceId=B55AC773505E5606F9D355A1A15553CE78B89FC7D8CB8A157B84;

osver=Microsoft-Windows-8-Professional-build-9200-64bit;

1

appver=1.5.0.75771; usertrack=ezq0alR0yqJMJC0dr9tEAg==;

2

MUSIC_A=088a57b553bd8cef58487f9d01ae

User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36

(KHTML, like Gecko) Chrome/35.0.1916.138 Safari/537.36rn

上面是抓到的信息,其中必要的只有cookie中的appver。而且如果要调用api,必须加上Referer,只要是的就可以

1 Cookie: appver=1.5.0.75771;

2 Referer: /

以上两条即可

返回的格式均为json

1.搜索

抓取到的信息如下

1 Full request URI:/api/search/pc

2 Key: hlpretag

3 Value:

4 Key: hlposttag

5 Value:

6 Key: s

7 Value: 345226234346254242344275240

8 Key: offset

9 Value: 0

10 Key: total

11 Value: true

12 Key: limit

13 Value: 100

14 Key: type

15 Value: 1

URL:

POST /api/search/pc

必要参数:

s:搜索的内容

offset:偏移量(分页用)

limit:获取的数量

type:搜索的类型

歌曲 1

专辑 10

歌手 100

歌单 1000

用户 1002

mv 1004

歌词 1006

主播电台 1009

2.歌曲信息

Full request URI:

1 /api/song/detail/?id=28377211&ids=%5B28377211%5D

URL:

GET /api/song/detail/

必要参数:

id:歌曲ID

ids:不知道干什么用的,用[]括起来的歌曲ID

3.歌手专辑

Full request URI:

1 /api/artist/albums/166009?id=166009&offset=0&total=true&limit=5

URL:

GET /api/artist/albums/歌手ID

必要参数:

limit:获取的数量(不知道为什么这个必须加上)

4.专辑信息

Full request URI:

1 /api/album/2457012?ext=true&id=2457012&offset=0&total=true&limit=10

URL:

GET /api/album/专辑ID

5.歌单

Full request URI:

1

/api/playlist/detail?id=37880978&updateTime=-1

URL:

GET /api/playlist/detail

必要参数:

id:歌单ID

6.歌词

Full request

1 /api/song/lyric?os=pc&id=93920&lv=-1&kv=-1&tv=-1

URL:

GET /api/song/lyric

必要参数:

id:歌曲ID

lv:值为-1,我猜测应该是判断是否搜索lyric格式

kv:值为-1,这个值貌似并不影响结果,意义不明

tv:值为-1,是否搜索tlyric格式

1

Full request

/api/mv/detail?id=319104&type=mp4

URL:

GET /api/mv/detail

必要参数:

id:mvid

type:值为mp4,视频格式,不清楚还有没有别的格式

PHP版使用示例

PHP

1

2 /**

3 * Created by PhpStorm.

4 * User: Moon

5 * Date: 2014/11/26 0026

6 * Time: 2:06

7 */

URI:

URI:

8 function curl_get($url)

9 {

10 $refer = "/";

11 $header[] = "Cookie: " . "appver=1.5.0.75771;";

12 $ch = curl_init();

13 curl_setopt($ch, CURLOPT_URL, $url);

14 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

15 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

16 curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);

17 curl_setopt($ch, CURLOPT_REFERER, $refer);

18 $output = curl_exec($ch);

19 curl_close($ch);

20 return $output;

21 }

22 function music_search($word, $type)

23 {

24 $url = "/api/search/pc";

25 $post_data = array(

26 's' => $word,

27 'offset' => '0',

28 'limit' => '20',

29 'type' => $type,

30 );

31 $referrer = "/";

32 $URL_Info = parse_url($url);

33 $values = [];

34 $result = '';

35 $request = '';

36 foreach ($post_data as $key => $value) {

37 $values[] = "$key=" . urlencode($value);

38 }

39 $data_string = implode("&", $values);

40 if (!isset($URL_Info["port"])) {

41 $URL_Info["port"] = 80;

42 }

43 $request .= "POST " . $URL_Info["path"] . " HTTP/1.1n";

44 $request .= "Host: " . $URL_Info["host"] . "n";

45 $request .= "Referer: $referrern";

46 $request .= "Content-type: application/x-www-form-47 urlencodedn";

48 $request .= "Content-length: " . strlen($data_string) .

49 "n";

50 $request .= "Connection: closen";

51 $request .= "Cookie: " . "appver=1.5.0.75771;n";

52 $request .= "n";

53 $request .= $data_string . "n";

54 $fp = fsockopen($URL_Info["host"], $URL_Info["port"]);

55 fputs($fp, $request);

56 $i = 1;

57 while (!feof($fp)) {

58 if ($i >= 15) {

59 $result .= fgets($fp);

60 } else {

61 fgets($fp);

62 $i++;

63 }

64 }

65 fclose($fp);

66 return $result;

67 }

68 function get_music_info($music_id)

69 {

70 $url = "/api/song/detail/?id=" .

71 $music_id . "&ids=%5B" . $music_id . "%5D";

72 return curl_get($url);

73 }

74 function get_artist_album($artist_id, $limit)

75 {

76 $url = "/api/artist/albums/" .

77 $artist_id . "?limit=" . $limit;

78 return curl_get($url);

79 }

80 function get_album_info($album_id)

81 {

82 $url = "/api/album/" . $album_id;

83 return curl_get($url);

84 }

85 function get_playlist_info($playlist_id)

86 {

87 $url = "/api/playlist/detail?id=" .

88 $playlist_id;

89 return curl_get($url);

90 }

91 function get_music_lyric($music_id)

92 {

93 $url = "/api/song/lyric?os=pc&id=" .

94 $music_id . "&lv=-1&kv=-1&tv=-1";

95 return curl_get($url);

96 }

97 function get_mv_info()

98 {

99 $url

100 "/api/mv/detail?id=319104&type=mp4";

101 return curl_get($url);

102 }

103 #echo music_search("Moon Without The Stars", "1");

104 #get_music_info("28949444");

105 #echo get_artist_album("166009", "5");

106 #echo get_album_info("3021064");

107 #echo get_playlist_info("22320356");

108 #echo get_music_lyric("29567020");

109 #echo get_mv_info();

110

=

PS:搜索的接口我用CURL调用失败,原因未知,于是搜索是用文件操作实现的