blob: ed849ee2a85d3ab2808a9156d12c3aeb0f0732e4 (
plain)
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
|
'''
Care about audio fileformat
'''
try:
from mutagen.flac import FLAC
from mutagen.oggvorbis import OggVorbis
except ImportError:
pass
import parser
import shutil
class MpegAudioStripper(parser.GenericParser):
'''
Represent mpeg audio file (mp3, ...)
'''
def _should_remove(self, field):
if field.name in ("id3v1", "id3v2"):
return True
else:
return False
class OggStripper(parser.GenericParser):
'''
Represent an ogg vorbis file
'''
def remove_all(self):
if self.backup is True:
shutil.copy2(self.filename, self.output)
self.filename = self.output
mfile = OggVorbis(self.filename)
mfile.delete()
mfile.save()
return True
def is_clean(self):
'''
Check if the "metadata" block is present in the file
'''
mfile = OggVorbis(self.filename)
if mfile.tags == []:
return True
else:
return False
def get_meta(self):
'''
Return the content of the metadata block if present
'''
metadata = {}
mfile = OggVorbis(self.filename)
for key, value in mfile.tags:
metadata[key] = value
return metadata
class FlacStripper(parser.GenericParser):
'''
Represent a Flac audio file
'''
def remove_all(self):
'''
Remove the "metadata" block from the file
'''
if self.backup is True:
shutil.copy2(self.filename, self.output)
self.filename = self.output
mfile = FLAC(self.filename)
mfile.delete()
mfile.clear_pictures()
mfile.save()
return True
def is_clean(self):
'''
Check if the "metadata" block is present in the file
'''
mfile = FLAC(self.filename)
if mfile.tags is None and mfile.pictures == []:
return True
else:
return False
def get_meta(self):
'''
Return the content of the metadata block if present
'''
metadata = {}
mfile = FLAC(self.filename)
if mfile.tags is not None:
if mfile.pictures != []:
metadata['picture :'] = 'yes'
for key, value in mfile.tags:
metadata[key] = value
return metadata
|