Skip to content

Commit

Permalink
Move 'starred' field to MediaBase
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
khers committed Jun 12, 2024
1 parent 6536f33 commit 340bc9b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ MANIFEST
dist
build
py_opensonic.egg-info
.vscode
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand Down
3 changes: 0 additions & 3 deletions src/libopensonic/media/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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
Expand All @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions src/libopensonic/media/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
13 changes: 11 additions & 2 deletions src/libopensonic/media/media_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,31 @@ 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):
return cls.__name__

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}'")
Expand Down

0 comments on commit 340bc9b

Please sign in to comment.