-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsongs_manager.py
35 lines (29 loc) · 1013 Bytes
/
songs_manager.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
from mutagen import MutagenError
from mutagen.easyid3 import EasyID3
class Song:
def __init__(self, path):
self.path = path
self.name = path.split('/')[-1]
self.ext = self.name.split('.')[-1]
try:
if self.ext == 'mp3':
self.m = EasyID3(self.path)
self.status = True
else:
self.status = False
except MutagenError:
self.status = False
def __str__(self):
assert self, "File {} not found".format(self.path)
return "{} -> {}".format(self.name, self.m)
def __bool__(self):
return self.status
def update_genre(self, genre, over_write=False):
assert self, "File {} not found".format(self.path)
stop = False
if 'genre' in self.m:
if over_write is False:
stop = True
if self.status and not stop:
self.m['genre'] = genre
self.m.save()