Skip to content

Commit 03948ae

Browse files
authored
Remove local file support (#394)
1 parent 1116e38 commit 03948ae

File tree

6 files changed

+405
-4
lines changed

6 files changed

+405
-4
lines changed

src/spotifyaio/models.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@ class CurrentPlaying(DataClassORJSONMixin):
322322
item: Annotated[Item, Discriminator(field="type", include_subtypes=True)] | None
323323
currently_playing_type: str | None
324324

325+
@classmethod
326+
def __pre_deserialize__(cls, d: dict[str, Any]) -> dict[str, Any]:
327+
"""Pre deserialize hook."""
328+
if (item := d.get("item")) is not None and item.get("is_local"):
329+
return {**d, "item": None}
330+
return d
331+
325332

326333
@dataclass
327334
class PlaybackState(CurrentPlaying):
@@ -386,6 +393,12 @@ class PlaylistTracks(DataClassORJSONMixin):
386393

387394
items: list[PlaylistTrack]
388395

396+
@classmethod
397+
def __pre_deserialize__(cls, d: dict[str, Any]) -> dict[str, Any]:
398+
"""Pre deserialize hook."""
399+
items = [item for item in d["items"] if not item["is_local"]]
400+
return {"items": items}
401+
389402

390403
@dataclass
391404
class PlaylistTrack(DataClassORJSONMixin):

tests/__snapshots__/test_spotify.ambr

Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4117,7 +4117,6 @@
41174117
'description': '''
41184118
Author(s): Frank Herbert
41194119
Narrator(s): Scott Brick, Orlagh Cassidy, Euan Morton, Ilyana Kadushin, Simon Vance
4120-
41214120
<p><b>NOW A MAJOR MOTION PICTURE directed by Denis Villeneuve, starring Timothée Chalamet, Zendaya, Rebecca Ferguson, Javier Bardem, Josh Brolin, Austin Butler, Florence Pugh, Dave Bautista, Christopher Walken, Léa Seydoux, Stellan Skarsgård, and Charlotte Rampling<br></b><br>Set on the desert planet Arrakis, <i>Dune</i> is the story of the boy Paul Atreides, who would become the mysterious man known as Muad'dib. He would avenge the traitorous plot against his noble family—and would bring to fruition humankind's most ancient and unattainable dream.<br><br>A stunning blend of adventure and mysticism, environmentalism and politics, <i>Dune</i> won the first Nebula Award, shared the Hugo Award, and formed the basis of what is undoubtedly the grandest epic in science fiction. Frank Herbert's death in 1986 was a tragic loss, yet the astounding legacy of his visionary fiction will live forever.</p>
41224121
''',
41234122
'edition': 'Unabridged',
@@ -9383,6 +9382,27 @@
93839382
'shuffle': False,
93849383
})
93859384
# ---
9385+
# name: test_get_playback_state[playback_4.json]
9386+
dict({
9387+
'context': None,
9388+
'currently_playing_type': 'track',
9389+
'device': dict({
9390+
'device_id': 'aee274e4bbe6b44cf3b22ad3b68eca3a6954a701',
9391+
'device_type': <DeviceType.COMPUTER: 'Computer'>,
9392+
'is_active': True,
9393+
'is_private_session': False,
9394+
'is_restricted': False,
9395+
'name': 'Joost’s MacBook Pro',
9396+
'supports_volume': True,
9397+
'volume_percent': 67,
9398+
}),
9399+
'is_playing': True,
9400+
'item': None,
9401+
'progress_ms': 22215,
9402+
'repeat_mode': <RepeatMode.OFF: 'off'>,
9403+
'shuffle': False,
9404+
})
9405+
# ---
93869406
# name: test_get_playback_state[playback_audiobook_1.json]
93879407
dict({
93889408
'context': dict({
@@ -9571,7 +9591,7 @@
95719591
'shuffle': False,
95729592
})
95739593
# ---
9574-
# name: test_get_playlist
9594+
# name: test_get_playlist[playlist_1.json]
95759595
dict({
95769596
'collaborative': False,
95779597
'description': 'A playlist for testing pourposes',
@@ -9891,6 +9911,98 @@
98919911
'uri': 'spotify:playlist:3cEYpjA9oz9GiPac4AsH4n',
98929912
})
98939913
# ---
9914+
# name: test_get_playlist[playlist_2.json]
9915+
dict({
9916+
'collaborative': False,
9917+
'description': '',
9918+
'external_urls': dict({
9919+
'spotify': 'https://open.spotify.com/playlist/3toMXYM91T55pKzuysH5Ph',
9920+
}),
9921+
'images': list([
9922+
dict({
9923+
'height': None,
9924+
'url': 'https://i.scdn.co/image/ab67616d00001e022f9b47bdc2b1c7cae7b014af',
9925+
'width': None,
9926+
}),
9927+
]),
9928+
'name': 'Starred',
9929+
'object_type': 'playlist',
9930+
'owner': dict({
9931+
'display_name': 'chadandcaren',
9932+
'external_urls': dict({
9933+
'spotify': 'https://open.spotify.com/user/chadandcaren',
9934+
}),
9935+
'href': 'https://api.spotify.com/v1/users/chadandcaren',
9936+
'object_type': 'user',
9937+
'owner_id': 'chadandcaren',
9938+
'uri': 'spotify:user:chadandcaren',
9939+
}),
9940+
'playlist_id': '3toMXYM91T55pKzuysH5Ph',
9941+
'public': True,
9942+
'tracks': dict({
9943+
'items': list([
9944+
dict({
9945+
'track': dict({
9946+
'album': dict({
9947+
'album_id': '3KVfMVtOmoVCgihLE4HoBr',
9948+
'album_type': <AlbumType.ALBUM: 'album'>,
9949+
'artists': list([
9950+
dict({
9951+
'artist_id': '2vm8GdHyrJh2O2MfbQFYG0',
9952+
'name': 'Ingrid Michaelson',
9953+
'uri': 'spotify:artist:2vm8GdHyrJh2O2MfbQFYG0',
9954+
}),
9955+
]),
9956+
'images': list([
9957+
dict({
9958+
'height': 640,
9959+
'url': 'https://i.scdn.co/image/ab67616d0000b273866dc0fd5fbfd51fd4c50919',
9960+
'width': 640,
9961+
}),
9962+
dict({
9963+
'height': 300,
9964+
'url': 'https://i.scdn.co/image/ab67616d00001e02866dc0fd5fbfd51fd4c50919',
9965+
'width': 300,
9966+
}),
9967+
dict({
9968+
'height': 64,
9969+
'url': 'https://i.scdn.co/image/ab67616d00004851866dc0fd5fbfd51fd4c50919',
9970+
'width': 64,
9971+
}),
9972+
]),
9973+
'name': 'Be OK',
9974+
'release_date': '2008-01-01',
9975+
'release_date_precision': <ReleaseDatePrecision.DAY: 'day'>,
9976+
'total_tracks': 11,
9977+
'uri': 'spotify:album:3KVfMVtOmoVCgihLE4HoBr',
9978+
}),
9979+
'artists': list([
9980+
dict({
9981+
'artist_id': '2vm8GdHyrJh2O2MfbQFYG0',
9982+
'name': 'Ingrid Michaelson',
9983+
'uri': 'spotify:artist:2vm8GdHyrJh2O2MfbQFYG0',
9984+
}),
9985+
]),
9986+
'disc_number': 1,
9987+
'duration_ms': 148706,
9988+
'explicit': False,
9989+
'external_urls': dict({
9990+
'spotify': 'https://open.spotify.com/track/4oeRfmp9XpKWym6YD1WvBP',
9991+
}),
9992+
'href': 'https://api.spotify.com/v1/tracks/4oeRfmp9XpKWym6YD1WvBP',
9993+
'is_local': False,
9994+
'name': 'You and I',
9995+
'track_id': '4oeRfmp9XpKWym6YD1WvBP',
9996+
'track_number': 10,
9997+
'type': <ItemType.TRACK: 'track'>,
9998+
'uri': 'spotify:track:4oeRfmp9XpKWym6YD1WvBP',
9999+
}),
10000+
}),
10001+
]),
10002+
}),
10003+
'uri': 'spotify:playlist:3toMXYM91T55pKzuysH5Ph',
10004+
})
10005+
# ---
989410006
# name: test_get_recently_played_tracks
989510007
list([
989610008
dict({

tests/fixtures/playback_4.json

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"device": {
3+
"id": "aee274e4bbe6b44cf3b22ad3b68eca3a6954a701",
4+
"is_active": true,
5+
"is_private_session": false,
6+
"is_restricted": false,
7+
"name": "Joost’s MacBook Pro",
8+
"supports_volume": true,
9+
"type": "Computer",
10+
"volume_percent": 67
11+
},
12+
"shuffle_state": false,
13+
"smart_shuffle": false,
14+
"repeat_state": "off",
15+
"timestamp": 1731336494187,
16+
"context": null,
17+
"progress_ms": 22215,
18+
"item": {
19+
"album": {
20+
"album_type": null,
21+
"artists": [],
22+
"available_markets": [],
23+
"external_urls": {},
24+
"href": null,
25+
"id": null,
26+
"images": [],
27+
"name": "",
28+
"release_date": null,
29+
"release_date_precision": null,
30+
"type": "album",
31+
"uri": null
32+
},
33+
"artists": [
34+
{
35+
"external_urls": {},
36+
"href": null,
37+
"id": null,
38+
"name": "Four Tet x Fred again.. x Skrillex",
39+
"type": "artist",
40+
"uri": null
41+
}
42+
],
43+
"available_markets": [],
44+
"disc_number": 0,
45+
"duration_ms": 5432000,
46+
"explicit": false,
47+
"external_ids": {},
48+
"external_urls": {},
49+
"href": null,
50+
"id": null,
51+
"is_local": true,
52+
"name": "Coachella 2023",
53+
"popularity": 0,
54+
"preview_url": null,
55+
"track_number": 0,
56+
"type": "track",
57+
"uri": "spotify:local:Four+Tet+x+Fred+again..+x+Skrillex::Coachella+2023:5432"
58+
},
59+
"currently_playing_type": "track",
60+
"actions": {
61+
"disallows": {
62+
"resuming": true,
63+
"skipping_prev": true
64+
}
65+
},
66+
"is_playing": true
67+
}

0 commit comments

Comments
 (0)