New Product -- 网易云下载播放器

昨天翻了下写过的博文,其中有一篇是写网易云直链的,看着看着,一个邪恶的想法油然而生……

“为何不做一个集合音乐下载和播放的小程序呢?以我的能力完全可以的啊!搞他。”

Niko贱贱的语言

于是开始搞了。

也没多久,一天一夜,搞定了。

下载的音乐会以歌曲id命名,放在文件目录,支持多文件下载(不是同时)。

看到没,下载完之后支持选择播放,但,凡事就怕但。
界面是在太 {丑} 好 {得} 看 {一} 了{批}!

没办法啊!Python语言没一个好看的UI界面,也可能有,我不会用,比如Pyqt5。
害,不多说了,多说无益,放源代码!

Github文件地址

源码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from tkinter.constants import LEFT, RIGHT
import requests
import tkinter
from tkinter import messagebox
import sys


def music_play():
import pygame

pygame.mixer.init()
pygame.mixer.music.load(str(id) + '.mp3')
pygame.mixer.music.play()


def get_link():
try:
text = entry.get()
lst = text.split('?')
str_lst = lst[1].split('=')[1]

link = 'https://music.163.com/song/media/outer/url?id=' + str_lst

global id
id = str(str_lst)

return link, id

except Exception as error:
error_s = 'ERROR:', str(error)
entry.delete(0, tkinter.END)
messagebox.showerror(error_s)


def get_song(link, id):
data = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'
}
resp = requests.get(link, data=data).content
with open('.\\' + id + '.mp3', 'wb') as s:
s.write(resp)

global result
result = messagebox.askyesno(title='是否播放?', message='下载完成,是否播放?')

if result:
music_play()

return True


def ex():
sys.exit(0)


def tkin_canvas():
global top
top = tkinter.Tk()
top.title('网易云音乐下载')

L1 = tkinter.Label(top, text='请输入歌曲网址:')

global entry
entry = tkinter.Entry(top)

button = tkinter.Button(top, text='下载', command=main)
button_exit = tkinter.Button(top, text='退出', command=ex)

L1.pack(side=LEFT)
button_exit.pack(side=RIGHT)
button.pack(side=RIGHT)
entry.pack(side=RIGHT)

top.mainloop()


def main():
print('System Starting......')
all = get_link()
link = all[0]
id = all[1]
chose = get_song(link, id)
print('All Done.')


if __name__ == '__main__':
tkin_canvas()

也没多少,80多行,轻轻松松。
搞完了这个,以后再来个进阶的,不断进步,积极进取!