-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsound.py
More file actions
66 lines (63 loc) · 1.84 KB
/
sound.py
File metadata and controls
66 lines (63 loc) · 1.84 KB
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
import os, pygame
from mutagen.flac import FLAC
from mutagen.mp3 import MP3
from mutagen.id3 import ID3, ID3NoHeaderError, TIT2, TALB, TPE1, TPE2, COMM, USLT, TCOM, TCON, TDRC
from mutagen.easyid3 import EasyID3
from mutagen import File
class Sound:
def __init__(self, sound):
self.sound = sound
if sound.endswith(".mp3"):
self.length = MP3(sound).info.length
else:
self.length = pygame.mixer.Sound(sound).get_length()
self.path, self.filename = os.path.split(sound)
try:
self.soundID3 = ID3(sound)
except ID3NoHeaderError:
self.soundID3 = ID3()
try:
self.title = str(self.soundID3["TIT2"])
except KeyError:
self.title = str(self.filename)
try:
self.album = str(self.soundID3["TALB"])
except KeyError:
self.album = ''
try:
self.band = str(self.soundID3["TPE2"])
except KeyError:
self.band = ''
try:
self.description = str(self.soundID3["COMM"])
except KeyError:
self.description = ''
try:
self.artist = str(self.soundID3["TPE1"])
except KeyError:
self.artist = ''
try:
self.composer = str(self.soundID3["TCOM"])
except KeyError:
self.composer = ''
try:
self.genre = str(self.soundID3["TCON"])
except KeyError:
self.genre = ''
try:
self.year = str(self.soundID3["TDRC"])
except KeyError:
self.year = ''
try:
self.track_number = str(self.soundID3["TRCK"])
except KeyError:
self.track_number = ''
try:
file = File(self.sound) # mutagen can automatically detect format and type of tags
self.album_art = str(file.tags['APIC:'].data) # access APIC frame and grab the image
print(self.album_art[-128:])
except:
self.album_art = False
self.infolayout = ' '+ self.title
def print_info(self):
print(self.soundID3)