博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python qq音乐下载
阅读量:4927 次
发布时间:2019-06-11

本文共 5355 字,大约阅读时间需要 17 分钟。

import math

import random
import codecs
import requests
import json
id=1
headers='''
accept: */*
accept-encoding: gzip, deflate, br
accept-language: zh-CN,zh;q=0.9,en;q=0.8
content-length: 201
content-type: application/x-www-form-urlencoded; charset=UTF-8
cookie: pgv_pvid=860409964; pgv_info=ssid=s283563460; tvfe_boss_uuid=7df2cac8bd6193a0; RK=iBBlJzZwNG; ptcz=1b235f9fcb71c931519073ed89b7d0e1bf4fd7a37630b3e2112aa5ebe841ba9e; pgv_pvi=8337976320; pgv_si=s4545376256; qz_gdt=5zt7mw7oaaahtx4vdusq; user_id=null; session_id=null; mobileUV=1_16796a94224_9f543; sd_userid=21341547794618409; sd_cookie_crttime=1547794618409; eas_sid=P1k5D4s919o3T798f0w8c2Y371; TGLoginJSCurDomain=tgideas.qq.com; qqmusic_uin=; qqmusic_key=; _qpsvr_localtk=0.7566170047720839; ptisp=cm; FTN5K=89b569ab; rv2=80DF8075170C27D2FBF99E2F84C9FFB75D5BCA8BD598786AB6; property20=5083A8E64673E26FE991BFB43C3B54CBCBF3E93ED1C1C3394A648935FEC5AB663DA23B12282236EC; ts_uid=3083466358; p_uin=o1026091321; pt4_token=D0GB8D5DXf9zY83tBIFfMSIsKxnD6y7qqKcyOLDufr4_; p_skey=b7sz55F8Ei21tjLcQ95WaMf3vq2Ihyyo4hz1MT6J4pY_; p_luin=o1026091321; p_lskey=000400002d26246df8c78585a3180a4cf6ba01ee74e283cd46d42226de92c040e398b5780ee7d5d00ea5f75e; o_cookie=1026091321; verifysession=h011ca7b768a6475e7a39d2e1fd4e45fdb73f928d1eb8a0b611ac442689e51938f5021a6e8743544aee; qqmusic_fromtag=66; pac_uid=1_1026091321; userAction=1; yqq_stat=0; ts_refer=www.cnblogs.com/; yq_playschange=0; yq_playdata=; player_exist=1; yq_index=0; yplayer_open=1; ts_last=y.qq.com/portal/player.html
origin: https://y.qq.com
referer: https://y.qq.com/portal/player.html
user-agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36
'''

mp3headers='''

accept: application/json, text/javascript, */*; q=0.01
accept-encoding: gzip, deflate, br
accept-language: zh-CN,zh;q=0.9,en;q=0.8
cookie: pgv_pvid=860409964; pgv_info=ssid=s283563460; tvfe_boss_uuid=7df2cac8bd6193a0; RK=iBBlJzZwNG; ptcz=1b235f9fcb71c931519073ed89b7d0e1bf4fd7a37630b3e2112aa5ebe841ba9e; pgv_pvi=8337976320; pgv_si=s4545376256; qz_gdt=5zt7mw7oaaahtx4vdusq; user_id=null; session_id=null; mobileUV=1_16796a94224_9f543; sd_userid=21341547794618409; sd_cookie_crttime=1547794618409; eas_sid=P1k5D4s919o3T798f0w8c2Y371; TGLoginJSCurDomain=tgideas.qq.com; qqmusic_uin=; qqmusic_key=; _qpsvr_localtk=0.7566170047720839; ptisp=cm; FTN5K=89b569ab; rv2=80DF8075170C27D2FBF99E2F84C9FFB75D5BCA8BD598786AB6; property20=5083A8E64673E26FE991BFB43C3B54CBCBF3E93ED1C1C3394A648935FEC5AB663DA23B12282236EC; ts_uid=3083466358; p_uin=o1026091321; pt4_token=D0GB8D5DXf9zY83tBIFfMSIsKxnD6y7qqKcyOLDufr4_; p_skey=b7sz55F8Ei21tjLcQ95WaMf3vq2Ihyyo4hz1MT6J4pY_; p_luin=o1026091321; p_lskey=000400002d26246df8c78585a3180a4cf6ba01ee74e283cd46d42226de92c040e398b5780ee7d5d00ea5f75e; o_cookie=1026091321; verifysession=h011ca7b768a6475e7a39d2e1fd4e45fdb73f928d1eb8a0b611ac442689e51938f5021a6e8743544aee; qqmusic_fromtag=66; pac_uid=1_1026091321; userAction=1; yqq_stat=0; ts_refer=www.cnblogs.com/; yq_playschange=0; yq_playdata=; player_exist=1; yplayer_open=1; ts_last=y.qq.com/portal/player.html; yq_index=1
origin: https://y.qq.com
referer: https://y.qq.com/portal/player.html
user-agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36'''
downheader='''
Accept-Encoding: identity;q=1, *;q=0
chrome-proxy: frfr
Range: bytes=0-
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36
guid: 860409964
vkey: 9F1451C2E1D71EAB3A28FBB17FCCE9424C870E2945D4A4FDF156848EA8ECE8714F28D85512C0D1302410E2C051DBC0DBBD22BF489D67325E
uin: 2361
fromtag: 66
'''
def gen_headers(s):
ls = s.split('\n')
lsl = []
ls = ls[1:-1]
headers = {}
for l in ls:
l = l.split(': ')
lsl.append(l)
for x in lsl:
headers[str(x[0]).strip(' ')] = x[1]
return headers

 

