python实现音乐下载器
作者:河间老王
这篇文章主要为大家详细介绍了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()
可以实现音乐的快速制定路径下载。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。