import requests
import json
import urllib
.request
headers
={'Host':'music.bbbbbb.me',
'User-Agent':'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0',
'Accept':'application/json, text/javascript, */*; q=0.01',
'Accept-Language':'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
'Accept-Encoding':'gzip, deflate',
'Referer':'http://music.bbbbbb.me/',
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With':'XMLHttpRequest',
'Content-Length':'47',
'Connection':'keep-alive',
'Pragma':'no-cache',
'Cache-Control':'no-cache'}
def search_Music(mname
):
global headers
data
={'input':mname
,'filter':'name','type':'netease','page':'1'}
url
= 'http://music.bbbbbb.me/'
wbdata
= requests
.post
(url
,headers
=headers
,data
=data
).text
data
= json
.loads
(wbdata
)
return data
def ShowList(data
):
i
=1
for n
in data
['data']:
author
= n
['author']
url
= n
['url']
print("编号:",i
,"歌手:",author
,"下载地址:",url
)
i
=i
+1
def DownLoad(data
,mname
,Number
):
try:
url
=data
['data'][Number
-1]['url']
singer
=data
['data'][Number
-1]['author']
base
="G:/3.Google网页下载文件存放处/音乐/歌曲/周杰伦/"
MusicName
=singer
+" - "+mname
+".mp3"
filepath
=base
+MusicName
urllib
.request
.urlretrieve
(url
,filepath
)
global SongName
SongName
.append
(MusicName
)
SongPath
.append
(filepath
)
filepath
print("下载完成")
return True
except:
print("下载失败")
return False
import tkinter
as tk
from tkinter
import *
import tkinter
.filedialog
import pygame
import os
from threading
import *
import threading
import time
from PIL
import ImageTk
, Image
import tkinter
.scrolledtext
import tkinter
.messagebox
import random
filePath
= 'G:\\3.Google网页下载文件存放处\音乐\歌曲\周杰伦\\'
SongName
=os
.listdir
(filePath
)
SongPath
=[filePath
+i
for i
in SongName
]
Number
=0
volume
=0.3
Switch
=True
def fun1():
global Number
Number
=Number
+1
if Number
>len(SongPath
)-1:
Number
=0
pygame
.mixer
.music
.load
(SongPath
[Number
])
pygame
.mixer
.music
.play
(0)
entry_var
.set(SongName
[Number
])
pass
def fun2():
global Number
global Switch
pygame
.mixer
.music
.set_volume
(volume
)
if Switch
==True:
pygame
.mixer
.music
.unpause
()
Switch
=False
else:
pygame
.mixer
.music
.pause
()
Switch
=True
pass
def fun3():
global Number
Number
=Number
-1
if Number
<0:
Number
=len(SongPath
)-1
pygame
.mixer
.music
.load
(SongPath
[Number
])
pygame
.mixer
.music
.play
(0)
entry_var
.set(SongName
[Number
])
pass
def fun4():
global volume
volume
+=0.1
if volume
>1:
volume
=1
pygame
.mixer
.music
.set_volume
(volume
)
def fun5():
global volume
volume
-=0.1
if volume
<0:
volume
=0
pygame
.mixer
.music
.set_volume
(volume
)
def Search():
txtCon
.delete
(0.0,tk
.END
)
mname
=en3
.get
()
if mname
!="":
data
=search_Music
(mname
)
i
=1
for n
in data
['data']:
author
= n
['author']
content
="编号:"+str(i
)+"歌手:"+author
+"\n"
txtCon
.insert
(tkinter
.INSERT
,content
)
i
=i
+1
def DownLoad_music():
mname
=en3
.get
()
Number
=int(en4
.get
())
data
=search_Music
(mname
)
ShowList
(data
)
boolean
=DownLoad
(data
,mname
,Number
)
if boolean
==True:
tk
.messagebox
.showinfo
(message
="下载成功")
else:
tk
.messagebox
.showerror
(message
="下载失败")
def os(time
) :
if time
<10:
return "0"+str(time
)
else:
return str(time
)
def clock(seconds
):
if seconds
>=60:
minutes
=seconds
//60
seconds
=seconds
-minutes
*60
return os
(minutes
)+":"+os
(seconds
)
else:
return "00:"+os
(seconds
)
class Current_time(threading
.Thread
):
def __init__(self
):
threading
.Thread
.__init__
(self
)
pass
def clock(seconds
):
if seconds
>=60:
minutes
=seconds
//60
seconds
=seconds
-minutes
*60
return os
(minutes
)+":"+os
(seconds
)
else:
return "00:"+os
(seconds
)
def run(self
):
while 1:
playtime
=pygame
.mixer
.music
.get_pos
()
seconds
=int(playtime
)//1000
current_time
=clock
(seconds
)
entry_var1
.set(current_time
)
time
.sleep
(1)
root
=tk
.Tk
()
root
.title
('音乐播放器')
root
["height"]=400
root
["width"]=300
root
.resizable
(0,0)
lal
=tk
.Label
(root
,text
="欢迎使用音乐播放器")
lal
.place
(x
=50,y
=15,width
=200,height
=50)
entry_var
= tk
.StringVar
()
entry_var
.set('欢迎使用')
en1
=tk
.Entry
(root
,textvariable
=entry_var
,justify
=CENTER
,state
=NORMAL
)
en1
.place
(x
=50,y
=70,width
=200,height
=15)
entry_var1
= tk
.StringVar
()
entry_var1
.set('00:00')
en2
=tk
.Entry
(root
,textvariable
=entry_var1
,justify
=CENTER
)
en2
.place
(x
=10,y
=5,width
=80,height
=15)
b3
=tk
.Button
(root
,text
="+",command
=fun4
)
b3
.place
(x
=50,y
=90)
b3
=tk
.Button
(root
,text
="-",command
=fun5
)
b3
.place
(x
=65,y
=90)
b1
=tk
.Button
(root
,text
="上一曲",command
=fun1
)
b1
.place
(x
=80,y
=90)
b1
=tk
.Button
(root
,text
="播放|暂停",command
=fun2
)
b1
.place
(x
=130,y
=90)
b3
=tk
.Button
(root
,text
="下一曲",command
=fun3
)
b3
.place
(x
=195,y
=90)
en3
=tk
.Entry
(root
,justify
=CENTER
,state
=NORMAL
)
en3
.place
(x
=50,y
=150,width
=80,height
=30)
b1
=tk
.Button
(root
,text
="搜索",command
=Search
)
b1
.place
(x
=135,y
=150)
en4
=tk
.Entry
(root
,justify
=CENTER
,state
=NORMAL
)
en4
.place
(x
=180,y
=150,width
=30,height
=30)
b1
=tk
.Button
(root
,text
="下载",command
=DownLoad_music
)
b1
.place
(x
=220,y
=150)
txtCon
=tk
.scrolledtext
.ScrolledText
(root
,wrap
=tk
.WORD
)
txtCon
.place
(x
=50,y
=200,width
=210,height
=150)
pygame
.mixer
.init
()
t
=Current_time
()
t
.start
()
root
.mainloop
()
转载请注明原文地址: https://mac.8miu.com/read-497173.html