diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ad007c..cdd6031 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +##5.0.5 + +Use more sane default values when getting a required key + ##5.0.4 Convert getTopSongs, getSimilarSongs[2], and getNewestPodcasts to use media objects diff --git a/src/libopensonic/_version.py b/src/libopensonic/_version.py index e87e65f..3a009ae 100644 --- a/src/libopensonic/_version.py +++ b/src/libopensonic/_version.py @@ -17,4 +17,4 @@ #Semantic versioning string for the library -__version__ = '5.0.4' +__version__ = '5.0.5' diff --git a/src/libopensonic/media/album.py b/src/libopensonic/media/album.py index 154a173..0426f1e 100644 --- a/src/libopensonic/media/album.py +++ b/src/libopensonic/media/album.py @@ -38,11 +38,11 @@ class Album(MediaBase): def __init__(self, info): self._parent = get_key(info, 'parent') self._album = get_key(info, 'album') - self._name = self.get_required_key(info, 'name') + self._name = self.get_required_key(info, 'name', '') self._is_dir = get_key(info, 'isDir') - self._song_count = int(self.get_required_key(info, 'songCount')) + self._song_count = int(self.get_required_key(info, 'songCount', 0)) self._created = self.get_required_key(info, 'created') - self._duration = int(self.get_required_key(info, 'duration')) + self._duration = int(self.get_required_key(info, 'duration', 0)) self._play_count = get_key(info, 'playCount') self._artist_id = get_key(info, 'artistId') self._artist = get_key(info, 'artist') diff --git a/src/libopensonic/media/artist.py b/src/libopensonic/media/artist.py index 305af6a..a2a7a4b 100644 --- a/src/libopensonic/media/artist.py +++ b/src/libopensonic/media/artist.py @@ -71,8 +71,8 @@ def __init__(self, info): """ self._album_count = get_key(info, 'albumCount') self._starred = get_key(info, 'starred') - self._name = self.get_required_key(info, 'name') - self._sort_name = self.get_required_key(info, 'sortName') + self._name = self.get_required_key(info, 'name', '') + self._sort_name = self.get_required_key(info, 'sortName', '') self._info = None self._artist_image_url = get_key(info, 'artistImageUrl') self._sort_name = get_key(info, 'sortName') diff --git a/src/libopensonic/media/media_base.py b/src/libopensonic/media/media_base.py index a01d7c7..5e8c3a9 100644 --- a/src/libopensonic/media/media_base.py +++ b/src/libopensonic/media/media_base.py @@ -46,7 +46,7 @@ def __init__(self, info): info:dict A dict from the JSON response to any get request Must contain fields 'id' and 'coverArt' """ - self._id = self.get_required_key(info, 'id') + self._id = self.get_required_key(info, 'id') self._cover_id = get_key(info, 'coverArt') def to_dict(self): @@ -55,13 +55,12 @@ def to_dict(self): @classmethod def get_class_name(cls): return cls.__name__ - + id = property(lambda s: s._id) cover_id = property(lambda s: s._cover_id) - def get_required_key(self, store, key): + def get_required_key(self, store, key, default=None): if key in store: return store[key] warn(f"{self.get_class_name()} object returned by server is missing required field '{key}'") - return None - + return default diff --git a/src/libopensonic/media/playlist.py b/src/libopensonic/media/playlist.py index 74a706d..215ebb4 100644 --- a/src/libopensonic/media/playlist.py +++ b/src/libopensonic/media/playlist.py @@ -24,10 +24,10 @@ def __init__(self, info): self._comment = get_key(info, 'comment') self._owner = get_key(info, 'owner') self._public = get_key(info, 'public', False) - self._song_count = self.get_required_key(info, 'songCount') + self._song_count = self.get_required_key(info, 'songCount', 0) self._created = self.get_required_key(info,'created') self._changed = self.get_required_key(info, 'changed') - self._duration = self.get_required_key(info, 'duration') + self._duration = self.get_required_key(info, 'duration', 0) self._cover_id = get_key(info, 'coverArt') self._songs = [] if 'entry' in info and info['entry']: