-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
197 lines (163 loc) · 5 KB
/
script.py
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import os
from tkinter.filedialog import askdirectory
import threading
try:
import pygame
from mutagen.id3 import ID3
except ImportError:
print("Trying to Install required module: requests\n")
os.system('python -m pip install pygame')
os.system('python -m pip install mutagen')
import pygame
from mutagen.id3 import ID3
from tkinter import *
root = Tk()
root.minsize(300, 300)
leftframe = Frame(root)
leftframe.grid(row=0,column=0, padx=10, pady=20)
rightframe = Frame(root)
rightframe.grid(row=0, column=1, padx=10, pady=20)
controlerframe = Frame(rightframe)
controlerframe.pack()
infoframe = Frame(rightframe)
infoframe.pack()
volumectroleframe = Frame(rightframe, height=2, bd=1, relief=GROOVE)
volumectroleframe.pack()
# variable declarion
listofsongs = []
realname = []
playsong = False
volumeValue = .30
v = StringVar()
songlabel = Label(infoframe, textvariable = v, width = 35)
index = 0
def playtrack():
global playsong, listofsongs, t1
if listofsongs:
if playsong == True:
pygame.mixer.music.pause()
playButton.config(image = playphoto)
playsong = False
else:
pygame.mixer.music.unpause()
playButton.config(image = pausephoto)
playsong = True
t1 = threading.Thread(target=loop)
t1.start()
def nextSong():
global index, listofsongs
if listofsongs:
# index += 1
# pygame.mixer.music.load(listofsongs[index])
# pygame.mixer.music.play()
# updatelabel()
if index != len(listofsongs) - 1:
index += 1
pygame.mixer.music.load(listofsongs[index])
pygame.mixer.music.play()
updatelabel()
else:
index = 0
pygame.mixer.music.load(listofsongs[0])
pygame.mixer.music.play()
updatelabel()
def prevsong():
global index, listofsongs
if listofsongs:
if index != 0:
index -= 1
pygame.mixer.music.load(listofsongs[index])
pygame.mixer.music.play()
updatelabel()
else:
index = len(listofsongs) - 1
pygame.mixer.music.load(listofsongs[index])
pygame.mixer.music.play()
updatelabel()
def stopsong():
global playsong
playsong = False
if playsong:
pygame.mixer.music.stop()
v.set("")
def volumecontroller(value):
global volumeValue, listofsongs
if listofsongs:
volumeValue = int(value) / 100
pygame.mixer.music.set_volume(volumeValue)
def updatelabel():
global index
# global songname
v.set(str(listofsongs[index]))
# Looping all song
import time
def loop():
global playsong, listofsongs
if listofsongs:
while playsong:
time.sleep(2)
if pygame.mixer.music.get_busy():
pass
else:
nextSong()
#declasre thread
def directoryChooser():
global playsong, listofsongs, volumeValue
listofsongs = []
directory = askdirectory()
if directory:
pass
else:
return
os.chdir(directory)
for files in os.listdir(directory):
if files.endswith(".mp3"):
realdir = os.path.realpath(files)
# audio = ID3(realdir)
# realname.append(audio["TIT2"].text[0])
listofsongs.append(files)
if listofsongs:
pygame.mixer.init()
pygame.mixer.music.load(listofsongs[index])
pygame.mixer.music.set_volume(volumeValue)
pygame.mixer.music.play()
updatelabel()
listofsongs.reverse()
for items in listofsongs:
listbox.insert(0, items)
listofsongs.reverse()
playButton.config(image = pausephoto)
playsong = True
vloume.set(30)
t1 = threading.Thread(target=loop)
t1.start()
# label = Label(root, text= "Music Player")
# label.pack()
# Listbox
listbox = Listbox(leftframe)
listbox.pack()
#UI
addButton = Button(leftframe, text="Add", command=directoryChooser)
addButton.pack()
prevphoto = PhotoImage(file="img/prev.png")
prevButton = Button(controlerframe, image = prevphoto, command = prevsong)
prevButton.pack(side=LEFT)
pausephoto = PhotoImage(file="img/pause.png")
playphoto = PhotoImage(file="img/play.png")
playButton = Button(controlerframe, image = playphoto, command=playtrack)
playButton.pack(side=LEFT)
nextphoto = PhotoImage(file="img/next.png")
nextButton = Button(controlerframe, image = nextphoto, command= nextSong)
nextButton.pack(side=RIGHT, pady=10)
speakerPhoto = PhotoImage(file="img/speaker.png")
speakerlabel = Label(volumectroleframe, image = speakerPhoto)
speakerlabel.grid(row=0, column=0)
vloume = Scale(volumectroleframe, from_ =0, to=100, orient=HORIZONTAL, command = volumecontroller)
vloume.grid(row=0, column=1)
songlabel.pack()
# Stop all loop after closing close button
def on_closing():
stopsong()
root.destroy()
root.protocol("WM_DELETE_WINDOW", on_closing)
root.mainloop()