arrange decode, set all attributes to be flexible
@@ -100,12 +100,7 @@ class AlbumInfo(Map):
``mediums`` along with the fields up through ``tracks`` are required.
The others are optional and may be None.
"""
- def __init__(self, album, album_id, artist, artist_id, tracks, **kwargs):
- self.album = album
- self.album_id = album_id
- self.artist = artist
- self.artist_id = artist_id
- self.tracks = tracks
+ def __init__(self, **kwargs):
for arg in kwargs:
self.__setattr__(arg, kwargs[arg])
@@ -116,20 +111,12 @@ class AlbumInfo(Map):
"""Ensure that all string attributes on this object, and the
constituent `TrackInfo` objects, are decoded to Unicode.
"""
- for fld in ['album', 'artist', 'albumtype', 'label', 'artist_sort',
- 'catalognum', 'script', 'language', 'country', 'style',
- 'genre', 'albumstatus', 'albumdisambig',
- 'releasegroupdisambig', 'artist_credit',
- 'media', 'discogs_albumid', 'discogs_labelid',
- 'discogs_artistid']:
+ for fld in self:
value = getattr(self, fld)
+ if type(value) == str:
if isinstance(value, bytes):
setattr(self, fld, value.decode(codec, 'ignore'))
- if self.tracks:
- for track in self.tracks:
- track.decode(codec)
-
class TrackInfo(Map):
"""Describes a canonical track present on a release. Appears as part
@@ -142,9 +129,7 @@ class TrackInfo(Map):
may be None. The indices ``index``, ``medium``, and ``medium_index``
are all 1-based.
"""
- def __init__(self, title, track_id, **kwargs):
- self.title = title
- self.track_id = track_id
+ def __init__(self, **kwargs):
for arg in kwargs:
self.__setattr__(arg, kwargs[arg])
@@ -153,9 +138,9 @@ class TrackInfo(Map):
"""Ensure that all string attributes on this object are decoded
to Unicode.
"""
- for fld in ['title', 'artist', 'medium', 'artist_sort', 'disctitle',
- 'artist_credit', 'media']:
+ for fld in self:
value = getattr(self, fld)
+ if type(value) == str:
if isinstance(value, bytes):
setattr(self, fld, value.decode(codec, 'ignore'))