headers=gen_headers(headers)
data={"comm":{"uin":"1026091321","ct":"24","cv":"0","gzip":"0","mcc":"460","mnc":"1"},"data_id":{"module":"track_info.UniformRuleCtrlServer","method":"GetTrackInfo","param":{"ids":[id],"types":[0]}}}
res=requests.post('https://u.y.qq.com/cgi-bin/musicu.fcg?g_tk=1111',json=data,headers=headers)
text=json.loads(res.text)
mid=text['data_id']['data']['tracks'][0]['mid']
mp3name=text['data_id']['data']['tracks'][0]['name']
mp3headers=gen_headers(mp3headers)
mp3url='https://u.y.qq.com/cgi-bin/musicu.fcg?-=getplaysongvkey03622942490798797&g_tk=231911714&loginUin=1026091321&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0&data={"req":{"module":"CDN.SrfCdnDispatchServer","method":"GetCdnDispatch","param":{"guid":"860409964","calltype":0,"userip":""}},"req_0":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"860409964","songmid":["'+mid+'"],"songtype":[0],"uin":"1026091321","loginflag":1,"platform":"20"}},"comm":{"uin":1026091321,"format":"json","ct":24,"cv":0}}'
mp3=requests.get(mp3url,headers=mp3headers)
text=json.loads(mp3.text)

downheader=gen_headers(downheader)

url='http://124.193.230.144/amobile.music.tc.qq.com/'+text['req_0']['data']['midurlinfo'][0]['purl']
mp3=requests.get(url,headers=downheader)
mp3=mp3.content
with open('./'+mp3name+'.mp3','wb') as f:
f.write(mp3)
f.close()

print(mp3name)

转载于:https://www.cnblogs.com/chengfengchi/p/10869249.html

你可能感兴趣的文章
graphviz入门
查看>>
JAVA编码(37)—— Java字符串转换为MAP对象
查看>>
jquery.validate.js 一个jQuery验证格式控件
查看>>
有表格的九九乘法表
查看>>
WPF 4 DataGrid 控件(自定义样式篇)
查看>>
改善C#程序的建议1:非用ICloneable不可的理由
查看>>
PHP的错误机制总结
查看>>
SharePoint 2013 工作流设计之Designer 使用“可视化视图”
查看>>
window.location
查看>>
C#实现万年历(农历、节气、节日、星座、星宿、属相、生肖、闰年月、时辰)
查看>>
使用Flex图表组件
查看>>
Windows Phone 8初学者开发—第6部分:设置应用程序的样式
查看>>
EmEditor Professional(文本编辑) 下载地址
查看>>
格式化数字串隔3个就断
查看>>
BUAA-OO-第二单元作业-电梯初体验
查看>>
CodeIgniter 目录结构详解
查看>>
跨子域的iframe高度自适应
查看>>
Redis配置文件详情
查看>>
Java语言基础—— 在控制台输入
查看>>
XMLHttpRequest之status
查看>>