import os
import tkinter as tk
import webbrowser
import requests
import tkinter.messagebox as mes_box
import PySimpleGUI as sg
from tkinter import ttk
from retrying import retry
class SetUI(object):
"""
音乐弹框界面
"""
def __init__(self, weight=1000, height=600):
self.ui_weight = weight
self.ui_height = height
self.title = " 音乐破解软件"
self.ui_root = tk.Tk(className=self.title)
self.ui_url = tk.StringVar()
self.ui_var = tk.IntVar()
self.ui_var.set(1)
self.show_result = None
self.song_num = None
self.response_data = None
self.song_url = None
self.song_name = None
self.song_author = None
def set_ui(self):
"""
设置简易UI界面
:return:
"""
# Frame空间
frame_1 = tk.Frame(self.ui_root)
frame_2 = tk.Frame(self.ui_root)
frame_3 = tk.Frame(self.ui_root)
frame_4 = tk.Frame(self.ui_root)
# ui界面中菜单设计
ui_menu = tk.Menu(self.ui_root)
self.ui_root.config(menu=ui_menu)
file_menu = tk.Menu(ui_menu, tearoff=0)
ui_menu.add_cascade(label='菜单', menu=file_menu)
file_menu.add_command(label='使用说明', command=lambda: webbrowser.open('www.baidu.com'))
file_menu.add_command(label='关于作者', command=lambda: webbrowser.open('www.baidu.com'))
file_menu.add_command(label='退出', command=self.ui_root.quit)
# 控件内容设置
choice_passageway = tk.Label(frame_1, text='请选择音乐搜索通道:', padx=10, pady=10)
passageway_button_1 = tk.Radiobutton(frame_1, text='酷我', variable=self.ui_var, value=1, width=10, height=3)
passageway_button_2 = tk.Radiobutton(frame_1, text='网易云', variable=self.ui_var, value=2, width=10, height=3)
passageway_button_3 = tk.Radiobutton(frame_1, text='QQ音乐', variable=self.ui_var, value=3, width=10, height=3)
passageway_button_4 = tk.Radiobutton(frame_1, text='酷狗', variable=self.ui_var, value=4, width=10, height=3)
input_link = tk.Label(frame_2, text="请输入歌曲名或歌手:")
entry_style = tk.Entry(frame_2, textvariable=self.ui_url, highlightcolor='Fuchsia', highlightthickness=1,
width=35)
label2 = tk.Label(frame_2, text=" ")
play_button = tk.Button(frame_2, text="搜索", font=('楷体', 11), fg='Purple', width=2, height=1,
command=self.get_KuWoMusic)
label3 = tk.Label(frame_2, text=" ")
# 表格样式
columns = ("序号", "歌手", "歌曲", "专辑")
self.show_result = ttk.Treeview(frame_3, height=20, show="headings", columns=columns)
# 下载
download_button = tk.Button(frame_4, text="下载", font=('楷体', 11), fg='Purple', width=6, height=1, padx=5,
pady=5, command=self.download_music)
# 控件布局
frame_1.pack()
frame_2.pack()
frame_3.pack()
frame_4.pack()
choice_passageway.grid(row=0, column=0)
passageway_button_1.grid(row=0, column=1)
passageway_button_2.grid(row=0, column=2)
passageway_button_3.grid(row=0, column=3)
passageway_button_4.grid(row=0, column=4)
input_link.grid(row=0, column=0)
entry_style.grid(row=0, column=1)
label2.grid(row=0, column=2)
play_button.grid(row=0, column=3, ipadx=10, ipady=10)
label3.grid(row=0, column=4)
self.show_result.grid(row=0, column=4)
download_button.grid(row=0, column=5)
# 设置表头
self.show_result.heading("序号", text="序号")
self.show_result.heading("歌手", text="歌手")
self.show_result.heading("歌曲", text="歌曲")
self.show_result.heading("专辑", text="专辑")
# 设置列
self.show_result.column("序号", width=100, anchor='center')
self.show_result.column("歌手", width=200, anchor='center')
self.show_result.column("歌曲", width=200, anchor='center')
self.show_result.column("专辑", width=300, anchor='center')
# 鼠标点击
self.show_result.bind('<ButtonRelease-1>', self.get_song_url)
@retry(stop_max_attempt_number=5)
def get_KuWoMusic(self):
"""
获取qq音乐
:return:
"""
# 清空treeview表格数据
for item in self.show_result.get_children():
self.show_result.delete(item)
headers = {
'accept': 'application/json, text/plain, */*',
'accept - encoding': 'gzip, deflate',
'accept - language': 'zh - CN, zh;q = 0.9',
'cache - control': 'no - cache',
'Connection': 'keep-alive',
'csrf': 'HH3GHIQ0RYM',
'Referer': 'http://www.kuwo.cn/search/list?key=%E5%91%A8%E6%9D%B0%E4%BC%A6',
'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/99.0.4844.51 Safari/537.36',
'Cookie': '_ga=GA1.2.218753071.1648798611; _gid=GA1.2.144187149.1648798611; _gat=1; '
'Hm_lvt_cdb524f42f0ce19b169a8071123a4797=1648798611; '
'Hm_lpvt_cdb524f42f0ce19b169a8071123a4797=1648798611; kw_token=HH3GHIQ0RYM'
}
search_input = self.ui_url.get()
if len(search_input) > 0:
search_url = 'http://www.kuwo.cn/api/www/search/searchMusicBykeyWord?'
search_data = {
'key': search_input,
'pn': '1',
'rn': '80',
'httpsStatus': '1',
'reqId': '858597c1-b18e-11ec-83e4-9d53d2ff08ff'
}
try:
self.response_data = requests.get(search_url, params=search_data, headers=headers, timeout=20).json()
songs_data = self.response_data['data']['list']
if int(self.response_data['data']['total']) <= 0:
mes_box.showerror(title='错误', message='搜索: {} 不存在.'.format(search_input))
else:
for i in range(len(songs_data)):
self.show_result.insert('', i, values=(i + 1, songs_data[i]['artist'], songs_data[i]['name'],
songs_data[i]['album']))
except TimeoutError:
mes_box.showerror(title='错误', message='搜索超时,请重新输入后再搜索!')
else:
mes_box.showerror(title='错误', message='未输入需查询的歌曲或歌手,请输入后搜索!')
def get_song_url(self, event):
"""
获取下载歌曲的地址
:return:
"""
# treeview中的左键单击
for item in self.show_result.selection():
item_text = self.show_result.item(item, "values")
# 获取
self.song_num = int(item_text[0])
# 获取下载歌曲的地址
if self.song_num is not None:
songs_data = self.response_data['data']['list']
songs_req_id = self.response_data['reqId']
song_rid = songs_data[self.song_num - 1]['rid']
music_url = 'http://www.kuwo.cn/api/v1/www/music/playUrl?mid={}&type=convert_url3' \
'&httpsStatus=1&reqId={}' \
.format(song_rid, songs_req_id)
response_data = requests.get(music_url).json()
self.song_url = response_data['data'].get('url')
self.song_name = songs_data[self.song_num - 1]['name']
self.song_author = songs_data[self.song_num - 1]['artist']
else:
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例获取歌曲python爬虫案例
资源推荐
资源详情
资源评论
收起资源包目录
爬取歌曲.zip (2个子文件)
这个文件夹可以使用 爬取音乐
1.py 5KB
music
这个文件夹里代码是B站视频展示代码,现已被修复不可用,可以查看学习
破解vip音乐.py 10KB
共 2 条
- 1
资源评论
晓枫-迷麟
- 粉丝: 123
- 资源: 76
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功