File tree Expand file tree Collapse file tree 4 files changed +74
-1
lines changed
Expand file tree Collapse file tree 4 files changed +74
-1
lines changed Original file line number Diff line number Diff line change 1414from spotifyaio .exceptions import SpotifyConnectionError , SpotifyError
1515from spotifyaio .models import (
1616 Album ,
17+ Artist ,
1718 ArtistResponse ,
1819 BasePlaylist ,
1920 BaseUserProfile ,
4546)
4647
4748if TYPE_CHECKING :
48- from spotifyaio import Artist , SimplifiedAlbum , Track
49+ from spotifyaio import SimplifiedAlbum , Track
4950
5051
5152@dataclass
@@ -148,6 +149,12 @@ async def get_album(self, album_id: str) -> Album:
148149 response = await self ._get (f"v1/albums/{ album_id } " )
149150 return Album .from_json (response )
150151
152+ async def get_artist (self , artist_id : str ) -> Artist :
153+ """Get artist."""
154+ identifier = artist_id .split (":" )[- 1 ]
155+ response = await self ._get (f"v1/artists/{ identifier } " )
156+ return Artist .from_json (response )
157+
151158 async def get_playback (self ) -> PlaybackState | None :
152159 """Get playback state."""
153160 response = await self ._get (
Original file line number Diff line number Diff line change 366366 'uri': 'spotify:album:3IqzqH6ShrRtie9Yd2ODyG',
367367 })
368368# ---
369+ # name: test_get_artist
370+ dict({
371+ 'artist_id': '0TnOYISbd1XYRBk9myaseg',
372+ 'name': 'Pitbull',
373+ 'uri': 'spotify:artist:0TnOYISbd1XYRBk9myaseg',
374+ })
375+ # ---
369376# name: test_get_category
370377 dict({
371378 'category_id': '0JQ5DAqbMKFRY5ok2pxXJ0',
Original file line number Diff line number Diff line change 1+ {
2+ "external_urls" : {
3+ "spotify" : " https://open.spotify.com/artist/0TnOYISbd1XYRBk9myaseg"
4+ },
5+ "followers" : {
6+ "href" : null ,
7+ "total" : 10817055
8+ },
9+ "genres" : [
10+ " dance pop" ,
11+ " miami hip hop" ,
12+ " pop"
13+ ],
14+ "href" : " https://api.spotify.com/v1/artists/0TnOYISbd1XYRBk9myaseg?locale=en-US%2Cen%3Bq%3D0.5" ,
15+ "id" : " 0TnOYISbd1XYRBk9myaseg" ,
16+ "images" : [
17+ {
18+ "url" : " https://i.scdn.co/image/ab6761610000e5ebee07b5820dd91d15d397e29c" ,
19+ "height" : 640 ,
20+ "width" : 640
21+ },
22+ {
23+ "url" : " https://i.scdn.co/image/ab67616100005174ee07b5820dd91d15d397e29c" ,
24+ "height" : 320 ,
25+ "width" : 320
26+ },
27+ {
28+ "url" : " https://i.scdn.co/image/ab6761610000f178ee07b5820dd91d15d397e29c" ,
29+ "height" : 160 ,
30+ "width" : 160
31+ }
32+ ],
33+ "name" : " Pitbull" ,
34+ "popularity" : 85 ,
35+ "type" : " artist" ,
36+ "uri" : " spotify:artist:0TnOYISbd1XYRBk9myaseg"
37+ }
Original file line number Diff line number Diff line change @@ -1026,3 +1026,25 @@ async def test_get_category(
10261026 params = None ,
10271027 data = None ,
10281028 )
1029+
1030+
1031+ async def test_get_artist (
1032+ responses : aioresponses ,
1033+ snapshot : SnapshotAssertion ,
1034+ authenticated_client : SpotifyClient ,
1035+ ) -> None :
1036+ """Test retrieving an artist."""
1037+ responses .get (
1038+ f"{ SPOTIFY_URL } /v1/artists/0TnOYISbd1XYRBk9myaseg" ,
1039+ status = 200 ,
1040+ body = load_fixture ("artist.json" ),
1041+ )
1042+ response = await authenticated_client .get_artist ("0TnOYISbd1XYRBk9myaseg" )
1043+ assert response == snapshot
1044+ responses .assert_called_once_with (
1045+ f"{ SPOTIFY_URL } /v1/artists/0TnOYISbd1XYRBk9myaseg" ,
1046+ METH_GET ,
1047+ headers = HEADERS ,
1048+ params = None ,
1049+ data = None ,
1050+ )
You can’t perform that action at this time.
0 commit comments