summaryrefslogtreecommitdiff
path: root/src/parse_mp4.py
blob: 3e9233098b2ad8d3c7a22ed9a50fb5fa7df2fdb8 (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
from mutagen import mp4
from mutagen.easyid3 import EasyID3


class MP4Tags(mp4.MP4Tags):

    fields = {
        'cover': 'covr',
        'tempo': 'tmpo',
        'track_num': 'trkn',
        'disc_num': 'disk',
        'is_part_of_compilation': 'cpil',
        'is_part_of_gapless_album': 'pgap',
        'is_podcast': 'pcst',
        'track_title': '\xa9nam',
        'album': '\xa9alb',
        'artist': '\xa9ART',
        'album_artist': 'aART',
        'composer': '\xa9wrt',
        'year': '\xa9day',
        'comment': '\xa9cmt',
        'description': 'desc',
        'purchase_date': 'purd',
        'grouping': '\xa9grp',
        'genre': '\xa9gen',
        'lyrics': '\xa9lyr',
        'podcast_url': 'purl',
        'podcast_episode_id': 'egid',
        'podcast_category': 'catg',
        'podcast_keyword': 'keyw',
        'encoded_by': '\xa9too',
        'copyright': 'cprt',
        'sort_album': 'soal',
        'sort_album_artist': 'soaa',
        'sort_artist': 'soar',
        'sort_title': 'sonm',
        'sort_composer': 'soco',
        'sort_show': 'sosn',
        'tv_show_name': 'tvsh',
    }

    @property
    def track_number(self):
        return self.track_num[0]

    @property
    def total_tracks(self):
        return self.track_num[1]

    @property
    def disc_number(self):
        return self.disc_num[0]

    @property
    def total_discs(self):
        return self.disc_num[1]

    def __getattr__(self, attr):
        value = self[self.fields[attr]]
        if len(value) == 1:
            return value[0]
        else:
            return value


class MP4(mp4.MP4):
    MP4Tags = MP4Tags