Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

网易云盘相关API #56

Open
Catofes opened this issue Mar 31, 2015 · 18 comments
Open

网易云盘相关API #56

Catofes opened this issue Mar 31, 2015 · 18 comments

Comments

@Catofes
Copy link
Collaborator

Catofes commented Mar 31, 2015

网易云音乐客户端提供了一个叫做云盘的东西,可以手工上传曲子,并且播放。不过现在只支持客户端。不知道要不要添加到这个项目里。如图:
2015-03-31 22 20 47
图中的Mirai Miracle 就是手工上传的曲子。这个在网页版的api中得不到相关的信息。

用Anyproxy分析了一下PC端的api,大概有以下的结果:

原来api是
http://music.163.com/api/playlist/detail?id=30391223&offset=0&total=true&limit=1001&csrf_token=358c82d006c539e72c6f68583a95ceb9

测试发现新的api变成了
http://music.163.com/api/v2/playlist/detail?id=30391223&offset=0&total=true&limit=1001&csrf_token=358c82d006c539e72c6f68583a95ceb9

当携带Cookie

[
{
    "domain": ".music.163.com",
    "expirationDate": 1459434720,
    "hostOnly": false,
    "httpOnly": false,
    "name": "MUSIC_U",
    "path": "/",
    "secure": false,
    "session": false,
    "storeId": "0",
    "value": "e2d3b03bfec5a6b3944edc75b89ce65a45c8d4980aa439590d31c0fe4f1b3684abdac0706d3b3a5e0e7d62790d97a47faf9e62a8590fd08a",
    "id": 1
},
{
    "domain": ".music.163.com",
    "expirationDate": 1459434600,
    "hostOnly": false,
    "httpOnly": false,
    "name": "os",
    "path": "/",
    "secure": false,
    "session": false,
    "storeId": "0",
    "value": "pc",
    "id": 2
}
]

的时候即可得到结果。测试得到只有携带os=pc 的cookie就可以返回不含云网盘数据的playlist, 也就是等同于现在的api,不过具体的参数以及定义都有所改变。如果想要得到云网盘的数据,需要携带MUSIC_U参数。这个参数还不知道时怎么得到的。貌似正常网页版登陆后也会有这个参数。

然后返回的数据大概如下,做了json的解析:

