好友
阅读权限 25
听众
最后登录 1970-1-1
本帖最后由 13955925361 于 2025-9-17 14:34 编辑
都说新版QQ音乐简单,我咋不觉得捏,就算逻辑通了,
光扣1400行, 写200行,json还得自己一个个取,ai是
不可能 用的,直接说你传入文字超过数量上限。
以搜索邓紫棋为例,获取歌曲的id,mid, albumid ,
构造Perform, 传入get_content函数就可以啦。
因为我不是绿钻,下载不了付费歌曲,headers和cookies
改成有会员的就可以实现全部下载。
免费的歌曲我写个了代码实例给大家参考,这个是可以获取
完整时长的音乐。
扣的1400多行我放压缩包里了,这是核心JS代码。
QQ音乐.js
[JavaScript] 纯文本查看 复制代码
window=global
window.crypto=require("crypto")
location={
"host": "y.qq.com",
}
navigator={'userAgent':
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0"}
function encrypt(encryp_data){
existingBuffer = Buffer.from(encryp_data);
arrayBuffer = existingBuffer.buffer.slice(
existingBuffer.byteOffset,
existingBuffer.byteOffset + existingBuffer.byteLength
);
return JSON.parse(N(arrayBuffer))}
QQ.js:
[JavaScript] 纯文本查看 复制代码
window=global
window.crypto=require("crypto")
location={
"host": "y.qq.com",
}
navigator={'userAgent':
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0"}
function encrypt(encryp_data){existingBuffer = Buffer.from(encryp_data);
arrayBuffer = existingBuffer.buffer.slice(
existingBuffer.byteOffset,
existingBuffer.byteOffset + existingBuffer.byteLength
);
return JSON.parse(N(arrayBuffer))}
const base64=require('base64-js');
axx=process.argv[2]
// axx='{"comm":{"cv":4747474,"ct":24,"format":"json","inCharset":"utf-8","outCharset":"utf-8","notice":0,"platform":"yqq.json","needNewCode":1,"uin":2509034534,"g_tk_new_20200303":264421996,"g_tk":264421996},"req_1":{"method":"DoSearchForQQMusicDesktop","module":"music.search.SearchCgiService","param":{"remoteplace":"txt.yqq.top","searchid":"57356518041915261","search_type":0,"query":"许嵩","page_num":1,"num_per_page":10}}}'
console.log(P(axx))
L(axx).then(res => {console.log(res)})
Python代码:
[Python] 纯文本查看 复制代码
import subprocess
import json
import execjs
from functools import partial
import os
os_path= os.getcwd() + '/QQ音乐歌曲/'
if not os.path.exists(os_path):
os.mkdir(os_path)
subprocess.Popen = partial(subprocess.Popen, encoding="utf-8")
import time
import base64
from pprint import pprint
cmd = ["node", "./qq音乐.js",'{"comm":{"cv":4747474,"ct":24,"format":"json","inCharset":"utf-8","outCharset":"utf-8","notice":0,"platform":"yqq.json","needNewCode":1,"uin":2509034534,"g_tk_new_20200303":264421996,"g_tk":264421996},"req_1":{"method":"DoSearchForQQMusicDesktop","module":"music.search.SearchCgiService","param":{"remoteplace":"txt.yqq.top","searchid":"63738392772163580","search_type":0,"query":"G.E.M. 邓紫棋","page_num":1,"num_per_page":10}}}'
]
text= subprocess.check_output(cmd).strip()
sign=text.split('\n')[0]
key=text.split('\n')[1]
print(sign)
print( key)
import requests
headers = {
"accept": "application/octet-stream",
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"cache-control": "no-cache",
"content-type": "text/plain",
"origin": "https://y.qq.com",
"pragma": "no-cache",
"priority": "u=1, i",
"referer": "https://y.qq.com/",
"sec-ch-ua": "\"Chromium\";v=\"140\", \"Not=A?Brand\";v=\"24\", \"Microsoft Edge\";v=\"140\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0"
}
cookies = {
"ts_uid": "885560536",
"RK": "BOnZhaf75v",
"ptcz": "504c023335c8bddd3c2a9b1afb43584bb8b2380b558ae34a8974c5ba8c4c87cc",
"pgv_pvid": "781480164",
"yyb_muid": "2EF66898AFD462E120A47B58AEFA63AC",
"fqm_pvqid": "235cd264-b12b-4977-a9fb-256434e665ac",
"fqm_sessionid": "aa29ae21-3dfb-4076-937f-bd48f9c9c2c3",
"pgv_info": "ssid=s2691900626",
"ts_refer": "www.sogou.com/link",
"_qpsvr_localtk": "0.1891120457098312",
"login_type": "1",
"tmeLoginType": "2",
"psrf_access_token_expiresAt": "1763215068",
"wxunionid": "",
"wxopenid": "",
"wxrefresh_token": "",
"music_ignore_pskey": "202306271436Hn@vBj",
"psrf_qqrefresh_token": "BBF4B8806A89500D2D06EC60BEC030CD",
"euin": "ow4zNKni7e4i7n**",
"psrf_qqopenid": "2885F7A9CC26657432288010503BACF5",
"qqmusic_key": "Q_H_L_63k3NI84ybImubet9E3hW6h_XbVEI_y4R-OKJ8BE_nWJcmvDbySZomL3gc8RZzvxBQSInkFDP4heEgDhBPKcIf3pJm0yPMA",
"psrf_qqaccess_token": "B3B376C6BBE6B237576B6F4F9958CFF7",
"qm_keyst": "Q_H_L_63k3NI84ybImubet9E3hW6h_XbVEI_y4R-OKJ8BE_nWJcmvDbySZomL3gc8RZzvxBQSInkFDP4heEgDhBPKcIf3pJm0yPMA",
"psrf_qqunionid": "468397ADDD0836EA577CB89FBBBAA840",
"psrf_musickey_createtime": "1758031068",
"uin": "2509034534",
"ts_last": "y.qq.com/n/ryqq/songDetail/001N8e5Q4Gjxda"
}
url = "https://u6.y.qq.com/cgi-bin/musics.fcg"
params = {
"_": "int(time.time() * 1000)",
"encoding": "ag-1",
"sign": sign
}
def save_song( url, name,title):
data = requests.get(url, headers=headers).content
with open(os_path + name + title + '.mp3', 'wb') as f:
f.write(data)
print(f"歌曲 :{name} -{ title} - - 下载完成")
def get_content( perform):
# perform={"comm":{"cv":4747474,"ct":24,"format":"json","inCharset":"utf-8","outCharset":"utf-8","notice":0,"platform":"yqq.json","needNewCode":1,"uin":2509034534,"g_tk_new_20200303":96573415,"g_tk":96573415},"req_1":{"module":"music.musichallSong.PlayLyricInfo","method":"GetPlayLyricInfo","param":{"songMID":mid,"songID":songid}},"req_2":{"method":"GetCommentCount","module":"music.globalComment.GlobalCommentRead","param":{"request_list":[{"biz_type":1,"biz_id":f"{songid}","biz_sub_type":0}]}},"req_3":{"module":"music.musichallAlbum.AlbumInfoServer","method":"GetAlbumDetail","param":{"albumMid":albumid}},"req_4":{"module":"music.vkey.GetEVkey","method":"GetUrl","param":{"guid":"5288187792","songmid":[mid],"songtype":[0],"uin":"2509034534","loginflag":1,"platform":"20","xcdn":1,"qdesc":"lq96kOgg"}}}
form = json.dumps(perform)
cmd = ["node", "./qq音乐.js", form]
text = subprocess.check_output(cmd).strip()
sign = text.split('\n')[0]
key = text.split('\n')[1]
params = {
"_": "int(time.time() * 1000)",
"encoding": "ag-1",
"sign": sign
}
response = requests.post(url, headers=headers, cookies=cookies, params=params, data=key)
content = list(response.content)
with open('qq.js', 'r', encoding='utf-8') as f:
js_code = f.read()
ctx = execjs.compile(js_code)
result = ctx.call('encrypt', content)
return result
response = requests.post(url, headers=headers, cookies=cookies, params=params, data=key)
content=list(response.content)
with open ('qq.js', 'r', encoding='utf-8') as f:
js_code = f.read()
ctx = execjs.compile(js_code)
result=ctx.call('encrypt',content)
# pprint(result)
result_list=result['req_1']['data']['body']['song']['list']
# pprint(result_list)
for i in result_list:
title=i['title'],
singer=i['singer'][0]['name'],
mid= i['mid'],
songid=i['id'],
albumid=i['album']['mid']
print(f'{title} {singer} {mid} {songid} {albumid}')
perform={"comm":{"cv":4747474,"ct":24,"format":"json","inCharset":"utf-8","outCharset":"utf-8","notice":0,"platform":"yqq.json","needNewCode":1,"uin":2509034534,"g_tk_new_20200303":96573415,"g_tk":96573415},"req_1":{"module":"music.musichallSong.PlayLyricInfo","method":"GetPlayLyricInfo","param":{"songMID":mid,"songID":songid}},"req_2":{"method":"GetCommentCount","module":"music.globalComment.GlobalCommentRead","param":{"request_list":[{"biz_type":1,"biz_id":f"{songid}","biz_sub_type":0}]}},"req_3":{"module":"music.musichallAlbum.AlbumInfoServer","method":"GetAlbumDetail","param":{"albumMid":albumid}},"req_4":{"module":"music.vkey.GetEVkey","method":"GetUrl","param":{"guid":"5288187792","songmid":[mid],"songtype":[0],"uin":"2509034534","loginflag":1,"platform":"20","xcdn":1,"qdesc":"lq96kOgg"}}}
# music=get_content(perform)
###免费歌曲举例###
perform={"comm":{"cv":4747474,"ct":24,"format":"json","inCharset":"utf-8","outCharset":"utf-8","notice":0,"platform":"yqq.json","needNewCode":1,"uin":2509034534,"g_tk_new_20200303":96573415,"g_tk":96573415},"req_1":{"module":"music.musichallSong.PlayLyricInfo","method":"GetPlayLyricInfo","param":{"songMID":"002mxYoy1LkLkw","songID":604203206}},"req_2":{"method":"GetCommentCount","module":"music.globalComment.GlobalCommentRead","param":{"request_list":[{"biz_type":1,"biz_id":"604203206","biz_sub_type":0}]}},"req_3":{"module":"music.musichallAlbum.AlbumInfoServer","method":"GetAlbumDetail","param":{"albumMid":"002t3JZZ3lJKZy"}},"req_4":{"module":"music.vkey.GetEVkey","method":"GetUrl","param":{"guid":"8160588230","songmid":["002mxYoy1LkLkw"],"songtype":[0],"uin":"2509034534","loginflag":1,"platform":"20","xcdn":1,"qdesc":"lq96kOgg"}}}
music=get_content(perform)
music_url=music['req_4']['data']['midurlinfo'][0]['xcdnurl']
print(music_url)
save_song(music_url, 'name','title')
QQ音乐.zip
33.59 KB, 下载次数: 257, 下载积分: 吾爱币 -1 CB
免费评分
查看全部评分