~andrewsomething/exaile/karmic

« back to all changes in this revision

Viewing changes to xl/metadata/_id3.py

  • Committer: Aren Olson
  • Date: 2009-09-12 00:36:59 UTC
  • Revision ID: reacocard@gmail.com-20090912003659-w373sg0n04uoa8op
remove useless files, add soem of the fixes from lp bug 420019

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2009 Adam Olsen
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2, or (at your option)
6
 
# any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 
 
17
 
from xl import common
18
 
from xl.metadata import BaseFormat
19
 
from mutagen import id3
20
 
 
21
 
import logging
22
 
logger = logging.getLogger(__name__)
23
 
 
24
 
 
25
 
class ID3Format(BaseFormat):
26
 
    MutagenType = id3.ID3
27
 
    tag_mapping = {
28
 
        "originalalbum": "TOAL",
29
 
        "lyricist": "TEXT",
30
 
        "part": "TSST",
31
 
        "website": "WOAR",
32
 
        "cover": "APIC",
33
 
        "originalartist": "TOPE",
34
 
        "author": "TOLY",
35
 
        "originaldate": "TDOR",
36
 
        "date": "TDRC",
37
 
        "arranger": "TPE4",
38
 
        "conductor": "TPE3",
39
 
        "performer": "TPE2",
40
 
        "artist": "TPE1",
41
 
        "album": "TALB",
42
 
        "copyright": "TCOP",
43
 
        "lyrics": "USLT",
44
 
        "tracknumber": "TRCK",
45
 
        "version": "TIT3",
46
 
        "title": "TIT2",
47
 
        "isrc": "TSRC",
48
 
        "genre": "TCON",
49
 
        "composer": "TCOM",
50
 
        "encodedby": "TENC",
51
 
        "organization": "TPUB",
52
 
        "discnumber": "TPOS",
53
 
        "bpm": "TBPM",
54
 
        }
55
 
    writable = True
56
 
 
57
 
    def _get_tag(self, raw, t):
58
 
        if not raw.tags: return []
59
 
        if t not in self.tag_mapping.itervalues():
60
 
            t = "TXXX:" + t
61
 
        field = raw.tags.getall(t)
62
 
        if len(field) <= 0:
63
 
            return []
64
 
        ret = []
65
 
        if t == 'TDRC' or t == 'TDOR': # values are ID3TimeStamps
66
 
            for value in field:
67
 
                ret.extend([unicode(x) for x in value.text])
68
 
        elif t == 'USLT': # Lyrics are stored in plain old strings
69
 
            for value in field:
70
 
                ret.append(unicode(value.text))
71
 
        elif t == 'WOAR': # URLS are stored in url not text
72
 
            for value in field:
73
 
                ret.extend([unicode(x.replace('\n','').replace('\r','')) \
74
 
                        for x in value.url])
75
 
        else:
76
 
            for value in field:
77
 
                try:
78
 
                    ret.extend([unicode(x.replace('\n','').replace('\r','')) \
79
 
                        for x in value.text])
80
 
                except:
81
 
                    logger.warning("Can't parse ID3 field")
82
 
                    common.log_exception(logger)
83
 
        return ret
84
 
 
85
 
    def _set_tag(self, raw, tag, data):
86
 
        if tag not in self.tag_mapping.itervalues():
87
 
            tag = "TXXX:" + tag
88
 
        if raw.tags is not None:
89
 
            raw.tags.delall(tag)
90
 
        frame = id3.Frames[tag](encoding=3, text=data)
91
 
        if raw.tags is not None:
92
 
            raw.tags.add(frame)
93
 
 
94
 
 
95
 
# vim: et sts=4 sw=4
96