{
    "playlist": {
        "subscribers": [],
        "subscribed": false,
        "creator": {
            "signature": "",
            "authority": 0,
            "description": "",
            "userId": 37734080,
            "nickname": "Catofes",
            "avatarUrl": "http://p4.music.126.net/L-1w-AuM_2TH-tW7Olsp3g==/3223768092658904.jpg",
            "backgroundImgId": 2002210674180202,
            "avatarImgId": 3223768092658904,
            "mutual": false,
            "gender": 0,
            "birthday": -2209017600000,
            "province": 110000,
            "city": 110101,
            "defaultAvatar": false,
            "userType": 0,
            "accountStatus": 0,
            "expertTags": null,
            "detailDescription": "",
            "djStatus": 0,
            "authStatus": 0,
            "followed": false,
            "backgroundUrl": "http://p1.music.126.net/pmHS4fcQtcNEGewNb5HRhg==/2002210674180202.jpg"
        },
        "tracks": [
            {
                "rtUrls": [],
                "name": "新鸳鸯蝴蝶梦",
                "id": 95410,
                "v": 3,
                "st": 1,
                "t": 0,
                "fee": 0,
                "ftype": 0,
                "rtype": 0,
                "rurl": null,
                "no": 1,
                "pst": 0,
                "alia": [],
                "pop": 90,
                "rt": "",
                "mst": 9,
                "cp": 5003,
                "crbt": "835fbd444d38c4f4e1efe33c11bf3954",
                "mv": 0,
                "cf": "",
                "ar": [
                    {
                        "id": 3082,
                        "name": "黄安"
                    }
                ],
                "al": {
                    "id": 9319,
                    "name": "新鸳鸯蝴蝶梦",
                    "picStr": "38482906984192",
                    "pic": 38482906984192
                },
                "dt": 261799,
                "h": {
                    "br": 320000,
                    "fid": 1031341906860656,
                    "size": 10485884,
                    "vd": -0.000265076
                },
                "m": {
                    "br": 160000,
                    "fid": 1020346790582851,
                    "size": 5254603,
                    "vd": 0
                },
                "l": {
                    "br": 96000,
                    "fid": 1212761325443605,
                    "size": 3161672,
                    "vd": -0.000265076
                },
                "a": {
                    "br": 64000,
                    "fid": 5830710162150141,
                    "size": 2119031,
                    "vd": 0
                },
                "cd": "",
                "rtUrl": null
            },
            {
                "rtUrls": [],
                "name": "人にやさしく",
                "id": 30245511,
                "v": 2,
                "st": 0,
                "t": 0,
                "fee": 0,
                "ftype": 0,
                "rtype": 0,
                "rurl": null,
                "no": 1,
                "pst": 0,
                "alia": [],
                "pop": 80,
                "rt": null,
                "mst": 9,
                "cp": 0,
                "crbt": null,
                "mv": 0,
                "cf": "",
                "ar": [
                    {
                        "id": 1047395,
                        "name": "THE ROLLING GIRLS"
                    }
                ],
                "al": {
                    "id": 3094448,
                    "name": "THE ROLLING GIRLS THEME SONGS COLLECTION",
                    "picStr": "7894493487528893",
                    "pic": 7894493487528893
                },
                "dt": 201480,
                "h": {
                    "br": 320000,
                    "fid": 7852712045676580,
                    "size": 8062179,
                    "vd": -2.36
                },
                "m": {
                    "br": 160000,
                    "fid": 7852712045676581,
                    "size": 4031619,
                    "vd": -1.96
                },
                "l": {
                    "br": 96000,
                    "fid": 7852712045676582,
                    "size": 2419395,
                    "vd": -2.1
                },
                "a": {
                    "br": 64000,
                    "fid": 7761452580569932,
                    "size": 1634106,
                    "vd": 0
                },
                "cd": "",
                "rtUrl": null
            },
            {
                "rtUrls": [],
                "name": null,
                "id": 29881275,
                "v": 3,
                "st": 0,
                "t": 1,
                "fee": 0,
                "ftype": 0,
                "rtype": 0,
                "rurl": null,
                "no": 0,
                "pst": 0,
                "alia": [],
                "pop": 0,
                "rt": null,
                "mst": 9,
                "cp": 0,
                "crbt": null,
                "mv": 0,
                "cf": null,
                "ar": [
                    {
                        "id": 0,
                        "name": null
                    }
                ],
                "al": {
                    "id": 0,
                    "name": null,
                    "picStr": "0",
                    "pic": 0
                },
                "dt": 219000,
                "h": {
                    "br": 320000,
                    "fid": 0,
                    "size": 8776247,
                    "vd": 0
                },
                "m": {
                    "br": 160000,
                    "fid": 0,
                    "size": 4388199,
                    "vd": 0
                },
                "l": {
                    "br": 96000,
                    "fid": 0,
                    "size": 2632979,
                    "vd": 0
                },
                "a": null,
                "cd": null,
                "rtUrl": null,
                "pc": {
                    "nickname": "Catofes",
                    "uid": 37734080,
                    "sn": "Mirai Miracle",
                    "ar": "Ghost",
                    "alb": "",
                    "br": 320,
                    "fn": "x13079310.mp3",
                    "cid": ""
                }
            }

做了一定的删减,所以数据不完全。可以看出新版本api(毕竟有v2的标识)对于普通曲子的返回结果也变了,直接返回了多个品质的曲子,对应的不同的mp3文件。然后也包涵了自己上传的曲子的相关信息。

重要的有两个信息,一个应该是曲子的id:
"id": 29881275,
一个我猜是用户uid
"uid": 37734080,

访问
http://music.163.com/api/cloud/media/url?id=29881275&uid=37734080&quality=h

既可以得到对应的曲子地址。这个Cookie 只需要 os=pc 这一个存在即可
{"url":"http://m3.music.126.net/20150331230203/a053fee8eb3543bc430d356caffbb1e7/NTMxMzgxODA=/d251a331521f3cfa7618c67ad1c5a54f.mp3","bitrate":320000,"size":8776247,"code":200}

得到的链接应该就是播放链接。

至于本身是网易云的音乐文件,重要的参数是:
"h": {
"br": 320000,
"fid": 7852712045676580,
"size": 8062179,
"vd": -2.36
},
里面的fid。

随后pc会请求

/2LrzOopZvDTHbpM-LJm86w==/7852712045676588.mp3?v=17509840 (这是另一个曲子的链接,和另外一个曲子的fid对应,原来曲子的连接地址被我刷掉了。)测试了一下前面的字符串和现行api.py里面的encrypted_id(id)函数返回的是一样的。

@Catofes
Copy link
Collaborator Author

Catofes commented Mar 31, 2015

整个playlist json文件如下:
https://paste.xinu.at/r8Lso/

@Catofes
Copy link
Collaborator Author

Catofes commented Mar 31, 2015

MUSIC_U 的COOKIE 会在登陆 时候设置。

http://music.163.com/api/login/cellphone/?csrf_token=

访问这个api的时候会设置。

@Catofes
Copy link
Collaborator Author

Catofes commented Mar 31, 2015

还有http登陆也是醉了

@Catofes
Copy link
Collaborator Author

Catofes commented Mar 31, 2015

wine运行网易云音乐太蛋疼了。首先你要吧gpu进程kill掉,这样不会黑屏,然后在设置里吧cpu加速关掉。基本就可以运行了,听音乐一顿一顿的超赞(貌似要替换一个dll库)。焦点不再它的时候还有下面这个问题
2015-03-31 23 09 11

@chaserhkj
Copy link
Collaborator

MUSIC_U 应该是类似于csrf_token的东西,我之前分析Android客户端API的时候也发现过,应该是反跨站攻击用的

HTTP登陆的问题在 #48 有讨论,起码我确认Android客户端是HTTPS登录的

我们现在的api.py是不保留cookie的(就是没有session), 我正在chaserhkj:cloud这个分支上面试图实现一些修改和收藏歌单的功能,现在这边分支上的api.py版本已经换成使用保留cookie的session http请求了,并且还加了个auth=True的选项用来自动往api请求里添加csrf_token/MUSIC_U,有需要可以看看 = =

@chaserhkj
Copy link
Collaborator

以及我根本就wine不起来网易云音乐Orz, 直接崩溃退出什么的.

我这里都是抓手机客户端的包来分析API……

@Catofes
Copy link
Collaborator Author

Catofes commented Mar 31, 2015

@chaserhkj 咋回事。。我这边ARCH默认就wine的起来啊 要不你来我这看看怎么回事?

@chaserhkj
Copy link
Collaborator

@Catofes 我已经换Gentoo了……不知道和这个有没有关系
wine版本是 wine-1.7.38

@Catofes
Copy link
Collaborator Author

Catofes commented Mar 31, 2015

2333 @chaserhkj 抽空见个面调调看?

@chaserhkj
Copy link
Collaborator

学长机智地提出了面基的建议 (=゚ω゚)=
可以一试……

@darknessomi
Copy link
Owner

@Catofes @chaserhkj 你俩原来是校友啊,好基2333

另外感觉云盘这功能很鸡肋有木有?而且网易承担了一部分未知的侵权风险啊。

@darknessomi
Copy link
Owner

最重要的是,Mac 版居然没这功能😓

害我找了一圈= =

@draplater
Copy link

是我校的hkj?
On Mar 31, 2015 11:14 PM, "Huang, Kang-Jing" notifications@github.com
wrote:

以及我根本就wine不起来网易云音乐Orz, 直接崩溃退出什么的.

我这里都是抓手机客户端的包来分析API……


Reply to this email directly or view it on GitHub
#56 (comment).

@darknessomi
Copy link
Owner

@draplater 不啊,上面两位是 PKU 的物理大神啦

@draplater
Copy link

看来确实是我校的……

2015-04-01 17:17 GMT+08:00 ZHANG RT notifications@github.com:

@draplater https://github.com/draplater 不啊,上面两位是 PKU 的物理大神啦


Reply to this email directly or view it on GitHub
#56 (comment).

@Catofes
Copy link
Collaborator Author

Catofes commented Apr 1, 2015

233~

侵权应该谈不上,比较像Google play music
可以自己上传音乐,不过也只有你自己能访问。无法分享。用处我觉得不小,一些自己收集的曲子也可以在云端用了。

不过感觉v2 api迟早会上线替换掉现行的啊。
On Apr 1, 2015 17:38, "draplater" notifications@github.com wrote:

看来确实是我校的……

2015-04-01 17:17 GMT+08:00 ZHANG RT notifications@github.com:

@draplater https://github.com/draplater 不啊,上面两位是 PKU 的物理大神啦


Reply to this email directly or view it on GitHub
#56 (comment).


Reply to this email directly or view it on GitHub
#56 (comment).

@shiywang
Copy link
Contributor

shiywang commented Apr 2, 2015

好久没来了~~~
@darknessomi @Catofes @chaserhkj 感谢感谢,把我改的代码没填的坑都填好啦

@darknessomi
Copy link
Owner

54cc33d 不知为何,有些歌曲的❤加不上 = =

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants