diff options
| author | jvoisin | 2011-07-26 21:53:41 +0200 |
|---|---|---|
| committer | jvoisin | 2011-07-26 21:53:41 +0200 |
| commit | e239c9e1ded521acb8b025701bc3d3b5a6084e37 (patch) | |
| tree | eb73ca0ff9c837736a1918554bd502c8c8325828 /lib | |
| parent | c3ce1dd99ec1671d50a7cf89dc1b287fbbdf96aa (diff) | |
Add support for Flac fileformat
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/audio.py | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/lib/audio.py b/lib/audio.py index d146fad..55562cc 100644 --- a/lib/audio.py +++ b/lib/audio.py | |||
| @@ -1,9 +1,14 @@ | |||
| 1 | import parser | 1 | ''' |
| 2 | Care about audio fileformat | ||
| 3 | ''' | ||
| 4 | from mutagen.flac import FLAC | ||
| 2 | 5 | ||
| 6 | import parser | ||
| 7 | import shutil | ||
| 3 | 8 | ||
| 4 | class MpegAudioStripper(parser.GenericParser): | 9 | class MpegAudioStripper(parser.GenericParser): |
| 5 | ''' | 10 | ''' |
| 6 | mpeg audio file (mp3, ...) | 11 | Represent mpeg audio file (mp3, ...) |
| 7 | ''' | 12 | ''' |
| 8 | def _should_remove(self, field): | 13 | def _should_remove(self, field): |
| 9 | if field.name in ("id3v1", "id3v2"): | 14 | if field.name in ("id3v1", "id3v2"): |
| @@ -12,4 +17,39 @@ class MpegAudioStripper(parser.GenericParser): | |||
| 12 | return False | 17 | return False |
| 13 | 18 | ||
| 14 | class FlacStripper(parser.GenericParser): | 19 | class FlacStripper(parser.GenericParser): |
| 15 | pass | 20 | ''' |
| 21 | Represent a Flac audio file | ||
| 22 | ''' | ||
| 23 | def remove_all(self): | ||
| 24 | ''' | ||
| 25 | Remove the "metadata" block from the file | ||
| 26 | ''' | ||
| 27 | if self.backup is True: | ||
| 28 | shutil.copy2(self.filename, self.output) | ||
| 29 | self.filename = self.output | ||
| 30 | |||
| 31 | mfile = FLAC(self.filename) | ||
| 32 | mfile.delete() | ||
| 33 | mfile.save() | ||
| 34 | |||
| 35 | def is_clean(self): | ||
| 36 | ''' | ||
| 37 | Check if the "metadata" block is present in the file | ||
| 38 | ''' | ||
| 39 | mfile = FLAC(self.filename) | ||
| 40 | if mfile.tags is None: | ||
| 41 | return True | ||
| 42 | else: | ||
| 43 | return False | ||
| 44 | |||
| 45 | def get_meta(self): | ||
| 46 | ''' | ||
| 47 | Return the content of the metadata block if present | ||
| 48 | ''' | ||
| 49 | metadata = {} | ||
| 50 | mfile = FLAC(self.filename) | ||
| 51 | if mfile.tags is None: | ||
| 52 | return metadata | ||
| 53 | for key, value in mfile.tags: | ||
| 54 | metadata[key] = value | ||
| 55 | return metadata | ||
