Skip to content

Commit c9842fa

Browse files
authored
Support podcast in playlist (#419)
1 parent e995816 commit c9842fa

File tree

5 files changed

+1301
-6
lines changed

5 files changed

+1301
-6
lines changed

src/spotifyaio/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def __pre_deserialize__(cls, d: dict[str, Any]) -> dict[str, Any]:
404404
class PlaylistTrack(DataClassORJSONMixin):
405405
"""PlaylistTrack model."""
406406

407-
track: Track
407+
track: Annotated[Item, Discriminator(field="type", include_subtypes=True)] | None
408408

409409

410410
@dataclass

src/spotifyaio/spotify.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,9 @@ async def add_to_queue(self, uri: str, device_id: str | None = None) -> None:
424424
async def get_playlist(self, playlist_id: str) -> Playlist:
425425
"""Get playlist."""
426426
identifier = playlist_id.split(":")[-1]
427-
response = await self._get(f"v1/playlists/{identifier}")
427+
response = await self._get(
428+
f"v1/playlists/{identifier}", params={"additional_types": "track,episode"}
429+
)
428430
return Playlist.from_json(response)
429431

430432
# Update playlist details

tests/__snapshots__/test_spotify.ambr

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10003,6 +10003,218 @@
1000310003
'uri': 'spotify:playlist:3toMXYM91T55pKzuysH5Ph',
1000410004
})
1000510005
# ---
10006+
# name: test_get_playlist[playlist_3.json]
10007+
dict({
10008+
'collaborative': False,
10009+
'description': '',
10010+
'external_urls': dict({
10011+
'spotify': 'https://open.spotify.com/playlist/0pM0KTMXM7K5qr3sL2DPw1',
10012+
}),
10013+
'images': list([
10014+
dict({
10015+
'height': None,
10016+
'url': 'https://i.scdn.co/image/ab67616d00001e02991e1b6c088e2abc38f584c8',
10017+
'width': None,
10018+
}),
10019+
]),
10020+
'name': 'Pain',
10021+
'object_type': 'playlist',
10022+
'owner': dict({
10023+
'display_name': 'Joost Lekkerkerker',
10024+
'external_urls': dict({
10025+
'spotify': 'https://open.spotify.com/user/1112264649',
10026+
}),
10027+
'href': 'https://api.spotify.com/v1/users/1112264649',
10028+
'object_type': 'user',
10029+
'owner_id': '1112264649',
10030+
'uri': 'spotify:user:1112264649',
10031+
}),
10032+
'playlist_id': '0pM0KTMXM7K5qr3sL2DPw1',
10033+
'public': True,
10034+
'tracks': dict({
10035+
'items': list([
10036+
dict({
10037+
'track': dict({
10038+
'album': dict({
10039+
'album_id': '5iuJo58XqIENkyviBJ4dil',
10040+
'album_type': <AlbumType.SINGLE: 'single'>,
10041+
'artists': list([
10042+
dict({
10043+
'artist_id': '6DDZJCwSnNF361mUwPEm4G',
10044+
'name': 'Saint Nomad',
10045+
'uri': 'spotify:artist:6DDZJCwSnNF361mUwPEm4G',
10046+
}),
10047+
]),
10048+
'images': list([
10049+
dict({
10050+
'height': 640,
10051+
'url': 'https://i.scdn.co/image/ab67616d0000b273991e1b6c088e2abc38f584c8',
10052+
'width': 640,
10053+
}),
10054+
dict({
10055+
'height': 300,
10056+
'url': 'https://i.scdn.co/image/ab67616d00001e02991e1b6c088e2abc38f584c8',
10057+
'width': 300,
10058+
}),
10059+
dict({
10060+
'height': 64,
10061+
'url': 'https://i.scdn.co/image/ab67616d00004851991e1b6c088e2abc38f584c8',
10062+
'width': 64,
10063+
}),
10064+
]),
10065+
'name': 'Nothing To Lose',
10066+
'release_date': '2020-05-01',
10067+
'release_date_precision': <ReleaseDatePrecision.DAY: 'day'>,
10068+
'total_tracks': 1,
10069+
'uri': 'spotify:album:5iuJo58XqIENkyviBJ4dil',
10070+
}),
10071+
'artists': list([
10072+
dict({
10073+
'artist_id': '6DDZJCwSnNF361mUwPEm4G',
10074+
'name': 'Saint Nomad',
10075+
'uri': 'spotify:artist:6DDZJCwSnNF361mUwPEm4G',
10076+
}),
10077+
]),
10078+
'disc_number': 1,
10079+
'duration_ms': 164453,
10080+
'explicit': False,
10081+
'external_urls': dict({
10082+
'spotify': 'https://open.spotify.com/track/4bEdcyI0l4zX2Ut5m5Xrhw',
10083+
}),
10084+
'href': 'https://api.spotify.com/v1/tracks/4bEdcyI0l4zX2Ut5m5Xrhw',
10085+
'is_local': False,
10086+
'name': 'Nothing To Lose',
10087+
'track_id': '4bEdcyI0l4zX2Ut5m5Xrhw',
10088+
'track_number': 1,
10089+
'type': <ItemType.TRACK: 'track'>,
10090+
'uri': 'spotify:track:4bEdcyI0l4zX2Ut5m5Xrhw',
10091+
}),
10092+
}),
10093+
dict({
10094+
'track': dict({
10095+
'album': dict({
10096+
'album_id': '4stVgm9xx3cSNYddv8oTcL',
10097+
'album_type': <AlbumType.SINGLE: 'single'>,
10098+
'artists': list([
10099+
dict({
10100+
'artist_id': '6GFq3n0UYhpfzYPprpmD4K',
10101+
'name': 'Doko',
10102+
'uri': 'spotify:artist:6GFq3n0UYhpfzYPprpmD4K',
10103+
}),
10104+
]),
10105+
'images': list([
10106+
dict({
10107+
'height': 640,
10108+
'url': 'https://i.scdn.co/image/ab67616d0000b273a8f196ac6565b31a5b6689de',
10109+
'width': 640,
10110+
}),
10111+
dict({
10112+
'height': 300,
10113+
'url': 'https://i.scdn.co/image/ab67616d00001e02a8f196ac6565b31a5b6689de',
10114+
'width': 300,
10115+
}),
10116+
dict({
10117+
'height': 64,
10118+
'url': 'https://i.scdn.co/image/ab67616d00004851a8f196ac6565b31a5b6689de',
10119+
'width': 64,
10120+
}),
10121+
]),
10122+
'name': 'Borrowed Time',
10123+
'release_date': '2019-06-28',
10124+
'release_date_precision': <ReleaseDatePrecision.DAY: 'day'>,
10125+
'total_tracks': 1,
10126+
'uri': 'spotify:album:4stVgm9xx3cSNYddv8oTcL',
10127+
}),
10128+
'artists': list([
10129+
dict({
10130+
'artist_id': '6GFq3n0UYhpfzYPprpmD4K',
10131+
'name': 'Doko',
10132+
'uri': 'spotify:artist:6GFq3n0UYhpfzYPprpmD4K',
10133+
}),
10134+
]),
10135+
'disc_number': 1,
10136+
'duration_ms': 198022,
10137+
'explicit': False,
10138+
'external_urls': dict({
10139+
'spotify': 'https://open.spotify.com/track/2kmZop34md5KWP4gn7Zuj8',
10140+
}),
10141+
'href': 'https://api.spotify.com/v1/tracks/2kmZop34md5KWP4gn7Zuj8',
10142+
'is_local': False,
10143+
'name': 'Borrowed Time',
10144+
'track_id': '2kmZop34md5KWP4gn7Zuj8',
10145+
'track_number': 1,
10146+
'type': <ItemType.TRACK: 'track'>,
10147+
'uri': 'spotify:track:2kmZop34md5KWP4gn7Zuj8',
10148+
}),
10149+
}),
10150+
dict({
10151+
'track': dict({
10152+
'description': 'HAPPYYYYY SEMEN DAY!!!!!! Love you xoxoxCheck out our Patreon at patreon.com/ToniandRyan, and make sure you join our Facebook Group!\xa0Find #ToniAndRyan on Instagram @tonilodge and @ryan.jon OR on TikTok @toniandryanpodcast Hosted on Acast. See acast.com/privacy for more information.',
10153+
'duration_ms': 2071013,
10154+
'episode_id': '5ytYkag3JZJ3GP2uuFAEBe',
10155+
'explicit': True,
10156+
'external_urls': dict({
10157+
'spotify': 'https://open.spotify.com/episode/5ytYkag3JZJ3GP2uuFAEBe',
10158+
}),
10159+
'href': 'https://api.spotify.com/v1/episodes/5ytYkag3JZJ3GP2uuFAEBe',
10160+
'images': list([
10161+
dict({
10162+
'height': 640,
10163+
'url': 'https://i.scdn.co/image/ab6765630000ba8ab5f65a943ef4f707bf79949b',
10164+
'width': 640,
10165+
}),
10166+
dict({
10167+
'height': 300,
10168+
'url': 'https://i.scdn.co/image/ab67656300005f1fb5f65a943ef4f707bf79949b',
10169+
'width': 300,
10170+
}),
10171+
dict({
10172+
'height': 64,
10173+
'url': 'https://i.scdn.co/image/ab6765630000f68db5f65a943ef4f707bf79949b',
10174+
'width': 64,
10175+
}),
10176+
]),
10177+
'name': 'Toni Delivers Semen',
10178+
'release_date': '2024-11-27',
10179+
'release_date_precision': <ReleaseDatePrecision.DAY: 'day'>,
10180+
'show': dict({
10181+
'description': 'We’ll all giggle along at naughty jokes, your dating horror stories and give questionable recommendations on movies, food and relationships. This podcast is hot, fun garbage and we (Toni Lodge and Ryan Jon here in Melbourne, Australia) would love you to climb aboard and be our friends. Hosted on Acast. See acast.com/privacy for more information.',
10182+
'external_urls': dict({
10183+
'spotify': 'https://open.spotify.com/show/5OzkclFjD6iAjtAuo7aIYt',
10184+
}),
10185+
'href': 'https://api.spotify.com/v1/shows/5OzkclFjD6iAjtAuo7aIYt',
10186+
'images': list([
10187+
dict({
10188+
'height': 640,
10189+
'url': 'https://i.scdn.co/image/ab6765630000ba8ab5f65a943ef4f707bf79949b',
10190+
'width': 640,
10191+
}),
10192+
dict({
10193+
'height': 300,
10194+
'url': 'https://i.scdn.co/image/ab67656300005f1fb5f65a943ef4f707bf79949b',
10195+
'width': 300,
10196+
}),
10197+
dict({
10198+
'height': 64,
10199+
'url': 'https://i.scdn.co/image/ab6765630000f68db5f65a943ef4f707bf79949b',
10200+
'width': 64,
10201+
}),
10202+
]),
10203+
'name': 'Toni and Ryan',
10204+
'publisher': 'Toni Lodge and Ryan Jon',
10205+
'show_id': '5OzkclFjD6iAjtAuo7aIYt',
10206+
'total_episodes': 780,
10207+
'uri': 'spotify:show:5OzkclFjD6iAjtAuo7aIYt',
10208+
}),
10209+
'type': <ItemType.EPISODE: 'episode'>,
10210+
'uri': 'spotify:episode:5ytYkag3JZJ3GP2uuFAEBe',
10211+
}),
10212+
}),
10213+
]),
10214+
}),
10215+
'uri': 'spotify:playlist:0pM0KTMXM7K5qr3sL2DPw1',
10216+
})
10217+
# ---
1000610218
# name: test_get_recently_played_tracks
1000710219
list([
1000810220
dict({

0 commit comments

Comments
 (0)