Resolves #11
This commit is contained in:
parent
7baa1c5d25
commit
72abef1092
@ -11,6 +11,15 @@ class ValidArtistSearchRequest(BaseModel):
|
||||
|
||||
a: str
|
||||
|
||||
class ValidAlbumDetailRequest(BaseModel):
|
||||
"""
|
||||
- **a**: artist name
|
||||
- **a2**: album/release name (as sourced from here/LastFM)
|
||||
"""
|
||||
|
||||
a: str
|
||||
a2: str
|
||||
|
||||
class LastFM(FastAPI):
|
||||
"""Last.FM Endpoints"""
|
||||
def __init__(self, app: FastAPI, util, constants): # pylint: disable=super-init-not-called
|
||||
@ -22,6 +31,7 @@ class LastFM(FastAPI):
|
||||
self.endpoints = {
|
||||
"get_artist_by_name": self.artist_by_name_handler,
|
||||
"get_artist_albums": self.artist_album_handler,
|
||||
"get_release": self.release_detail_handler,
|
||||
#tbd
|
||||
}
|
||||
|
||||
@ -30,6 +40,7 @@ class LastFM(FastAPI):
|
||||
|
||||
async def artist_by_name_handler(self, data: ValidArtistSearchRequest):
|
||||
"""
|
||||
/get_artist_by_name/
|
||||
Get artist info
|
||||
"""
|
||||
artist = data.a.strip()
|
||||
@ -53,6 +64,7 @@ class LastFM(FastAPI):
|
||||
|
||||
async def artist_album_handler(self, data: ValidArtistSearchRequest):
|
||||
"""
|
||||
/get_artist_albums/
|
||||
Get artist's albums/releases
|
||||
"""
|
||||
artist = data.a.strip()
|
||||
@ -77,3 +89,31 @@ class LastFM(FastAPI):
|
||||
'success': True,
|
||||
'result': album_result_out
|
||||
}
|
||||
|
||||
async def release_detail_handler(self, data: ValidAlbumDetailRequest):
|
||||
"""
|
||||
/get_release/
|
||||
Get details of a particular release by an artist
|
||||
"""
|
||||
artist = data.a.strip()
|
||||
release = data.a2.strip()
|
||||
|
||||
if not artist or not release:
|
||||
return {
|
||||
'err': True,
|
||||
'errorText': 'Invalid request'
|
||||
}
|
||||
|
||||
release_result = await self.lastfm.get_release(artist=artist, album=release)
|
||||
ret_obj = {
|
||||
'id': release_result.get('id'),
|
||||
'artists': release_result.get('artists'),
|
||||
'title': release_result.get('title'),
|
||||
'summary': release_result.get('summary'),
|
||||
'tracks': release_result.get('tracks')
|
||||
}
|
||||
|
||||
return {
|
||||
'success': True,
|
||||
'result': ret_obj
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user