吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 6694|回复: 45
上一主题 下一主题
收起左侧

[Python 转载] QQ音乐搜索接口下载音乐

[复制链接]
跳转到指定楼层
楼主
13955925361 发表于 2025-9-17 14:11 回帖奖励
本帖最后由 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

免费评分

参与人数 4吾爱币 +9 热心值 +3 收起 理由
zhou19900615 + 1 谢谢@Thanks!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
luozi1653 + 1 + 1 热心回复!
yukingw + 1 谢谢@Thanks!

查看全部评分

发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

推荐
水清无余 发表于 2025-9-17 14:15
大佬没压缩包呀
推荐
yang2018 发表于 2025-11-15 19:26
本帖最后由 yang2018 于 2025-11-15 19:28 编辑

运行提示错误:
Traceback (most recent call last):
  File "qq.py", line 17, in <module>
    text= subprocess.check_output(cmd).strip()
  File "C:\Program Files\python\lib\subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "C:\Program Files\python\lib\subprocess.py", line 489, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Program Files\python\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Program Files\python\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] 系统找不到指定的文件。
3#
 楼主| 13955925361 发表于 2025-9-17 14:28 |楼主
本帖最后由 13955925361 于 2025-9-17 14:32 编辑

我一直在编辑帖子,改好了。有会员的话改下cookies,不然只能下免费歌曲。
头像被屏蔽
4#
appstore 发表于 2025-9-17 14:32
提示: 作者被禁止或删除 内容自动屏蔽
5#
水清无余 发表于 2025-9-17 14:32
好的 感谢
6#
qhd11 发表于 2025-9-17 14:35
免费的随便下也不错。
7#
thxyhuang 发表于 2025-9-17 14:40
必须点赞,大佬牛逼
8#
xxooxx 发表于 2025-9-17 14:52
存在有2个问题:
1.开了会员也是有次数下载的限制。次数用完了,就算是会员也不能下载。
2.下载了也只能在QQ音乐才能播放,非会员不能播放会员歌曲。

注:非会员不能播放已下载的会员歌曲,这个我还没验证不知道现在是否还是这样。如果下载后自动转换成mp3等可以正常播放的非腾讯格式,应该就不受这个限制了。
9#
otg007 发表于 2025-9-17 15:22
我怎么下载无损也没花钱
10#
aiyu07 发表于 2025-9-17 15:25
可以随便下载的吗
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - 52pojie.cn ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2026-11-8 11:33

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表