Debian Codegraph @

xl/metadata/asf.py

raw
1 # Copyright (C) 2008-2010 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 #
18 # The developers of the Exaile media player hereby grant permission
19 # for non-GPL compatible GStreamer and Exaile plugins to be used and
20 # distributed together with GStreamer and Exaile. This permission is
21 # above and beyond the permissions granted by the GPL license by which
22 # Exaile is covered. If you modify this code, you may extend this
23 # exception to your version of the code, but you are not obligated to
24 # do so. If you do not wish to do so, delete this exception statement
25 # from your version.
26
27
28 from xl.metadata._base import BaseFormat
29 from mutagen import asf
30
31
32 class AsfFormat(BaseFormat):
33 MutagenType = asf.ASF
34 # TODO: figure out the the WM/ prefix is universal
35 tag_mapping = {
36 # fmt: off
37 "artist" : "Author",
38 "album" : "WM/AlbumTitle",
39 "title" : "Title",
40 "genre" : "WM/Genre",
41 "tracknumber" : "WM/TrackNumber",
42 "date" : "WM/Year",
43 "albumartist" : "WM/AlbumArtist",
44 "grouping" : "WM/ContentGroupDescription"
45 # fmt: on
46 }
47 others = False
48 writable = True
49
50 def _get_tag(self, raw, tag_name):
51 # the mutagen container for ASF returns the WM/ fields in its own
52 # wrappers which are *almost* like a string.. convert them to
53 # str so things don't break
54 tag = super(AsfFormat, self)._get_tag(raw, tag_name)
55 if isinstance(tag, list):
56 attrs = [
57 asf.ASFUnicodeAttribute,
58 asf.ASFDWordAttribute,
59 asf.ASFQWordAttribute,
60 asf.ASFWordAttribute,
61 ]
62
63 def __process_tag(any_tag):
64 for attrtype in attrs:
65 if isinstance(any_tag, attrtype):
66 return str(any_tag)
67 return any_tag
68
69 return [__process_tag(t) for t in tag]
70
71
72 # vim: et sts=4 sw=4