summaryrefslogtreecommitdiff
path: root/lib/audio.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/audio.py')
-rw-r--r--lib/audio.py98
1 files changed, 0 insertions, 98 deletions
diff --git a/lib/audio.py b/lib/audio.py
deleted file mode 100644
index 18daa7e..0000000
--- a/lib/audio.py
+++ /dev/null
@@ -1,98 +0,0 @@
1'''
2 Care about audio fileformat
3'''
4try:
5 from mutagen.flac import FLAC
6 from mutagen.oggvorbis import OggVorbis
7except ImportError:
8 pass
9
10
11import parser
12import shutil
13
14
15class MpegAudioStripper(parser.GenericParser):
16 '''
17 Represent mpeg audio file (mp3, ...)
18 '''
19 def _should_remove(self, field):
20 if field.name in ("id3v1", "id3v2"):
21 return True
22 else:
23 return False
24
25
26class OggStripper(parser.GenericParser):
27 '''
28 Represent an ogg vorbis file
29 '''
30 def remove_all(self):
31 if self.backup is True:
32 shutil.copy2(self.filename, self.output)
33 self.filename = self.output
34
35 mfile = OggVorbis(self.filename)
36 mfile.delete()
37 mfile.save()
38
39 def is_clean(self):
40 '''
41 Check if the "metadata" block is present in the file
42 '''
43 mfile = OggVorbis(self.filename)
44 if mfile.tags == []:
45 return True
46 else:
47 return False
48
49 def get_meta(self):
50 '''
51 Return the content of the metadata block if present
52 '''
53 metadata = {}
54 mfile = OggVorbis(self.filename)
55 for key, value in mfile.tags:
56 metadata[key] = value
57 return metadata
58
59
60class FlacStripper(parser.GenericParser):
61 '''
62 Represent a Flac audio file
63 '''
64 def remove_all(self):
65 '''
66 Remove the "metadata" block from the file
67 '''
68 if self.backup is True:
69 shutil.copy2(self.filename, self.output)
70 self.filename = self.output
71
72 mfile = FLAC(self.filename)
73 mfile.delete()
74 mfile.clear_pictures()
75 mfile.save()
76
77 def is_clean(self):
78 '''
79 Check if the "metadata" block is present in the file
80 '''
81 mfile = FLAC(self.filename)
82 if mfile.tags is None and mfile.pictures == []:
83 return True
84 else:
85 return False
86
87 def get_meta(self):
88 '''
89 Return the content of the metadata block if present
90 '''
91 metadata = {}
92 mfile = FLAC(self.filename)
93 if mfile.tags is not None:
94 for key, value in mfile.tags:
95 metadata[key] = value
96 if mfile.pictures != []:
97 metadata['picture :'] = 'yes'
98 return metadata