这篇文章将为大家详细讲解有关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()
可以实现音乐的快速制定路径下载。
关于“python怎么实现音乐下载器”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。