吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 14932|回复: 101
收起左侧

[Python 原创] 图形版哇哈哈音乐下载器

  [复制链接]
w3812247 发表于 2023-2-24 09:30
昨天隔壁老王终于补全了自己的歌词,今天他又想要下载一些歌曲,但是在众多资源中找到想要的歌真的太麻烦了,于是老王又找到了我,我想起来前一阵我用坛友的源码,改过一个gui版的歌曲+歌词下载器,正好就给他用了,老王喜出望外,这下出差途中也不寂寞了,他还拜托我帮忙照顾一下王嫂,哎,真是一个劳碌命。
一般我搜索QQ的和酷我的资源相对能多些。搜索的话回车就可以搜索。
动画.gif

[Python] 纯文本查看 复制代码
# 导入模块

from tkinter import *
from tkinter.ttk import *
import requests
import jsonpath
import os
from urllib.request import urlretrieve
import tkinter.messagebox as msgbox
xz = ""


class WinGUI(Tk):

    def __init__(self):
        super().__init__()
        self.__win()
        self.tk_label_qsrgqm = self.__tk_label_qsrgqm()
        self.tk_input_inputgqm = self.__tk_input_inputgqm()
        self.tk_button_ss = self.__tk_button_ss()
        self.tk_radio_button_netease = self.__tk_radio_button_netease()
        self.tk_progressbar_xzjdt = self.__tk_progressbar_xzjdt()
        self.tk_radio_button_qq = self.__tk_radio_button_qq()
        self.tk_radio_button_kugou = self.__tk_radio_button_kugou()
        self.tk_radio_button_kuwo = self.__tk_radio_button_kuwo()
        self.tk_radio_button_baidu = self.__tk_radio_button_baidu()
        self.tk_radio_button_1ting = self.__tk_radio_button_1ting()
        self.tk_radio_button_lizhi = self.__tk_radio_button_lizhi()
        self.tk_radio_button_qingting = self.__tk_radio_button_qingting()
        self.tk_radio_button_ximalaya = self.__tk_radio_button_ximalaya()
        self.tk_radio_button_5singyc = self.__tk_radio_button_5singyc()
        self.tk_radio_button_5singfc = self.__tk_radio_button_5singfc()
        self.tk_radio_button_kg = self.__tk_radio_button_kg()
        self.tk_list_box_text = self.__tk_list_box_text()
        self.tk_label_xzjd = self.__tk_label_xzjd()
        self.tk_button_xz = self.__tk_button_xz()
        self.tk_radio_button_migu = self.__tk_radio_button_migu()


    def __win(self):
        self.title("全网歌曲下载")
        # 设置窗口大小、居中
        width = 600
        height = 500
        screenwidth = self.winfo_screenwidth()
        screenheight = self.winfo_screenheight()
        geometry = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
        self.geometry(geometry)
        self.resizable(width=False, height=False)
        global xz
        xz = StringVar()
        xz.set("qq")
    def __tk_label_qsrgqm(self):
        label = Label(self, text="请输入要下载的歌曲名")
        label.place(x=20, y=10, width=147, height=24)
        return label

    def __tk_input_inputgqm(self):
        ipt = Entry(self)
        ipt.place(x=180, y=10, width=312, height=24)
        return ipt

    def __tk_button_ss(self):
        btn = Button(self, text="搜索")
        btn.place(x=500, y=10, width=44, height=24)
        return btn



    def __tk_radio_button_netease(self):
        rb = Radiobutton(self, text="网易",variable=xz,value='netease')
        rb.place(x=20, y=50, width=60, height=24)
        return rb

    def __tk_progressbar_xzjdt(self):
        progressbar = Progressbar(self, orient=HORIZONTAL)
        progressbar.place(x=80, y=450, width=473, height=24)
        return progressbar

    def __tk_radio_button_qq(self):
        rb = Radiobutton(self, text="QQ",variable=xz,value='qq')
        rb.place(x=90, y=50, width=54, height=24)
        return rb

    def __tk_radio_button_kugou(self):
        rb = Radiobutton(self, text="酷狗",variable=xz,value='kugou')
        rb.place(x=150, y=50, width=61, height=24)
        return rb

    def __tk_radio_button_kuwo(self):
        rb = Radiobutton(self, text="酷我",variable=xz,value='kuwo')
        rb.place(x=220, y=50, width=57, height=24)
        return rb

    def __tk_radio_button_baidu(self):
        rb = Radiobutton(self, text="千千",variable=xz,value='baidu')
        rb.place(x=290, y=50, width=58, height=24)
        return rb

    def __tk_radio_button_1ting(self):
        rb = Radiobutton(self, text="一听",variable=xz,value='1ting')
        rb.place(x=360, y=50, width=61, height=24)
        return rb

    def __tk_radio_button_lizhi(self):
        rb = Radiobutton(self, text="荔枝",variable=xz,value='lizhi')
        rb.place(x=430, y=50, width=59, height=24)
        return rb

    def __tk_radio_button_qingting(self):
        rb = Radiobutton(self, text="蜻蜓",variable=xz,value='qingting')
        rb.place(x=500, y=50, width=65, height=24)
        return rb

    def __tk_radio_button_ximalaya(self):
        rb = Radiobutton(self, text="喜马拉雅",variable=xz,value='ximalaya')
        rb.place(x=20, y=90, width=96, height=24)
        return rb

    def __tk_radio_button_5singyc(self):
        rb = Radiobutton(self, text="5sing原创",variable=xz,value='5singyc')
        rb.place(x=130, y=90, width=99, height=24)
        return rb

    def __tk_radio_button_5singfc(self):
        rb = Radiobutton(self, text="5sing翻唱",variable=xz,value='5singfc')
        rb.place(x=240, y=90, width=99, height=24)
        return rb

    def __tk_radio_button_kg(self):
        rb = Radiobutton(self, text="全民K歌",variable=xz,value='kg')
        rb.place(x=350, y=90, width=99, height=24)
        return rb

    def __tk_list_box_text(self):
        lb = Listbox(self)
        lb.place(x=20, y=130, width=561, height=310)
        return lb

    def __tk_label_xzjd(self):
        label = Label(self, text="下载进度")
        label.place(x=10, y=450, width=59, height=24)
        return label

    def __tk_button_xz(self):
        btn = Button(self, text="下载")
        btn.place(x=550, y=10, width=43, height=24)
        return btn

    def __tk_radio_button_migu(self):
        rb = Radiobutton(self, text="咪咕",variable=xz,value='migu')
        rb.place(x=460, y=90, width=80, height=24)
        return rb


