Skip to content

Commit f34dfe0

Browse files
authored
Add files via upload
1 parent 6231930 commit f34dfe0

8 files changed

Lines changed: 231 additions & 0 deletions

File tree

‎网易云下载/chromedriver.exe‎

6.38 MB
Binary file not shown.

‎网易云下载/file/他不懂.mp3‎

3.54 MB
Binary file not shown.
4.33 MB
Binary file not shown.
4.02 MB
Binary file not shown.

‎网易云下载/file/绅士.mp3‎

4.44 MB
Binary file not shown.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import json
2+
from Crypto.Cipher import AES
3+
import base64
4+
from Crypto.PublicKey import RSA
5+
import codecs
6+
import random
7+
#PKCS_7方式进行补位
8+
def pad(data:bytes,blockbytes:int=16):
9+
"""
10+
data:需要补位的bytes
11+
blockbytes:块bytes大小
12+
"""
13+
_data = data
14+
#判断是否是字符串,如果是则按utf8编码为bytes
15+
if isinstance(_data,str):
16+
_data = _data.encode('utf8')
17+
length = len(_data)
18+
pad_length = blockbytes - length % blockbytes
19+
padding = (chr(pad_length)*pad_length).encode('utf8')
20+
_data += padding
21+
return _data
22+
23+
#dict序列化
24+
def dictSerialize(data:dict):
25+
if not isinstance(data,dict):
26+
_data = dict(data)
27+
_data = data
28+
_data = json.dumps(_data,ensure_ascii=False)
29+
return _data
30+
31+
#生成随机值用于AES第二阶段加密的密钥
32+
def rand_a(a=16):
33+
b = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
34+
c = ""
35+
length = len(b)
36+
for _ in range(a):
37+
c += b[int(random.random()*length)]
38+
return c
39+
40+
#aes加密
41+
def aes_encrypt(data,key,iv,mode=AES.MODE_CBC):
42+
"""
43+
data:明文
44+
key:密钥
45+
iv:偏移量
46+
mode:模式,默认为CBC模式
47+
"""
48+
encryptor=AES.new(key.encode('utf-8'),mode=mode,IV=iv.encode('utf-8'))
49+
#补位操作
50+
_data = pad(data,16)
51+
encrypted_data = encryptor.encrypt(_data)
52+
return base64.b64encode(encrypted_data)
53+
54+
#aes解密
55+
def aes_decrypt(data,key,iv,mode=AES.MODE_CBC):
56+
"""
57+
data:密文
58+
key:密钥
59+
iv:偏移量
60+
mode:模式,默认为CBC模式
61+
"""
62+
decryptor = AES.new(key,mode=mode,IV=iv)
63+
return decryptor.decrypt(data)
64+
65+
def netEase_AES_encrypt(data,key1,key2,iv,mode=AES.MODE_CBC):
66+
"""
67+
data:明文
68+
key1:第一阶段密钥
69+
key2:第二阶段密钥
70+
iv:偏移量
71+
mode:模式,默认为CBC模式
72+
"""
73+
if isinstance(data,dict):
74+
_data = dictSerialize(data)
75+
_data = str(data)
76+
_encryptedData = aes_encrypt(_data,key1,iv,mode)
77+
_encryptedData = aes_encrypt(_encryptedData,key2,iv,mode)
78+
return _encryptedData.decode('utf8')
79+
80+
def netEase_AES_decryot(data,key1,key2,iv,mode=AES.MODE_CBC):
81+
"""
82+
data:密文
83+
key1:第一阶段加密函数
84+
key2:第二阶段加密函数
85+
iv:偏移量
86+
mode:模式,默认为CBC模式
87+
"""
88+
_data = base64.b64decode(data)
89+
plaintext = aes_decrypt(_data,key2,iv,mode)
90+
plaintext = base64.b64decode(plaintext)
91+
plaintext = aes_decrypt(plaintext,key1,iv,mode)
92+
plaintext = plaintext.decode('utf8')
93+
return plaintext
94+
95+
96+
def netEase_RSA_encrypt_NoPadding(data:str,publickey:str,module:str):
97+
"""
98+
RSA采用Nopadding方式,即明文先倒排,再在前面补0
99+
data:明文
100+
publickey:公钥
101+
module:RSA中两个大质数的乘积
102+
"""
103+
#网易云云音乐中js加密采用的算法中的参数是以16进制来操作的
104+
_publickey = int(publickey,16)
105+
_module = int(module,16)
106+
_data = data[::-1]
107+
_data = int(codecs.encode(_data.encode('utf8'),'hex'),16)
108+
#RSA加密过程
109+
rs = _data**_publickey%_module
110+
#返回16进制解码,前面补0补足256位的字符串
111+
return format(rs,'x').zfill(256)
112+
113+

