-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
325 lines (253 loc) · 11.8 KB
/
run.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/usr/bin/env python3
import os,sys
from Tagger import *
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtCore import pyqtSlot
from PyQt4 import QtCore, QtGui
class MainWindow(QtGui.QWidget):
def __init__(self):
super(MainWindow, self).__init__()
self.setGeometry(0, 0, 600, 700)
self.setWindowTitle('Welcome | MP3 Tagger')
# Opening Image
self.pic = QtGui.QLabel(self)
self.pic.setGeometry(50, 50, 500, 500)
self.pic.setPixmap(QtGui.QPixmap(os.getcwd() + "/earphones.jpg"))
# Enter Program Button
self.button = QPushButton('Click Here to Continue!', self)
self.button.resize(self.button.sizeHint())
self.button.move(220, 600)
self.button.clicked.connect(lambda: self.show_next_window())
# 'Welcome to MP3 Tagger' label
self.label = QLabel('Welcome', self)
self.label.resize(100, 30)
self.label.move(275, 100)
self.center()
def show_next_window(self):
self.close()
self._new_window = SongsWindow()
self._new_window.show()
def center(self):
frameGm = self.frameGeometry()
screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos())
centerPoint = QtGui.QApplication.desktop().screenGeometry(screen).center()
frameGm.moveCenter(centerPoint)
self.move(frameGm.topLeft())
class SongsWindow(QtGui.QMainWindow):
def __init__(self):
super(SongsWindow, self).__init__()
self._new_window = None
self.initUI()
self.setGeometry(0, 0, 1000, 700)
self.setWindowTitle('Song Information | MP3 Tagger')
self.center()
self.show()
def initUI(self):
songs = read_files_in_current_directory()
num_songs = 0
for song in songs:
num_songs = num_songs + 1
exec("self.track_name_label" + str(num_songs) + " = QtGui.QLabel('" + song + "', self)")
exec("self.track_label" + str(num_songs) + " = QtGui.QLabel('Track: ', self)")
exec("self.artist_label" + str(num_songs) + " = QtGui.QLabel('Artist: ', self)")
exec("self.track_box" + str(num_songs) + " = QtGui.QLineEdit(self)")
exec("self.artist_box" + str(num_songs) + " = QtGui.QLineEdit(self)")
exec("self.track_box" + str(num_songs) + ".resize(150, 40)")
exec("self.artist_box" + str(num_songs) + ".resize(150, 40)")
exec("self.track_name_label" + str(num_songs) + ".resize(200, 30)")
exec("self.track_label" + str(num_songs) + ".move(50," + str(num_songs) + "* 50)")
exec("self.track_box" + str(num_songs) + ".move(100," + str(num_songs) + "* 50)")
exec("self.artist_label" + str(num_songs) + ".move(275," + str(num_songs) + "* 50)")
exec("self.artist_box" + str(num_songs) + ".move(325," + str(num_songs) + "* 50)")
exec("self.track_name_label" + str(num_songs) + ".move(500," + str(num_songs) + "* 50)")
self.label = QLabel('Please enter the information.\nThen click submit.', self)
self.label.resize(500, 30)
self.label.move(50, (num_songs + 2) * 50)
self.button = QPushButton('Submit!', self)
self.button.resize(self.button.sizeHint())
self.button.move(50, (num_songs + 3) * 50)
self.button.clicked.connect(lambda: self.write_song_metadata())
def write_song_metadata(self):
self.splash_pix = QPixmap('earphones.jpg')
self.splash = QSplashScreen(self.splash_pix, Qt.WindowStaysOnTopHint)
self.progressBar = QProgressBar(self.splash)
self.progressBar.move(100, 400)
self.progressBar.resize(300, 30)
self.splash.setMask(self.splash_pix.mask())
self.splash.show()
songs = read_files_in_current_directory()
num_songs = 0
total_num_songs = len(songs)
for song in songs:
percent_done = round(num_songs / total_num_songs * 100)
self.progressBar.setValue(percent_done)
num_songs = num_songs + 1
exec("main_run('" + song + "', self.track_box" + str(num_songs) + ".text(), self.artist_box" + str(num_songs) + ".text())")
percent_done = round(num_songs / total_num_songs * 100)
self.progressBar.setValue(percent_done)
self.splash.hide()
self.show_next_window()
def show_next_window(self):
self.close()
self._new_window = PlaylistOptionWindow()
self._new_window.show()
def center(self):
frameGm = self.frameGeometry()
screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos())
centerPoint = QtGui.QApplication.desktop().screenGeometry(screen).center()
frameGm.moveCenter(centerPoint)
self.move(frameGm.topLeft())
class PlaylistOptionWindow(QtGui.QMainWindow):
def center(self):
frameGm = self.frameGeometry()
screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos())
centerPoint = QtGui.QApplication.desktop().screenGeometry(screen).center()
frameGm.moveCenter(centerPoint)
self.move(frameGm.topLeft())
def __init__(self):
super(PlaylistOptionWindow, self).__init__()
self._new_window = None
self.setGeometry(0, 0, 600, 200)
self.setWindowTitle('Select Playlist Type | MP3 Tagger')
self.label = QLabel('Successfully fetched and wrote metadata!\nChoose one of the following options.\n\n'
+ 'Click "Automatic" to create playlists by Genre, Artist, Album, and Year.\n'
+ 'Click "Custom" to create your own playlist.', self)
self.label.resize(500, 90)
self.label.move(50, 40)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.button = QPushButton('Automatic', self)
self.button.resize(self.button.sizeHint())
self.button.move(150, 150)
self.button.clicked.connect(lambda: self.automatic_playlist_option())
self.button = QPushButton('Custom', self)
self.button.resize(self.button.sizeHint())
self.button.move(350, 150)
self.button.clicked.connect(lambda: self.custom_playlist_option())
self.center()
self.show()
def automatic_playlist_option(self):
self.close()
self._new_window = AutomaticPlaylist()
self._new_window.show()
def custom_playlist_option(self):
self.close()
self._new_window = ManualPlaylist()
self._new_window.show()
class AutomaticPlaylist(QtGui.QMainWindow):
def __init__(self):
super(AutomaticPlaylist, self).__init__()
self._new_window = None
self.setGeometry(0, 0, 600, 200)
self.setWindowTitle('Automatic Playlist | MP3 Tagger')
self.label = QLabel('Choose an option to create your playlists.', self)
self.label.resize(500, 50)
self.label.move(50, 50)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.artist = QRadioButton("Artist", self)
self.album = QRadioButton("Album", self)
self.genre = QRadioButton("Genre", self)
self.year = QRadioButton("Year", self)
# self.b1.toggled.connect(lambda:self.btnstate(self.b1))
self.artist.move(100, 100)
self.album.move(200, 100)
self.genre.move(300, 100)
self.year.move(400, 100)
self.artist.setChecked(True)
self.button = QPushButton('Submit', self)
self.button.resize(self.button.sizeHint())
self.button.move(250, 150)
self.button.clicked.connect(lambda: self.automatic_playlist_option())
self.center()
self.show()
def automatic_playlist_option(self):
playlist_specifier = "Artist"
if self.artist.isChecked():
playlist_specifier = "Artist"
elif self.album.isChecked():
playlist_specifier = "Album"
elif self.genre.isChecked():
playlist_specifier = "Genre"
elif self.year.isChecked():
playlist_specifier = "Year"
else:
playlist_specifier = "Artist"
generate_playlists(playlist_specifier)
QMessageBox.information(self, "Completed.", "Successfully generated playlists!\nGo to your directory to view.")
sys.exit()
def center(self):
frameGm = self.frameGeometry()
screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos())
centerPoint = QtGui.QApplication.desktop().screenGeometry(screen).center()
frameGm.moveCenter(centerPoint)
self.move(frameGm.topLeft())
class ManualPlaylist(QtGui.QMainWindow):
def __init__(self):
super(ManualPlaylist, self).__init__()
self._new_window = None
self.setGeometry(0, 0, 600, 700)
self.setWindowTitle('Custom Playlist | MP3 Tagger')
self.label = QLabel('Type the name of the playlist you would like to create,\nand select the songs you would like to add to it.\nThen press "Create".', self)
self.label.resize(500, 50)
self.label.move(50, 20)
self.playlist_name = QtGui.QLineEdit(self)
self.playlist_name.resize(150, 40)
self.playlist_name.move(50, 100)
height_level = self.initUI()
self.button = QPushButton('Submit', self)
self.button.resize(self.button.sizeHint())
self.button.move(250, height_level * 50)
self.button.clicked.connect(lambda: self.custom_playlist_option())
self.center()
self.show()
def initUI(self):
songs = read_files_in_current_directory()
num_songs = 0
for song in songs:
num_songs = num_songs + 1
exec("self.select_track" + str(num_songs) + " = QtGui.QCheckBox('" + song + "', self)")
exec("self.select_track" + str(num_songs) + ".move(50," + str(num_songs + 2) + "* 50)")
exec("self.select_track" + str(num_songs) + ".resize(300, 50)")
return num_songs + 4
def custom_playlist_option(self):
playlist_name = self.playlist_name.text()
if playlist_name is not '':
# Create directory if it doesn't exist
if not os.path.exists(playlist_name):
os.makedirs(playlist_name)
songs = read_files_in_current_directory()
song_number = 0
for filename in songs:
song_number = song_number + 1
self.is_checked = False
exec("self.is_checked = self.select_track" + str(song_number) + ".isChecked()")
if self.is_checked:
# The folder exists in the current directory.
# Move the MP3 file into that folder.
source = os.path.abspath(filename)
destination = os.getcwd() + "/" + playlist_name + "/" + filename
move(source, destination)
msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setText("Successfully generated playlist!\nWould you like to create another?")
msg.setWindowTitle("Completed Action")
msg.setStandardButtons(QMessageBox.No | QMessageBox.Yes)
if msg.exec_() == 16384:
# Again
self.close()
self._new_window = ManualPlaylist()
self._new_window.show()
else:
QMessageBox.information(self, "Completed", "Thank you for using MP3 Tagger!")
sys.exit()
def center(self):
frameGm = self.frameGeometry()
screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos())
centerPoint = QtGui.QApplication.desktop().screenGeometry(screen).center()
frameGm.moveCenter(centerPoint)
self.move(frameGm.topLeft())
if __name__=='__main__':
app = QtGui.QApplication(sys.argv)
main = MainWindow()
main.show()
sys.exit(app.exec_())