This commit is contained in:
codey 2024-08-14 08:06:02 -04:00
parent 9aabe40d8e
commit 05e99718f8

View File

@ -35,6 +35,23 @@ class ValidAlbumDetailRequest(BaseModel):
} }
} }
class ValidTrackInfoRequest(BaseModel):
"""
- **a**: artist name
- **t**: track
"""
a: str
t: str
class Config:
schema_extra = {
"example": {
"a": "eminem",
"t": "rap god"
}
}
class LastFM(FastAPI): class LastFM(FastAPI):
"""Last.FM Endpoints""" """Last.FM Endpoints"""
def __init__(self, app: FastAPI, util, constants, glob_state): # pylint: disable=super-init-not-called def __init__(self, app: FastAPI, util, constants, glob_state): # pylint: disable=super-init-not-called
@ -48,7 +65,8 @@ class LastFM(FastAPI):
"get_artist_by_name": self.artist_by_name_handler, "get_artist_by_name": self.artist_by_name_handler,
"get_artist_albums": self.artist_album_handler, "get_artist_albums": self.artist_album_handler,
"get_release": self.release_detail_handler, "get_release": self.release_detail_handler,
"get_album_tracklist": self.release_tracklist_handler, "get_release_tracklist": self.release_tracklist_handler,
"get_track_info": self.track_info_handler,
#tbd #tbd
} }
@ -158,3 +176,25 @@ class LastFM(FastAPI):
'summary': tracklist_result.get('summary'), 'summary': tracklist_result.get('summary'),
'tracks': tracklist_result.get('tracks') 'tracks': tracklist_result.get('tracks')
} }
async def track_info_handler(self, data: ValidTrackInfoRequest):
"""
/get_track_info/
Get track info from Last.FM given an artist/track
"""
artist = data.a
track = data.t
if not(artist) or not(track):
return {
'err': True,
'errorText': 'Invalid request'
}
track_info_result = await self.lastfm.get_track_info(artist=artist, track=track)
assert not "err" in track_info_result.keys()
return {
'success': True,
'result': track_info_result
}