‎网易云下载/search.py‎

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#author:九世
2+
#time:2019/2/11
3+
4+
import requests
5+
from netEaseMusicEncrypt import rand_a, netEase_AES_encrypt,netEase_RSA_encrypt_NoPadding,dictSerialize,aes_encrypt
6+
import webbrowser
7+
import os
8+
9+
musica={}
10+
11+
print('作者:By 九世')
12+
print('网易云音乐搜索')
13+
print('')
14+
user = input('输入你要搜索的歌手或歌曲名称:')
15+
query = {"s": "{}".format(user), "limit": "8", "csrf_token": ""}
16+
key1 = "0CoJUm6Qyw8W8jud"
17+
iv = "0102030405060708"
18+
19+
# 公钥对,hex16进制编码
20+
module = "00e0b509f6259df8642dbc35662901477df22677ec152b5ff68a\
21+
ce615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7"
22+
publickey = "010001"
23+
# 序列化查询dict
24+
queryStr = dictSerialize(query)
25+
26+
aaa = aes_encrypt(queryStr, key1, iv)
27+
# AES加密随机量
28+
key2 = rand_a()
29+
secretStr = netEase_AES_encrypt(queryStr, key1, key2, iv) # 加密后的params
30+
rsaSec = netEase_RSA_encrypt_NoPadding(key2, publickey, module) # 加密后的key
31+
32+
33+
class Search:
34+
def __init__(self,headers,url,data):
35+
self.headers=headers
36+
self.url=url
37+
self.data=data
38+
39+
def reqt(self):
40+
try:
41+
rqt=requests.post(url=self.url,headers=self.headers,data=self.data)
42+
jsons=rqt.json()
43+
44+
result=jsons['result']
45+
songs=result['songs']
46+
for s in songs:
47+
print('歌曲名称:{} 下载ID:{}'.format(s['name'],s['id']))
48+
musica[s['name']]=s['id']
49+
50+
except Exception as r:
51+
print('[-] 报错:{}'.format(r))
52+
return ''
53+
return 1
54+
55+
def music(self):
56+
print('')
57+
ids=input('请输入歌曲的名称,q退出:')
58+
if ids in musica.keys():
59+
print('[+] 自动打开默认浏览器,在线试听')
60+
value=musica.get(ids)
61+
url='http://music.163.com/song/media/outer/url?id={}'.format(value)
62+
webbrowser.open(url)
63+
elif ids=='q':
64+
print('退出...')
65+
exit()
66+
else:
67+
print('[-] 找不到歌曲')
68+
69+
def download(self):
70+
print('')
71+
ids = input('请输入歌曲的名称,q是退出:')
72+
if ids in musica.keys():
73+
print('[+] 下载中')
74+
value = musica.get(ids)
75+
url = 'http://music.163.com/song/media/outer/url?id={}'.format(value)
76+
rst=requests.get(url=url,headers=self.headers)
77+
rst2=requests.get(url=rst.url,headers=self.headers)
78+
xj=open('file/{}.mp3'.format(ids),'wb')
79+
xj.write(rst2.content)
80+
xj.close()
81+
if os.path.exists('file/{}.mp3'.format(ids)):
82+
print('[+] {}.mp3 下载成功'.format(ids))
83+
else:
84+
print('[-] {}.mp3 下载失败'.format(ids))
85+
elif ids=='q':
86+
print('退出...')
87+
exit()
88+
else:
89+
print('[-] 找不到歌曲')
90+
91+
92+
if __name__ == '__main__':
93+
headers={'user-agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36','Content-Type': 'application/x-www-form-urlencoded'}
94+
url='http://music.163.com/weapi/search/suggest/web?csrf_token='
95+
data={'params':secretStr,'encSecKey':rsaSec}
96+
obj=Search(headers=headers,url=url,data=data)
97+
rs=obj.reqt()
98+
while True:
99+
if rs==1:
100+
print('1.自动打开浏览器试听')
101+
print('2.下载')
102+
print('0.退出')
103+
useq=input('请选择:')
104+
if useq=='1':
105+
while True:
106+
obj.music()
107+
elif useq=='2':
108+
while True:
109+
obj.download()
110+
elif useq=='0':
111+
print('退出...')
112+
exit()
113+
else:
114+
print('[-] 没有这个选择')

‎网易云下载/目标.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## 目标 ##
2+
- [x] 可以搜索
3+
- [x] 可以自动打开默认浏览器试听
4+
- [x] 可以下载

0 commit comments

Comments
 (0)