最新公告
  • 欢迎您光临百元,本站秉承服务宗旨 履行“站长”责任,做国内最专业的站长资源平台!立即加入我们
  • 百元源码带酷狗音乐搜索版本 (源码附带ui打包)

    import requests,os
    import time,re
    import urllib.parse
    import tkinter as tk
    from tkinter import ttk
    from tkinter.filedialog import askdirectory
    import threading

    headers={
    “authority”: “www.kugou.com”,
    “method”: “GET”,
    “path”: “/yy/rank/home/1-6666.html?from=rank”,
    “scheme”: “https”,
    “accept”: “text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9”,
    “accept-encoding”: “gzip, deflate, br”,
    “accept-language”: “zh-CN,zh;q=0.9”,
    “cache-control”: “no-cache”,
    “cookie”: “kg_mid=628fb7a3fc8e7dab426f2846c32b409f; kg_dfid=3dpnap3DlhYI2QcUiN4BVBki; KuGooRandom=66411627561045001; kg_dfid_collect=d41d8cd98f00b204e9800998ecf8427e; Hm_lvt_aedee6983d4cfc62f509129360d6bb3d=1627561043,1627564661,1630060779,1630066172; ACK_SERVER_10016=%7B%22list%22%3A%5B%5B%22gzreg-user.kugou.com%22%5D%5D%7D; ACK_SERVER_10017=%7B%22list%22%3A%5B%5B%22gzverifycode.service.kugou.com%22%5D%5D%7D; ACK_SERVER_10015=%7B%22list%22%3A%5B%5B%22gzlogin-user.kugou.com%22%5D%5D%7D; kg_mid_temp=628fb7a3fc8e7dab426f2846c32b409f; Hm_lpvt_aedee6983d4cfc62f509129360d6bb3d=1630066414”,
    “pragma”: “no-cache”,
    ‘sec-ch-ua’: ‘” Not;A Brand”;v=”99″, “Google Chrome”;v=”91″, “Chromium”;v=”91″‘,
    “sec-ch-ua-mobile”: “?0”,
    “sec-fetch-dest”: “document”,
    “sec-fetch-mode”: “navigate”,
    “sec-fetch-site”: “none”,
    “sec-fetch-user”: “?1”,
    “upgrade-insecure-requests”: “1”,
    “user-agent”: “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36”,
    }

    def start_music():
    ui.t.delete(‘1.0’, ‘end’)
    name = ui.path1.get()
    ui.t.insert(‘insert’, “正在搜索歌曲:” + name)
    ui.t.insert(‘insert’, “\n”)
    name1 = urllib.parse.quote(name)
    t = int(time.time()*1000)
    url = f”http://songsearch.kugou.com/song_search_v2?callback=&keyword={name1}&page=1&pagesize=30&userid=-1&clientver=&platform=WebFilter&tag=em&filter=2&iscorrection=1&privilege_filter=0&_={t}”
    print(url)
    resp1 = html_respense(url)
    y=resp1.json()
    hashs = y[“data”][“lists”]
    hash=[hash[‘FileHash’] for hash in hashs]
    AlbumID=[hash[‘AlbumID’] for hash in hashs]
    FileName=[hash[‘FileName’] for hash in hashs]
    indexs=[]
    i=0
    for index in zip(hash,AlbumID,FileName):
    i+=1
    ui.t.insert(‘insert’, f”第{i}首 {index[2]}”)
    ui.t.insert(‘insert’, “\n”)
    ui.t.see(‘end’) #随着text的文本增加,焦点(光标),view始终在行尾
    indexs.append(index)
    return indexs

    # 请求函数
    def html_respense(url):
    for i in range(3):
    try:
    resp= requests.get(url,headers=headers,timeout=20)
    resp.encoding = ‘utf-8’
    if resp.status_code==200:
    return resp
    except:
    time.sleep(1)
    print(f”正在尝试重新请求第{i}次”)
    continue
    else:
    print(“请求失败,请检查”)

    #下载
    def music_down(indexs):
    title=ui.vv.get()
    print(title)
    if not os.path.exists(title):
    os.makedirs(title)
    down_fails = []
    for index in indexs:
    pattern = re.compile(r”[\/\\\:\*\?\”\<\>\|]”) # 文件名不能包括/\:*?<>”|
    songname = re.sub(pattern, “_”, index[2])
    print(songname)
    try:
    params = {
    “r”: “play/getdata”,
    “hash”: index[0],
    “dfid”: “3dpnap3DlhYI2QcUiN4BVBki”,
    “mid”: “628fb7a3fc8e7dab426f2846c32b409f”,
    “platid”: “4”,
    “album_id”: index[1],
    “_”: int(time.time() * 1000),
    }
    ui.t.insert(‘insert’, f”歌曲—-{index[2]}正在下载”)
    ui.t.insert(‘insert’, “\n”)
    resp_2 = requests.get(url=callback_url, headers=headers, params=params).json()
    music_down_url = resp_2[‘data’][‘play_url’]
    print(music_down_url)
    resp_3 = html_respense(music_down_url)
    path = title +”\\” + songname + “.mp3”
    with open(path, ‘wb’) as f:
    f.write(resp_3.content)
    print(songname, “下载完成”)
    ui.t.insert(‘insert’, f”歌曲{songname}下载完成”)
    ui.t.insert(‘insert’, “\n”)
    ui.t.see(‘end’)
    except Exception:
    down_fails.append(songname)
    ui.t.insert(‘insert’, f”歌曲{songname}下载失败”)
    ui.t.insert(‘insert’, “\n”)
    for root, dirs, files in os.walk(title):
    t = songname + “.mp3”
    for file in files:
    if file == t:
    os.remove(root + “\\” + t)
    print(t, “删除成功****************************************”)

    music_down_fails(down_fails)

    def music_down_fails(down_fails):
    ui.t.delete(‘1.0’, ‘end’)
    for songname in down_fails:
    ui.t.insert(‘insert’, f”歌曲{songname}下载失败”)
    ui.t.insert(‘insert’, “\n”)
    ui.t.see(‘end’)

    def main():
    ui.t.delete(‘1.0’, ‘end’)
    start = time.time()
    indexs = start_music()
    ui.t.delete(‘1.0’, ‘end’)
    thread = threading.Thread(target=music_down, args=(indexs,))
    thread.start()
    tim = time.time() – start
    tim = round(tim, 2)
    print(“一共耗时”, tim)
    ui.t.insert(‘insert’, f”一共耗时{tim}秒”)
    ui.t.insert(‘insert’, “\n”)
    ui.t.see(‘end’)

    class music_ui():
    def __init__(self,root):
    self.root =root
    self.vv=tk.StringVar()
    self.path1 = tk.StringVar()

    def ui_cuaw(self):
    # 标题
    self.root.title(“音乐下载2.0”)
    # 画布大小
    self.root.geometry(“600×480″)
    #标签
    tk.Label(self.root,text=”酷狗歌曲下载”,font=”楷体”).place(x=250,y=10)
    # 备注
    tk.Label(self.root, text=”可以搜索歌曲名或者歌手名支持模糊搜索”).place(x=40, y=30)
    #搜索按钮
    ttk.Button(self.root,text=”搜索”,command=start_music).place(x=40,y=50)
    #输入框
    ttk.Entry(self.root,width=60,textvariable=self.path1).place(x=140,y=52)
    #选择存放地址
    ttk.Button(self.root, text=”选择存放地址”,command=self.storage).place(x=40, y=80)
    ttk.Entry(self.root, width=60,textvariable=self.vv).place(x=140, y=82)
    #状态文本框
    tk.Label(self.root, text=”下载状态”).place(x=240, y=110)
    ttk.Button(self.root, text=”歌曲下载”,command=main).place(x=40, y=110)
    self.t=tk.Text(self.root, width=75,height=24)
    self.t.place(x=40, y=140)

    def storage(self):
    path = askdirectory()
    music_down_path=path.replace(“/”,”\\\\”)
    print(music_down_path)
    self.vv1= self.vv.set(music_down_path)

    if __name__ == ‘__main__’:
    callback_url = ‘https://wwwapi.kugou.com/yy/index.php?’
    #画布
    root= tk.Tk()
    #ui类
    ui = music_ui(root)
    ui.ui_cuaw()
    #循环
    root.mainloop()
    #++====代码优化 去除几个小bug =====

    百度网盘下载:https://pan.baidu.com/s/1c0xYh8G
    两种百度网盘选择方式下载
    链接: https://pan.baidu.com/s/1I2TNWbILhHL8W2uWRy5Ebw 提取码: 42ym

    1. 百元所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
    2. 分享目的仅供大家学习和交流,请不要用于商业用途!
    3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入!
    4. 百元提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
    5. 如有链接无法下载、失效或广告,请联系管理员处理!
    6. 百元资源售价只是赞助,收取费用仅维持本站的日常运营所需!
    7. 如遇到加密压缩包,默认解压密码为"dtmb.taobao.com",如遇到无法解压的请联系管理员!
    8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载
    声明如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性

    百元 » 百元源码带酷狗音乐搜索版本 (源码附带ui打包)

    常见问题FAQ

    免费下载或者VIP会员专享资源能否直接商用?
    本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
    提示下载完但解压或打开不了?
    最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。 若排除这种情况,可在对应资源底部留言,或 联络我们.。
    你们有qq群吗怎么加入?
    当然有的,如果你是帝国cms、易优cms、和pbootcms系统的爱好者你可以加入我们的QQ千人交流群http://www.100ix.com/page-qun.html。
    • 4025参与人数(人)
    • 131网站资源数(个)
    • 10本周更新(个)
    • 2 今日更新(个)
    • 630本站已经运行(天)

    提供最优质的资源集合

    加入VIP
    开通VIP 享更多特权,建议使用 QQ 登录