首页 > 编程语言 >python学习记录:酷我音乐VIP付费歌曲下载工具源码

python学习记录:酷我音乐VIP付费歌曲下载工具源码

时间:2022-10-17 17:37:34浏览次数:61  
标签:下载工具 name artist python list url 源码 music data

 


酷我音乐VIP付费歌曲下载工具

import requests
import prettytable as pt
print('*******欢迎使用酷我音乐VIP付费歌曲下载工具**********')
print()
key=input('请输入你要搜索的歌手姓名:')
print('')
rn=input('请输入搜索的歌曲数量:')
headers={
'Cookie': '_ga=GA1.2.1300693071.1665231987; _gid=GA1.2.931129797.1665231987; _gat=1; Hm_lvt_cdb524f42f0ce19b169a8071123a4797=1665231987,1665238429; Hm_lpvt_cdb524f42f0ce19b169a8071123a4797=1665238429; kw_token=L88ZS2R48VP',
'csrf': 'L88ZS2R48VP',
'Host': 'www.kuwo.cn',
'Referer': 'http://www.kuwo.cn/search/list?key=%E5%91%A8%E6%B7%B1',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'
}
url=f'http://www.kuwo.cn/api/www/search/searchMusicBykeyWord?key={key}&pn=1&rn={rn}&httpsStatus=1&reqId=81636940-4713-11ed-b98d-5bfcdbde3710'
response=requests.get(url,headers=headers)
#print(response.text)
json_data=response.json()
tb=pt.PrettyTable()
count=0
info_list=[]
data_list=json_data['data']['list']
tb.field_names=['序号','歌曲名称','歌手名']
for data in data_list:
name=data['name']
artist=data['artist']
rid=data['rid']
info_url=f'http://www.kuwo.cn/api/v1/www/music/playUrl?mid={rid}&type=convert_url3&br=320kmp3'
tb.add_row([str(count),name,artist])
count=count+1
music_url=requests.get(info_url).json()['data']['url']
info_list.append([name,artist,music_url])
print(tb)
while True:
print()
index=int(input('请输入要下载的歌曲序号(-1退出):'))
if index==int('\n'):
break
name=info_list[index][0]
artist=info_list[index][1]
music_url=info_list[index][2]
music=requests.get(music_url).content
with open(f'歌曲目录/{name}-{artist}.mp3','wb') as file:
file.write(music)
print(f'歌曲{name}-{artist}.mp3已下载成功!')

标签:下载工具,name,artist,python,list,url,源码,music,data
From: https://www.cnblogs.com/qlsh/p/16799947.html

相关文章