-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path清明雨上
132 lines (120 loc) · 6.5 KB
/
清明雨上
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
from Crypto.Cipher import AES
import base64
import json
import requests
from bs4 import BeautifulSoup
import json
import requests
from bs4 import BeautifulSoup
id=input("请输入歌曲的id:")
url="https://music.163.com/song?id={}".format(str(id))
headers={
'authority':'music.163.com',
'method':'GET',
'path':'/song?id=167882',
'scheme':'https',
'accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
# 'accept-encoding':'gzip,deflate,br',
'accept-language':'zh-CN,zh;q=0.9',
'cache-control':'no-cache',
'cookie':'_iuqxldmzr_=32;_ntes_nnid=5a92b3ce0512ad0bee4fcc23cba878f7,1616329117433;_ntes_nuid=5a92b3ce0512ad0bee4fcc23cba878f7;NMTID=00OQccTzqvsbgQ5VUQIhi4xyGA9UagAAAF4VLkTaA;WM_TID=%2B0lbH8Uqy9JABEBERQc%2FhWD%2FMh6dht34;WM_NI=YBj1A9zOhKJemkoTqbDQdzisnYZPpvdiMF1%2BPyIHFhbxCW2PuC8ad4tXJdY1NB1A8kcrrrbcw9ypYg5KEYLvn7ncYH7tWoVpH42V5vUz647DJYN7iIOcp5uVIAgnZv%2BIUUE%3D;WM_NIKE=9ca17ae2e6ffcda170e2e6eeb7f862f3f5ada2b63eb4ac8ab2d84a928f9eaeaa3ba89baddac641968b82b8dc2af0fea7c3b92a9b9ea6d2c433ba91a8acc96fafb5a1b5f46a888fac9bec79ae8796b1f37ea8b783a7b42194a787a9c564a2a88db8b15cb79df882e740b8888685dc3b8e9effa2bb61a1aebe93e169b5e7b791dc6df7958bbacf7eaee9a284dc44f5ac9990d57c8cecfeb7b87e97a6fad5b6508a8782d8ec438dbdc0d6f85e8b9fa98fd97ee9979bb6c837e2a3;WEVNSM=1.0.0;WNMCID=bboafb.1617102917304.01.0;playerid=51914285;JSESSIONID-WYYY=DESDdf7%2F%2B0kVtJkVduxVox70UwIUD6vbKs6C2rWoayGgpuRS6R5aZbthxmEaegS3%2B7wvime%2F073zg%2BaCx3A3wG%2B%2B4TbCi6t3nUJsoJzWR%2F2FAkosejSYF8s3f14f6jsWx%5CxCGuK3RqVXwidtqz%2Bx%2BR7r6ukTEC4YbJ%5CyN4rw10yOczW3%3A1617113948045',
'pragma':'no-cache',
'referer':'https://music.163.com/',
'sec-ch-ua':'"GoogleChrome";v="89","Chromium";v="89",";NotABrand";v="99"',
'sec-ch-ua-mobile':'?0',
'sec-fetch-dest':'iframe',
'sec-fetch-mode':'navigate',
'sec-fetch-site':'same-origin',
'upgrade-insecure-requests':'1',
'user-agent':'Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/89.0.4389.90Safari/537.36'
}
requests.packages.urllib3.disable_warnings()
res = requests.get(url,headers=headers,verify=False)
r=res.text
soup=BeautifulSoup(r,"lxml")#对返回的数据进行解析
song_name=soup.title.string.split("-")[0]
print(song_name)
first_param = '{"ids":"[%s]","level":"standard","encodeType":"aac","csrf_token":""}'%str(id) # ids:歌曲id
second_param = '010001'
third_param = '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7'
fourth_param = '0CoJUm6Qyw8W8jud'
def get_params():
#根据该加密算法做出解密
iv = '0102030405060708'
first_key = fourth_param
second_key = 16 * 'F'
h_encText = AES_encrypt(first_param, first_key, iv)
h_encText = AES_encrypt(h_encText, second_key, iv)
return h_encText
def AES_encrypt(text, key, iv):
if type(text) == type(b'123'):
#这是判断当前变量的类型是bytes还是字符串,因为pycryptodome要
#求参数要是字节类型
text = text.decode('utf-8')
pad = 16 - len(text) % 16
text = text + pad*chr(pad)
iv = iv.encode('utf-8')
key = key.encode('utf-8')
encryptor = AES.new(key, AES.MODE_CBC, iv)
text = text.encode('utf-8')
encrypt_text = encryptor.encrypt(text)
encrypt_text = base64.b64encode(encrypt_text)
return encrypt_text
params = get_params()
url="https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token="
headers={
'authority':'music.163.com',
'method':'POST',
'path':'/weapi/song/enhance/player/url/v1?csrf_token=',
'scheme':'https',
'accept':'*/*',
# 'accept-encoding':'gzip,deflate,br',
'accept-language':'zh-CN,zh;q=0.9',
'cache-control':'no-cache',
'content-length':'436',
'content-type':'application/x-www-form-urlencoded',
'cookie':'_iuqxldmzr_=32;_ntes_nnid=5a92b3ce0512ad0bee4fcc23cba878f7,1616329117433;_ntes_nuid=5a92b3ce0512ad0bee4fcc23cba878f7;NMTID=00OQccTzqvsbgQ5VUQIhi4xyGA9UagAAAF4VLkTaA;WM_TID=%2B0lbH8Uqy9JABEBERQc%2FhWD%2FMh6dht34;JSESSIONID-WYYY=mdXIX9%2B%2BuB%2FBkT9A0OdxHTDtgNYOC%5C6hr7yYhFnrMSZJRxJ341Ni%2FIs3J9ttfoa5UDUcWg%2B%2Bl7pQBN7%2FmtsTnk4%2FdewBdn0T3ecT6gAIcX9dJ%2F0Sg1syev8%2BCsUipmY0f6esB3Rv%2BcIPk799TgHg%2Bwp%5CRPSodMysWc2vG%2FXkssmpzCOO%3A1617103483073;WM_NI=YBj1A9zOhKJemkoTqbDQdzisnYZPpvdiMF1%2BPyIHFhbxCW2PuC8ad4tXJdY1NB1A8kcrrrbcw9ypYg5KEYLvn7ncYH7tWoVpH42V5vUz647DJYN7iIOcp5uVIAgnZv%2BIUUE%3D;WM_NIKE=9ca17ae2e6ffcda170e2e6eeb7f862f3f5ada2b63eb4ac8ab2d84a928f9eaeaa3ba89baddac641968b82b8dc2af0fea7c3b92a9b9ea6d2c433ba91a8acc96fafb5a1b5f46a888fac9bec79ae8796b1f37ea8b783a7b42194a787a9c564a2a88db8b15cb79df882e740b8888685dc3b8e9effa2bb61a1aebe93e169b5e7b791dc6df7958bbacf7eaee9a284dc44f5ac9990d57c8cecfeb7b87e97a6fad5b6508a8782d8ec438dbdc0d6f85e8b9fa98fd97ee9979bb6c837e2a3;WEVNSM=1.0.0;WNMCID=bboafb.1617102917304.01.0;playerid=99031207',
'origin':'https://music.163.com',
'pragma':'no-cache',
'referer':'https://music.163.com/',
'sec-ch-ua':'"GoogleChrome";v="89","Chromium";v="89",";NotABrand";v="99"',
'sec-ch-ua-mobile':'?0',
'sec-fetch-dest':'empty',
'sec-fetch-mode':'cors',
'sec-fetch-site':'same-origin',
'user-agent':'Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/89.0.4389.90Safari/537.36',
}
data={
'params':params,
'encSecKey':'257348aecb5e556c066de214e531faadd1c55d814f9be95fd06d6bff9f4c7a41f831f6394d5a3fd2e3881736d94a02ca919d952872e7d0a50ebfa1769a7a62d512f5f1ca21aec60bc3819a9c3ffca5eca9a0dba6d6f7249b06f5965ecfff3695b54e1c28f3f624750ed39e7de08fc8493242e26dbc4484a01c76f739e135637c'
}
requests.packages.urllib3.disable_warnings()
res = requests.post(url,headers=headers,data=data,verify=False)
r=res.text
a=res.json()
song_url=a['data'][0]['url']
print(song_url)
Host=song_url.split("/")[2]
url=song_url
headers={
'Accept':'*/*',
'Accept-Encoding':'identity',
'Accept-Language':'zh-CN,zh;q=0.9',
'Connection':'keep-alive',
'Host':Host,
'Origin':'https://music.163.com',
'Range':'bytes=0-',
'Referer':'https://music.163.com/',
'sec-ch-ua':'"GoogleChrome";v="89","Chromium";v="89",";NotABrand";v="99"',
'sec-ch-ua-mobile':'?0',
'Sec-Fetch-Dest':'empty',
'Sec-Fetch-Mode':'cors',
'Sec-Fetch-Site':'cross-site',
'User-Agent':'Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/89.0.4389.90Safari/537.36',
}
requests.packages.urllib3.disable_warnings()
res = requests.get(url,headers=headers,verify=False)
r=res.content
with open("k:/zhusc/{}.m4a".format(song_name),'wb') as f:
f.write(r)
f.close()