summaryrefslogtreecommitdiff
path: root/lib/audio.py
blob: 55562cc7c44659da76786ad202cfad402f4904a6 (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
'''
    Care about audio fileformat
'''
from mutagen.flac import FLAC

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 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.save()

    def is_clean(self):
        '''
            Check if the "metadata" block is present in the file
        '''
        mfile = FLAC(self.filename)
        if mfile.tags is None:
            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 None:
            return metadata
        for key, value in mfile.tags:
            metadata[key] = value
        return metadata