class Win(WinGUI):
    def __init__(self):
        super().__init__()
        self.__event_bind()
        self.bind('<Return>', self.get_music_name)
    # 2.功能实现""" 1.url 2.模拟浏览器请求 3.解析网页源代码 4.保存数据"""
    def cbk(self,a, b, c):
        '''回调函数
        @a:已经下载的数据块
        @b:数据块的大小
        @c:远程文件的大小
        '''
        per = 100.0 * a * b / c
        if per > 100:
            per = 100
        self.tk_progressbar_xzjdt['value'] =per
        self.tk_progressbar_xzjdt.update()
        print('%.2f%%' % per)

    def song_download(self,url, title, author, jlrc):
        # 创建文件夹

        self.tk_button_ss.configure(state='disabled')
        self.tk_button_xz.configure(state='disabled')

        os.makedirs("music", exist_ok=True)
        path = 'music\{}.mp3'.format(title)
        lrcpath = 'music\{}.lrc'.format(title)
        self.tk_list_box_text.insert(END, '歌曲:{0}-{1},正在下载...'.format(title, author))
        # 文本框滑动
        self.tk_list_box_text.see(END)
        # 更新
        self.tk_list_box_text.update()
        # 下载
        urlretrieve(url, path, self.cbk)
        if os.path.exists(lrcpath):  # 如果存在a/1.txt文件
            r = lrcpath
            file = open(r, 'a', encoding='utf-8')  # a表示在原有文档下继续编辑
            file.write(str(jlrc[0]))  # 在文件中写入loss: 2
            file.flush()
            file.close()
        else:
            # r为路径,'a\\1.txt','\\'与'/'一致,在os.path.join()函数中,
            # 每个逗号之间的元素都会被'\\'分开,无需添加分隔符
            r = lrcpath

            file = open(r, 'w', encoding='utf-8')  # w表示在重新创建文件
            file.write(str(jlrc[0]))  # 在文件中写入loss: 2
            file.flush()
            file.close()

        self.tk_list_box_text.insert(END, '下载完毕,{0}-{1},请试听'.format(title, author))
        # 文本框滑动
        self.tk_list_box_text.see(END)
        # 更新
        self.tk_list_box_text.update()
        self.tk_button_ss["state"] =  "enable"
        self.tk_button_xz["state"] = "enable"



    def down_music(self):
        """ 搜索歌曲名称 :return: """
        djg = self.tk_input_inputgqm.get()
        djg = int(djg) - 1
        name = self.tk_input_inputgqm.get()
        platfrom = WinGUI.xz.get()
        # name = '碧蓝的学姐与朱砂痣'
        url = 'https://music.liuzhijin.cn/'
        headers = {
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36",
            # 判断请求是异步还是同步
            "x-requested-with": "XMLHttpRequest", }
        param = {"input": name, "filter": "name", "type": platfrom, "page": 1, }
        res = requests.post(url=url, data=param, headers=headers)
        json_text = res.json()
        # print(res)
        title = jsonpath.jsonpath(json_text, '$..title')
        author = jsonpath.jsonpath(json_text, '$..author')
        url = jsonpath.jsonpath(json_text, '$..url')
        jlrc = jsonpath.jsonpath(json_text, '$..lrc')
        # print("jlrc",jlrc)
        # print("json_text", json_text)
        # print(url[djg], title[djg], author[djg],jlrc)
        self.song_download(url[djg], title[djg], author[djg], jlrc)
    def get_music_name(self, evt):
        """ 搜索歌曲名称 :return: """

        name = self.tk_input_inputgqm.get()
        platfrom = xz.get()
        self.tk_list_box_text.delete(0, END)
        if name=="" or platfrom=="":
            msgbox.showerror("完整性检测","请填写歌名或选择下载站点!")
        print(platfrom)
        # name = '碧蓝的学姐与朱砂痣'
        url = 'https://music.liuzhijin.cn/'
        headers = {
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36",
            # 判断请求是异步还是同步
            "x-requested-with": "XMLHttpRequest", }
        param = {"input": name, "filter": "name", "type": platfrom, "page": 1, }
        res = requests.post(url=url, data=param, headers=headers)
        json_text = res.json()
        title = jsonpath.jsonpath(json_text, '$..title')
        author = jsonpath.jsonpath(json_text, '$..author')
        url = jsonpath.jsonpath(json_text, '$..url')
        print(title, author, url)
        ii = 0
        for i in title:
            # 插入文本框
            strchuan = "第" + str(ii + 1) + "个---" + title[ii] + "  " + author[ii] + "  " + url[ii]
            self.tk_list_box_text.insert(END, strchuan.format(title, author))
            # 文本框滑动
            self.tk_list_box_text.see(END)
            # 更新
            self.tk_list_box_text.update()
            ii = ii + 1

    def downthis(self, evt):
        print("<Double-Button-1>事件未处理", evt)
        w = evt.widget
        print(w.index(w.curselection()))
        value = w.get(w.curselection())
        print(value)
        """ 搜索歌曲名称 :return: """
        djg = w.index(w.curselection())

        name = self.tk_input_inputgqm.get()
        platfrom = xz.get()
        # name = '碧蓝的学姐与朱砂痣'
        url = 'https://music.liuzhijin.cn/'
        headers = {
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36",
            # 判断请求是异步还是同步
            "x-requested-with": "XMLHttpRequest", }
        param = {"input": name, "filter": "name", "type": platfrom, "page": 1, }
        res = requests.post(url=url, data=param, headers=headers)
        json_text = res.json()
        # print(res)
        title = jsonpath.jsonpath(json_text, '$..title')
        author = jsonpath.jsonpath(json_text, '$..author')
        url = jsonpath.jsonpath(json_text, '$..url')
        jlrc = jsonpath.jsonpath(json_text, '$..lrc')
        # print("jlrc",jlrc)
        # print("json_text", json_text)
        # print(url[djg], title[djg], author[djg],jlrc)
        self.song_download(url[djg], title[djg], author[djg], jlrc)
    def __event_bind(self):
        self.tk_button_ss.bind('<Button>', self.get_music_name)

        self.tk_button_xz.bind('<Button>', self.xzan)
        self.tk_list_box_text.bind('<Double-Button-1>', self.downthis)
    def xzan(self,evt):
        print("下载啦")
        msgbox.showerror('错误提示', '直接双击具体的歌单信息即可下载!')

