summaryrefslogtreecommitdiff
path: root/src/audio.py
blob: 4da298c32c70c46fa84ed36b2f79b5d5bbe1d6d8 (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
import subprocess
import shutil
import json

import mutagen

from . import abstract

class MutagenParser(abstract.AbstractParser):
    def get_meta(self):
        f = mutagen.File(self.filename)
        if f.tags:
            return f.tags
        return {}

    def remove_all(self):
        shutil.copy(self.filename, self.output_filename)
        f = mutagen.File(self.output_filename)
        f.delete()
        f.save()
        return True

class MP3Parser(MutagenParser):
    mimetypes = {'audio/mpeg', }

    def get_meta(self):
        meta = super().get_meta()
        metadata = {}
        for key in meta:
            metadata[key] = meta[key].text
        return metadata

class OGGParser(MutagenParser):
    mimetypes = {'audio/ogg', }

class FLACParser(MutagenParser):
    mimetypes = {'audio/flac', }