From 340bc9b0054ecb3ae456e709c05d8f0a0d057dd9 Mon Sep 17 00:00:00 2001 From: Eric B Munson Date: Wed, 12 Jun 2024 09:03:42 -0400 Subject: [PATCH] Move 'starred' field to MediaBase The only class which inherits from MediaBase which -might- not have this field is Podcast Channel (known as 'podcasts' in the spec) and this response type is still marked TODO. We can refactor this field into derived classes if leaving it in MediaBase causes trouble. Signed-off-by: Eric B Munson --- .gitignore | 1 + CHANGELOG.md | 6 ++++++ setup.py | 3 ++- src/libopensonic/media/album.py | 3 --- src/libopensonic/media/artist.py | 5 +---- src/libopensonic/media/media_base.py | 13 +++++++++++-- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 029f8fc..e9a7711 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ MANIFEST dist build py_opensonic.egg-info +.vscode diff --git a/CHANGELOG.md b/CHANGELOG.md index cdd6031..ef72766 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +##5.1.0 + +Move the starred field up to MediaBase giving all media items the ability to be +starred. It is possible that Podcast Channels cannot be starred in the spec but this +should not cause serious issue. + ##5.0.5 Use more sane default values when getting a required key diff --git a/setup.py b/setup.py index 7b5cba3..68b60bc 100644 --- a/setup.py +++ b/setup.py @@ -57,7 +57,8 @@ install_requires=requirements, python_requires='>=3', classifiers=[ - 'Development Status :: 4 - Beta', + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', 'Intended Audience :: System Administrators', 'Intended Audience :: Information Technology', 'License :: OSI Approved :: GNU General Public License (GPL)', diff --git a/src/libopensonic/media/album.py b/src/libopensonic/media/album.py index 0426f1e..beaa996 100644 --- a/src/libopensonic/media/album.py +++ b/src/libopensonic/media/album.py @@ -48,7 +48,6 @@ def __init__(self, info): self._artist = get_key(info, 'artist') self._year = get_key(info, 'year') self._genre = get_key(info, 'genre') - self._starred = get_key(info, 'starred') self._played = get_key(info, 'played') self._user_rating = get_key(info, 'userRating') self._songs = [] @@ -71,7 +70,6 @@ def to_dict(self): ret['artist'] = self._artist ret['year'] = self._year ret['genre'] = self._genre - ret['starred'] = self._starred ret['played'] = self._played ret['userRating'] = self._user_rating ret['parent'] = self._parent @@ -85,7 +83,6 @@ def to_dict(self): is_dir = property(lambda s: s._is_dir) song_count = property(lambda s: s._song_count) created = property(lambda s: s._created) - starred = property(lambda s: s._starred) duration = property(lambda s: s._duration) play_count = property(lambda s: s._play_count) artist_id = property(lambda s: s._artist_id) diff --git a/src/libopensonic/media/artist.py b/src/libopensonic/media/artist.py index a2a7a4b..32f9c7f 100644 --- a/src/libopensonic/media/artist.py +++ b/src/libopensonic/media/artist.py @@ -66,11 +66,10 @@ def __init__(self, info): info:dict A dict from the JSON response to getArtist Must contain fields for MediaBase and 'name', - 'starred, 'albumCount', and 'album' though 'album' + 'albumCount', and 'album' though 'album' is a list and can be an empty one """ 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._info = None @@ -86,7 +85,6 @@ def __init__(self, info): def to_dict(self): ret = super().to_dict() ret['albumCount'] = self._album_count - ret['starred'] = self._starred ret['sortName'] = self._sort_name ret['name'] = self._name ret['artistImageUrl'] = self._artist_image_url @@ -100,7 +98,6 @@ def to_dict(self): album_count = property(lambda s: s._album_count) artist_image_url = property(lambda s: s._artist_image_url) - starred = property(lambda s: s._starred) name = property(lambda s: s._name) sort_name = property(lambda s: s._sort_name) albums = property(lambda s: s._albums) diff --git a/src/libopensonic/media/media_base.py b/src/libopensonic/media/media_base.py index 5e8c3a9..b300cdd 100644 --- a/src/libopensonic/media/media_base.py +++ b/src/libopensonic/media/media_base.py @@ -44,13 +44,18 @@ def __init__(self, info): (e.g. Songs, Albums, Artists, Podcasts, etc) info:dict A dict from the JSON response to any get request - Must contain fields 'id' and 'coverArt' + Must contain id field + May contain coverArt and starred field """ self._id = self.get_required_key(info, 'id') self._cover_id = get_key(info, 'coverArt') + self._starred = get_key(info, 'starred') def to_dict(self): - return {'id': self._id, 'coverId': self.cover_id} + """ + Return a dictonary representation of self. + """ + return {'id': self._id, 'coverId': self._cover_id, 'starred': self._starred} @classmethod def get_class_name(cls): @@ -58,8 +63,12 @@ def get_class_name(cls): id = property(lambda s: s._id) cover_id = property(lambda s: s._cover_id) + starred = property(lambda s: s._starred) def get_required_key(self, store, key, default=None): + """ + Used when parsing server returns for keys that are marked required by the specification. + """ if key in store: return store[key] warn(f"{self.get_class_name()} object returned by server is missing required field '{key}'")