diff options
| author | jvoisin | 2014-06-08 13:39:18 +0200 |
|---|---|---|
| committer | jvoisin | 2014-06-08 13:39:18 +0200 |
| commit | af36529554c39a2eefcc2c8723715e2d25b401b8 (patch) | |
| tree | f54b964520bab44d1dfac725086211eaf22d3763 /libmat/audio.py | |
| parent | ef5a32cfd3c0555ffe5ddf413eeaae61622ebb4b (diff) | |
Rename the MAT folder to libmat.
This commit fixes some issues for dump operating
systems who doesn't handle capitalization.
Diffstat (limited to 'libmat/audio.py')
| -rw-r--r-- | libmat/audio.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/libmat/audio.py b/libmat/audio.py new file mode 100644 index 0000000..dae9d75 --- /dev/null +++ b/libmat/audio.py | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | ''' Care about audio fileformat | ||
| 2 | ''' | ||
| 3 | |||
| 4 | try: | ||
| 5 | from mutagen.flac import FLAC | ||
| 6 | from mutagen.oggvorbis import OggVorbis | ||
| 7 | except ImportError: | ||
| 8 | pass | ||
| 9 | |||
| 10 | import parser | ||
| 11 | import mutagenstripper | ||
| 12 | |||
| 13 | |||
| 14 | class MpegAudioStripper(parser.GenericParser): | ||
| 15 | ''' Represent mpeg audio file (mp3, ...) | ||
| 16 | ''' | ||
| 17 | def _should_remove(self, field): | ||
| 18 | return field.name in ("id3v1", "id3v2") | ||
| 19 | |||
| 20 | |||
| 21 | class OggStripper(mutagenstripper.MutagenStripper): | ||
| 22 | ''' Represent an ogg vorbis file | ||
| 23 | ''' | ||
| 24 | def _create_mfile(self): | ||
| 25 | self.mfile = OggVorbis(self.filename) | ||
| 26 | |||
| 27 | |||
| 28 | class FlacStripper(mutagenstripper.MutagenStripper): | ||
| 29 | ''' Represent a Flac audio file | ||
| 30 | ''' | ||
| 31 | def _create_mfile(self): | ||
| 32 | self.mfile = FLAC(self.filename) | ||
| 33 | |||
| 34 | def remove_all(self): | ||
| 35 | ''' Remove the "metadata" block from the file | ||
| 36 | ''' | ||
| 37 | super(FlacStripper, self).remove_all() | ||
| 38 | self.mfile.clear_pictures() | ||
| 39 | self.mfile.save() | ||
| 40 | return True | ||
| 41 | |||
| 42 | def is_clean(self): | ||
| 43 | ''' Check if the "metadata" block is present in the file | ||
| 44 | ''' | ||
| 45 | return super(FlacStripper, self).is_clean() and not self.mfile.pictures | ||
| 46 | |||
| 47 | def get_meta(self): | ||
| 48 | ''' Return the content of the metadata block if present | ||
| 49 | ''' | ||
| 50 | metadata = super(FlacStripper, self).get_meta() | ||
| 51 | if self.mfile.pictures: | ||
| 52 | metadata['picture:'] = 'yes' | ||
| 53 | return metadata | ||
