1、PC web端api,获取低品质音乐
2、自建api,获取高品质无损音质
getReqid.js
function getReqid() {
var t, e, n
var r = [55, 72, 12, 64, 240, 191]
var o
var h = 0, d = 0;
var i = e && n || 0
, b = []
, f = (t = t || {}).node || r
, v = void 0 !== t.clockseq ? t.clockseq : o;
var y = void 0 !== t.msecs ? t.msecs : (new Date).getTime()
, w = void 0 !== t.nsecs ? t.nsecs : d + 1
, dt = y - h + (w - d) / 1e4;
if (dt < 0 && void 0 === t.clockseq && (v = v + 1 & 16383),
(dt < 0 || y > h) && void 0 === t.nsecs && (w = 0),
w >= 1e4)
throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
var x = (1e4 * (268435455 & (y += 122192928e5)) + w) % 4294967296;
b[i++] = x >>> 24 & 255,
b[i++] = x >>> 16 & 255,
b[i++] = x >>> 8 & 255,
b[i++] = 255 & x;
var _ = y / 4294967296 * 1e4 & 268435455;
b[i++] = _ >>> 8 & 255,
b[i++] = 255 & _,
b[i++] = _ >>> 24 & 15 | 16,
b[i++] = _ >>> 16 & 255,
b[i++] = v >>> 8 | 128,
b[i++] = 255 & v;
for (var A = 0; A < 6; ++A)
b[i + A] = f[A];
var t = b
for (var n = [], i = 0; i < 256; ++i)
n[i] = (i + 256).toString(16).substr(1);
var i = 0
, r = n;
return [r[t[i++]], r[t[i++]], r[t[i++]], r[t[i++]], "-", r[t[i++]], r[t[i++]], "-", r[t[i++]], r[t[i++]], "-", r[t[i++]], r[t[i++]], "-", r[t[i++]], r[t[i++]], r[t[i++]], r[t[i++]], r[t[i++]], r[t[i++]]].join("")
}
完整python代码:
自建API格式:
API:
http://api.null119.cn:6666
请求类型:Get
参数1:rid
(歌曲ID)
参数2:que
(指定品质[128,192,320,999])
# -*- coding: utf-8 -*-
# @Author: Null119
# @Desc: { 酷我高品质音乐搜索/下载 }
# @Date: 2022/03/12 10:56
import requests,execjs,random,jsonpath,re
from urllib.parse import quote
ctx = execjs.compile(open('./getReqid.js').read())
r=requests.session()
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
}
def getCsrf():
tmp=['0','1','2','3','4','5','6','7','8','9','A', 'B','C','D','E','F','G','H','I','J','K', 'L','M','N','O','P','Q','R','S','T','U', 'V','W','X','Y','Z']
rlist=random.choices(range(0, 35), k=10, weights=range(0, 35))
result=''
for i in rlist:
result+=tmp[i]
return result
def search(word):
csrf = getCsrf()
headers['Cookie'] = 'kw_token=' + csrf
headers['csrf']=csrf
eword=quote(word, 'utf-8')
headers['Referer']='http://www.kuwo.cn/search/list?key='+ eword
surl='http://www.kuwo.cn/api/www/search/searchMusicBykeyWord?key='+eword+'&pn=1&rn=10&httpsStatus=1&reqId='+getReq()
html=r.get(surl,headers=headers)
mname=jsonpath.jsonpath(html.json(),'$.data.list..name')
mrid = jsonpath.jsonpath(html.json(), '$.data.list..rid')
malb = jsonpath.jsonpath(html.json(), '$.data.list..album')
mart=jsonpath.jsonpath(html.json(), '$.data.list..artist')
tmp = []
for i in range(len(mrid)):
tmp.append([mname[i],mrid[i],mart[i],malb[i]])
return tmp
def getReq():
evstr = 'getReqid()'
return str(ctx.eval(evstr))
def main(typ):
sWord=input('输入歌曲名称:')
songList=search(sWord)
for i in range(len(songList)):
tmp='%d--【%s】--【%s】' % (i,songList[i][0],songList[i][2])
print(tmp)
id=input('输入要下载的歌曲ID:')
rid = songList[int(id)][1]
if typ==0:
url='http://www.kuwo.cn/api/v1/www/music/playUrl?mid='+str(rid)+'&type=music&httpsStatus=1&reqId='+getReq()
html=r.get(url,headers=headers)
if html.json()['code']==200:
print('下载地址:',html.json()['data']['url'])
else:
print('下载地址获取异常。')
else:
sq = input('选择音乐品质[0:128k 1:192k 2:320k 3:flac]:')
print('下载地址:',getDownurl(rid,sq))
def getDownurl(rid,que):
if int(que)==3:que = '999'
elif int(que)==2:que = '320'
elif int(que)==1:que = '192'
else:que = '128'
url='http://api.null119.cn:6666?rid='+str(rid)+'&que='+que
durl=requests.get(url).text
req=requests.get(durl).text
downurl = re.search('url=(.*?)\n',req).group(1)
return downurl
def musicDown(url):
pass
if __name__ == '__main__':
main(1)
本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习使用,请在下载后24小时内删除,严禁商用。若由于商用引起版权纠纷,一切责任均由使用者承担。
【注意:本站发布资源来源于网络搜集,均有较强时效性,请在下载前注意查看文章资源发布或更新时间,距离当前时间太久的资源不建议下载,特别是安卓专区相关资源,会有大概率失效无法使用】
评论(0)