Last active
October 22, 2021 05:53
-
-
Save WincerChan/abb6da2399107db125c38c75d84e36ff to your computer and use it in GitHub Desktop.
获得QQ音乐直链
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from json import loads as jsload | |
from os import system | |
from random import random | |
from time import time | |
from requests import get as request | |
def resolve(sMid): | |
filename = 'C400' + sMid + '.m4a' | |
guid = int(random() * 2147483647) * int(time() * 1000) % 10000000000 | |
data = { | |
'format': 'json', | |
'cid': 205361747, | |
'uin': 0, | |
'songmid': sMid, | |
'filename': filename, | |
'guid': guid, | |
} | |
url = 'https://c.y.qq.com/base/fcgi-bin/fcg_music_express_mobile3.fcg' | |
r = request(url, params=data) | |
vkey = jsload(r.content)['data']['items'][0]['vkey'] | |
audio_url = ('https://dl.stream.qqmusic.qq.com/' | |
'{}?vkey={}&guid={}&uin=0&fromtag=66'.format( | |
filename, vkey, guid)) | |
return audio_url | |
def hand_error(name): | |
exit = False | |
while name != '': | |
prefix = ('https://c.y.qq.com/soso/fcgi-bin/' | |
'client_search_cp?ct=24&cr=1&w=') | |
r = request(prefix + name).text | |
cont = eval(r[9:-1]) | |
names = [] | |
try: | |
for x in range(10): | |
print('{}: \t {} - {}'.format(x, cont['data']['song']['list'][ | |
x]['singer'][0]['name'], cont['data']['song']['list'][x][ | |
'songname'])) | |
names.append(cont['data']['song']['list'][x]['songmid']) | |
except Exception as e: | |
pass | |
finally: | |
a = input('输入编号: ') | |
try: | |
sMid = names[int(a)] | |
dir_url = resolve(sMid) | |
except: | |
print('Please reinput.') | |
exit = True | |
if exit is False: | |
print('歌曲直链已复制至剪贴板'.format( | |
dir_url)) | |
system('echo \'{}\' | xsel -b'.format(dir_url)) | |
name = input('请重新输入信息(Enter 退出): ') | |
if __name__ == "__main__": | |
name = input('输入歌曲名或者歌手名: ') | |
hand_error(name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment