summaryrefslogtreecommitdiff
path: root/MAT/audio.py
diff options
context:
space:
mode:
authorjvoisin2012-12-08 02:02:25 +0100
committerjvoisin2012-12-13 14:24:01 +0100
commitcbf8a2a65928694202e19b6bcf56ec84bcbf613c (patch)
treee106475b0d5c003505336b5ae6416e4508bb768b /MAT/audio.py
parent67d5c1fa6b9ab6e1e7328ee57b15d8e46526d72a (diff)
Reorganize source tree and files installation location, cleanup setup.py (Closes: #689409)
Diffstat (limited to 'MAT/audio.py')
-rw-r--r--MAT/audio.py100
1 files changed, 100 insertions, 0 deletions
diff --git a/MAT/audio.py b/MAT/audio.py
new file mode 100644
index 0000000..ed849ee
--- /dev/null
+++ b/MAT/audio.py
@@ -0,0 +1,100 @@
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 return True
39
40 def is_clean(self):
41 '''
42 Check if the "metadata" block is present in the file
43 '''
44 mfile = OggVorbis(self.filename)
45 if mfile.tags == []:
46 return True
47 else:
48 return False
49
50 def get_meta(self):
51 '''
52 Return the content of the metadata block if present
53 '''
54 metadata = {}
55 mfile = OggVorbis(self.filename)
56 for key, value in mfile.tags:
57 metadata[key] = value
58 return metadata
59
60
61class FlacStripper(parser.GenericParser):
62 '''
63 Represent a Flac audio file
64 '''
65 def remove_all(self):
66 '''
67 Remove the "metadata" block from the file
68 '''
69 if self.backup is True:
70 shutil.copy2(self.filename, self.output)
71 self.filename = self.output
72
73 mfile = FLAC(self.filename)
74 mfile.delete()
75 mfile.clear_pictures()
76 mfile.save()
77 return True
78
79 def is_clean(self):
80 '''
81 Check if the "metadata" block is present in the file
82 '''
83 mfile = FLAC(self.filename)
84 if mfile.tags is None and mfile.pictures == []:
85 return True
86 else:
87 return False
88
89 def get_meta(self):
90 '''
91 Return the content of the metadata block if present
92 '''
93 metadata = {}
94 mfile = FLAC(self.filename)
95 if mfile.tags is not None:
96 if mfile.pictures != []:
97 metadata['picture :'] = 'yes'
98 for key, value in mfile.tags:
99 metadata[key] = value
100 return metadata