@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env python3.12
|
||||
# pylint: disable=bare-except
|
||||
|
||||
import importlib
|
||||
import traceback
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
@ -182,19 +184,25 @@ class LastFM(FastAPI):
|
||||
/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:
|
||||
try:
|
||||
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
|
||||
}
|
||||
except:
|
||||
traceback.print_exc()
|
||||
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
|
||||
}
|
||||
|
||||
'errorText': 'General error',
|
||||
}
|
||||
|
@ -194,6 +194,16 @@ class LyricSearch(FastAPI):
|
||||
result = result.dict()
|
||||
result['lyrics'] = regex.sub(r'(\s/\s|\n)', '<br>', result['lyrics']).strip()
|
||||
result['confidence'] = f'{float(result.get('confidence', 0)):.2f}'
|
||||
result['time'] = f'{float(result['time']):.4f}'
|
||||
if "cached" in result['src']:
|
||||
result['from_cache'] = True
|
||||
|
||||
"""
|
||||
REMOVE BELOW AFTER TESTING IS DONE
|
||||
"""
|
||||
|
||||
# if not data.extra:
|
||||
# result.pop('src')
|
||||
return result
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user