forked from platypush/platypush
Include album_id and the list of tracks in music.tidal.get_album
This commit is contained in:
parent
c2a3f2f4f3
commit
09baceab4b
2 changed files with 26 additions and 3 deletions
|
@ -207,7 +207,7 @@ class MusicTidalPlugin(RunnablePlugin):
|
||||||
:return: .. schema:: tidal.TidalAlbumSchema
|
:return: .. schema:: tidal.TidalAlbumSchema
|
||||||
"""
|
"""
|
||||||
ret = self.session.album(album_id)
|
ret = self.session.album(album_id)
|
||||||
return TidalAlbumSchema().dump(ret)
|
return TidalAlbumSchema(with_tracks=True).dump(ret)
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def get_track(self, track_id: Union[str, int]):
|
def get_track(self, track_id: Union[str, int]):
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from marshmallow import Schema, fields, pre_dump
|
from marshmallow import Schema, fields, pre_dump, post_dump
|
||||||
|
|
||||||
from platypush.schemas import DateTime
|
from platypush.schemas import DateTime
|
||||||
|
|
||||||
|
@ -35,10 +35,13 @@ class TidalArtistSchema(TidalSchema):
|
||||||
|
|
||||||
|
|
||||||
class TidalAlbumSchema(TidalSchema):
|
class TidalAlbumSchema(TidalSchema):
|
||||||
|
def __init__(self, *args, with_tracks=False, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self._with_tracks = with_tracks
|
||||||
|
|
||||||
id = fields.String(
|
id = fields.String(
|
||||||
required=True,
|
required=True,
|
||||||
dump_only=True,
|
dump_only=True,
|
||||||
attribute='uuid',
|
|
||||||
metadata={
|
metadata={
|
||||||
'example': '45288612',
|
'example': '45288612',
|
||||||
'description': 'Album ID',
|
'description': 'Album ID',
|
||||||
|
@ -59,12 +62,32 @@ class TidalAlbumSchema(TidalSchema):
|
||||||
duration = fields.Int(metadata={'description': 'Album duration, in seconds'})
|
duration = fields.Int(metadata={'description': 'Album duration, in seconds'})
|
||||||
year = fields.Integer(metadata={'example': 2003})
|
year = fields.Integer(metadata={'example': 2003})
|
||||||
num_tracks = fields.Int(metadata={'example': 10})
|
num_tracks = fields.Int(metadata={'example': 10})
|
||||||
|
tracks = fields.List(fields.Dict(), attribute='_tracks')
|
||||||
|
|
||||||
@pre_dump
|
@pre_dump
|
||||||
def _prefill_url(self, data, *_, **__):
|
def _prefill_url(self, data, *_, **__):
|
||||||
data.url = f'https://tidal.com/album/{data.id}'
|
data.url = f'https://tidal.com/album/{data.id}'
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@pre_dump
|
||||||
|
def _cache_tracks(self, data, *_, **__):
|
||||||
|
if self._with_tracks:
|
||||||
|
album_id = str(data.id)
|
||||||
|
self.context[album_id] = {
|
||||||
|
'tracks': data.tracks(),
|
||||||
|
}
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
@post_dump
|
||||||
|
def _dump_tracks(self, data, *_, **__):
|
||||||
|
if self._with_tracks:
|
||||||
|
album_id = str(data['id'])
|
||||||
|
ctx = self.context.pop(album_id, {})
|
||||||
|
data['tracks'] = TidalTrackSchema().dump(ctx.pop('tracks', []), many=True)
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
class TidalTrackSchema(TidalSchema):
|
class TidalTrackSchema(TidalSchema):
|
||||||
id = fields.String(
|
id = fields.String(
|
||||||
|
|
Loading…
Reference in a new issue