好友
阅读权限25
听众
最后登录1970-1-1
|
厄斐琉斯
发表于 2020-12-1 16:11
代码开源:
import tkinter
from tkinter import *
from tkinter import ttk
import tkinter.messagebox, os, sys, requests, _thread, socket, struct, hashlib, json, webbrowser
RunPath = os.path.split(os.path.realpath(sys.argv[0]))[0] + '\\'
print(RunPath)
SavePath = RunPath + 'Downloads\\'
print(SavePath)
if os.path.exists(SavePath):
print('下载保存目录存在!')
else:
print('目录不存在')
try:
os.makedirs(SavePath)
print('目录创建成功。')
except:
print('目录创建失败,请尝试以管理员身份运行。')
else:
def encode_md5(str):
m = hashlib.md5()
m.update(str.encode('utf-8'))
result = m.hexdigest()
return result
def Update():
try:
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((SocketServerIP, SocketServerPort))
except:
tkinter.messagebox.showerror('Message', 'Network Connection Failed!')
webbrowser.open('http://www.8kvd.com/downloads/music/musicdownloadermini/')
exit()
else:
NowVersionNum = '1'
JSON = {'do':'update',
'by':'update',
'keywords':'1',
'key':encode_md5('update' + NowVersionNum + '_qq1070892573')}
hander_json = json.dumps(JSON)
hander_bytes = hander_json.encode('utf-8')
s_hander = struct.pack('i', len(hander_bytes))
client.send(s_hander)
client.send(hander_bytes)
s_hander = client.recv(4)
s_hander = struct.unpack('i', s_hander)[0]
b_hander = client.recv(s_hander)
json_hander = b_hander.decode('utf-8')
JSON = json.loads(json_hander)
try:
client.close()
except:
print('关闭连接失败。')
else:
if JSON['status']:
print('顺利通过更新')
else:
tkinter.messagebox.showinfo('Message', 'New Version Found!')
webbrowser.open('http://www.baidu.com')
exit()
SocketServerIP = 'musicdownloadermini.8kvd.com'
SocketServerPort = 11111
def delButton():
for item in ResultTable.get_children():
ResultTable.delete(item)
def Search():
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((SocketServerIP, SocketServerPort))
JSON = {'do':'search',
'by':Select.get(),
'keywords':SearchInput.get(),
'key':encode_md5(Select.get() + SearchInput.get() + '_qq1070892573')}
hander_json = json.dumps(JSON)
hander_bytes = hander_json.encode('utf-8')
s_hander = struct.pack('i', len(hander_bytes))
client.send(s_hander)
client.send(hander_bytes)
s_hander = client.recv(4)
s_hander = struct.unpack('i', s_hander)[0]
b_hander = client.recv(s_hander)
json_hander = b_hander.decode('utf-8')
JSON = json.loads(json_hander)
if JSON['status']:
delButton()
for x in range(0, len(JSON['data'])):
ResultTable.insert('', x, values=[JSON['data'][x]['ID'], JSON['data'][x]['Name'], JSON['data'][x]['Singer']])
else:
tkinter.messagebox.showerror('Message', 'Search Failed!')
try:
client.close()
except:
print('关闭连接失败。')
myWindow = Tk()
myWindow.title('Music Downloader Mini By 52Pojie')
width = 500
height = 300
myWindow.geometry(str(width) + 'x' + str(height))
myWindow.resizable(width=False, height=False)
screenwidth = myWindow.winfo_screenwidth()
screenheight = myWindow.winfo_screenheight()
alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
myWindow.geometry(alignstr)
Select = ttk.Combobox(myWindow, width=14, state='readonly')
Select['value'] = ('y.qq.com', 'music.163.com', 'kuwo.cn')
Select.current(0)
Select.pack()
Select.place(x=30, y=20)
SearchInput = Entry(myWindow, width=16, textvariable=StringVar(value=['AutumnBenBohmer']))
SearchInput.pack()
SearchInput.place(x=160, y=20)
SearchButton = Button(myWindow, text='Search', command=Search)
SearchButton.pack()
SearchButton.place(x=290, y=20)
def DownloadThread(filename, id):
if os.path.isfile(SavePath + filename):
tkinter.messagebox.showinfo('Message', 'The File Has Been Downloaded!\r\nClick Folder Button,Open The Downloads Folder.')
return False
else:
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((SocketServerIP, SocketServerPort))
JSON = {'do':'download',
'by':Select.get(),
'keywords':id,
'key':encode_md5(Select.get() + id + '_qq1070892573')}
hander_json = json.dumps(JSON)
hander_bytes = hander_json.encode('utf-8')
s_hander = struct.pack('i', len(hander_bytes))
client.send(s_hander)
client.send(hander_bytes)
s_hander = client.recv(4)
s_hander = struct.unpack('i', s_hander)[0]
b_hander = client.recv(s_hander)
json_hander = b_hander.decode('utf-8')
JSON = json.loads(json_hander)
if JSON['status']:
url = JSON['data']
r = requests.get(url)
with open(SavePath + filename, 'wb') as (f):
f.write(r.content)
else:
tkinter.messagebox.showerror('Message', 'Download Failed!')
client.close()
def Download():
if ResultTable.focus() == '':
tkinter.messagebox.showwarning('Message', 'Not Selected!')
else:
id = str(ResultTable.item(ResultTable.focus())['values'][0])
filename = str(ResultTable.item(ResultTable.focus())['values'][2]) + ' - ' + str(ResultTable.item(ResultTable.focus())['values'][1]) + '.mp3'
_thread.start_new_thread(DownloadThread, (filename, id))
def OpenFolder():
os.system('start explorer ' + SavePath)
SearchButton = Button(myWindow, text='Download', command=Download)
SearchButton.pack()
SearchButton.place(x=350, y=20)
SearchButton = Button(myWindow, text='Folder', command=OpenFolder)
SearchButton.pack()
SearchButton.place(x=430, y=20)
ResultTable = ttk.Treeview(myWindow, columns=('ID', 'Name', 'Singer'), show='headings', height=9, selectmode='browse')
ResultTable.column('ID', width=100, anchor='center')
ResultTable.column('Name', width=150, anchor='center')
ResultTable.column('Singer', width=150, anchor='center')
ResultTable.heading('ID', text='ID')
ResultTable.heading('Name', text='Name')
ResultTable.heading('Singer', text='Singer')
ResultTable.pack()
ResultTable.place(x=30, y=70)
tkinter.messagebox.showwarning('Message', '本工具仅供学习、交流测试使用,严禁任何人倒卖本程序!')
Update()
myWindow.mainloop()
|
免费评分
-
查看全部评分
|