if __name__ == "__main__":
    win = Win()
    win.mainloop()

成品链接:https://wwox.lanzout.com/ix3kh0offtkj     密码:5qy9

免费评分

参与人数 23吾爱币 +29 热心值 +20 收起 理由
laochenren888 + 2 + 1 谢谢@Thanks!
peeppp + 1 试了,用不了,根本用不了2024.2.21
zr0081 + 1 + 1 我很赞同!
xyw930511 + 1 谢谢@Thanks!
zhangxiaofeng70 + 1 + 1 网易的挂了
gaoshizhe + 1 + 1 谢谢@Thanks!
shuai5995 + 1 用心讨论,共获提升!
春又来人已去 + 1 热心回复!
wangjt + 1 我很赞同!
sndncel + 1 + 1 进网站看了一下,发现酷狗通道已经挂了,其他的应该还可以用呀。
wzy_yang + 1 + 1 感谢您的宝贵建议,我们会努力争取做得更好!
junjia215 + 1 + 1 我很赞同!
安歌 + 1 + 1 我很赞同!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
Bob5230 + 1 + 1 谢谢@Thanks!
13066627762 + 2 + 1 &amp;amp;#128522;好活当赏
zzhaoxue + 1 + 1 热心回复!
whyzhhdo + 2 + 1 谢谢@Thanks!
chenxiran + 1 + 1 谢谢@Thanks!
山里红数码 + 1 + 1 用心讨论,共获提升!
jiyong1975 + 1 谢谢@Thanks!
冬天冷了多穿点 + 1 + 1 我很赞同!
山田凉粉 + 1 + 1 谢谢@Thanks!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

