python实现音乐下载器
本文实例为大家分享了python音乐下载器的具体代码,供大家参考,具体内容如下
import requests import urllib import json from tkinter import * import tkinter.messagebox from tkinter.filedialog import askdirectory class QQMusic(): def __init__(self): self.interface = Tk() self.interface.title('QQ音乐下载器') self.SavePath = 'C:/Users' self.entry = None self.label = None def DownloadMusic(self): res1 = requests.get('https://c.y.qq.com/soso/fcgi-bin/client_search_cp?&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=1&n=20&w='+self.entry.get()) jm1 = json.loads(res1.text.strip('callback()[]'))['data']['song']['list'][0] mids=jm1['media_mid'] songmids=jm1['songmid'] songnames=jm1['songname'] singers=jm1['singer'][0]['name'] res2 = requests.get('https://c.y.qq.com/base/fcgi-bin/fcg_music_express_mobile3.fcg?&\ jsonpCallback=MusicJsonCallback&cid=205361747&songmid='+songmids+'&filename=C400'+mids+'.m4a&guid=6612300644') jm2 = json.loads(res2.text) vkey = jm2['data']['items'][0]['vkey'] srcs='http://dl.stream.qqmusic.qq.com/C400'+mids+'.m4a?vkey='+vkey+'&guid=6612300644&uin=0&fromtag=66' try: urllib.request.urlretrieve(srcs,self.SavePath+'/'+songnames+'-'+singers+'.mp3')#.m4a tkinter.messagebox.showinfo('完成','歌曲下载成功\n保存在'+self.SavePath) except: tkinter.messagebox.showerror('错误','下载出错,请重试!') def ChangePath(self): self.SavePath = askdirectory() self.label["text"] = self.SavePath def Run(self): button = Button(self.interface,text='下载歌曲',command = self.DownloadMusic) button.grid(row=0,column=1,padx=3,pady=2) self.entry = Entry(self.interface,width=30) self.entry.grid(row=0,column=0,padx=3,pady=2) button1 = Button(self.interface,text='保存位置',command = self.ChangePath) button1.grid(row=1,column=1,padx=3,pady=2) self.label = Label(self.interface,text=self.SavePath) self.label.grid(row=1,column=0,padx=3,pady=2) QQ = QQMusic() QQ.Run()
可以实现音乐的快速制定路径下载。
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16