luwentao 发表于 2023-2-24 09:52
下载下来有问题,只有几K大小
dtadsl 发表于 2023-2-24 11:17
只能下载到mp3,很多歌曲搜不到原版,歌曲下载没有参数、封面,说实话,并不实用
飞杨先生 发表于 2023-2-24 09:38
wtz0027 发表于 2024-4-15 09:33
试了一下,用不了
flashtang 发表于 2023-2-25 10:01
我是菜鸡,看了半天没看到下载的文件保存在哪啊?
冬天冷了多穿点 发表于 2023-2-24 09:39
感谢楼主分享 试试
hwjsj00101 发表于 2023-2-24 09:45
软件我不知道咋样,这台词就很牛逼了。
jiyong1975 发表于 2023-2-24 09:45
已下!可以下载歌曲!棒棒的!预祝老王天天出差!
头像被屏蔽
mokson 发表于 2023-2-24 09:58
提示: 作者被禁止或删除 内容自动屏蔽
饮食协会 发表于 2023-2-24 10:16
这个经典 ,歌曲+歌词一起下来了,厉害
雾都孤尔 发表于 2023-2-24 10:18
学习下,好东西。感谢分享。
暗之守护 发表于 2023-2-24 10:50
感谢大佬,默认是下载320k音质的么
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-24 12:40

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表