webhook / album art changes
This commit is contained in:
parent
7145e86ded
commit
55bd485af4
@ -69,6 +69,7 @@ class Radio(FastAPI):
|
|||||||
app.add_api_route("/radio/album_art", self.album_art_handler, methods=["GET"],
|
app.add_api_route("/radio/album_art", self.album_art_handler, methods=["GET"],
|
||||||
include_in_schema=True)
|
include_in_schema=True)
|
||||||
asyncio.get_event_loop().run_until_complete(self.load_playlist())
|
asyncio.get_event_loop().run_until_complete(self.load_playlist())
|
||||||
|
asyncio.get_event_loop().run_until_complete(self._ls_skip())
|
||||||
|
|
||||||
|
|
||||||
def get_queue_item_by_uuid(self, uuid: str) -> tuple[int, dict] | None:
|
def get_queue_item_by_uuid(self, uuid: str) -> tuple[int, dict] | None:
|
||||||
@ -269,7 +270,8 @@ class Radio(FastAPI):
|
|||||||
query = "SELECT album_art FROM tracks WHERE id = ?"
|
query = "SELECT album_art FROM tracks WHERE id = ?"
|
||||||
query_params = (track_id,)
|
query_params = (track_id,)
|
||||||
|
|
||||||
if file_path:
|
if file_path and not track_id:
|
||||||
|
logging.info("Searchijng w filePath %s", file_path)
|
||||||
query = "SELECT album_art FROM tracks WHERE file_path = ?"
|
query = "SELECT album_art FROM tracks WHERE file_path = ?"
|
||||||
query_params = (file_path,)
|
query_params = (file_path,)
|
||||||
|
|
||||||
@ -295,7 +297,8 @@ class Radio(FastAPI):
|
|||||||
file_path = file_path.replace("/paul/toons/",
|
file_path = file_path.replace("/paul/toons/",
|
||||||
"/singer/gogs_toons/")
|
"/singer/gogs_toons/")
|
||||||
logging.info("Seeking %s", original_file_path)
|
logging.info("Seeking %s", original_file_path)
|
||||||
cached_album_art = await self.get_album_art(file_path=original_file_path)
|
cached_album_art = await self.get_album_art(file_path=original_file_path,
|
||||||
|
track_id=track_id)
|
||||||
if cached_album_art:
|
if cached_album_art:
|
||||||
logging.info("Returning from cache!")
|
logging.info("Returning from cache!")
|
||||||
return cached_album_art
|
return cached_album_art
|
||||||
@ -308,9 +311,10 @@ class Radio(FastAPI):
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
# TODO: Optimize/cache
|
# TODO: Optimize/cache
|
||||||
async def album_art_handler(self, request: Request) -> bytes:
|
async def album_art_handler(self, request: Request, track_id: Optional[int] = None) -> bytes:
|
||||||
try:
|
try:
|
||||||
album_art = await self._get_album_art()
|
logging.info("Seeking album art with trackId: %s", track_id)
|
||||||
|
album_art = await self._get_album_art(track_id=track_id)
|
||||||
if not album_art:
|
if not album_art:
|
||||||
return RedirectResponse(url="https://codey.lol/images/radio_art_default.jpg",
|
return RedirectResponse(url="https://codey.lol/images/radio_art_default.jpg",
|
||||||
status_code=302)
|
status_code=302)
|
||||||
@ -337,7 +341,7 @@ class Radio(FastAPI):
|
|||||||
|
|
||||||
|
|
||||||
async def radio_get_next(self, data: ValidRadioNextRequest, request: Request,
|
async def radio_get_next(self, data: ValidRadioNextRequest, request: Request,
|
||||||
background_tasks: BackgroundTasks) -> dict:
|
background_tasks: BackgroundTasks) -> Optional[dict]:
|
||||||
"""
|
"""
|
||||||
Get next track
|
Get next track
|
||||||
Args:
|
Args:
|
||||||
@ -349,13 +353,16 @@ class Radio(FastAPI):
|
|||||||
"""
|
"""
|
||||||
if not self.util.check_key(path=request.url.path, req_type=4, key=data.key):
|
if not self.util.check_key(path=request.url.path, req_type=4, key=data.key):
|
||||||
raise HTTPException(status_code=403, detail="Unauthorized")
|
raise HTTPException(status_code=403, detail="Unauthorized")
|
||||||
|
if not isinstance(self.active_playlist, list) or not self.active_playlist:
|
||||||
if isinstance(self.active_playlist, list) and self.active_playlist:
|
await self.load_playlist()
|
||||||
|
await self._ls_skip()
|
||||||
|
return
|
||||||
next = self.active_playlist.pop(0)
|
next = self.active_playlist.pop(0)
|
||||||
if not isinstance(next, dict):
|
if not isinstance(next, dict):
|
||||||
logging.info("next is of type: %s, reloading playlist...", type(next))
|
logging.info("next is of type: %s, reloading playlist...", type(next))
|
||||||
await self.load_playlist()
|
await self.load_playlist()
|
||||||
return await self.radio_pop_track(request, recursion_type="not dict: next")
|
await self._ls_skip()
|
||||||
|
return
|
||||||
|
|
||||||
duration = next['duration']
|
duration = next['duration']
|
||||||
time_started = int(time.time())
|
time_started = int(time.time())
|
||||||
@ -383,8 +390,6 @@ class Radio(FastAPI):
|
|||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return next
|
return next
|
||||||
else:
|
|
||||||
return await self.radio_pop_track(request, recursion_type="not list: self.active_playlist")
|
|
||||||
|
|
||||||
|
|
||||||
async def radio_request(self, data: ValidRadioSongRequest, request: Request) -> Response:
|
async def radio_request(self, data: ValidRadioSongRequest, request: Request) -> Response:
|
||||||
|
@ -65,8 +65,11 @@ class RadioUtil:
|
|||||||
'username': 'serious.FM',
|
'username': 'serious.FM',
|
||||||
"embeds": [{
|
"embeds": [{
|
||||||
"title": "Now Playing",
|
"title": "Now Playing",
|
||||||
"description": f'# {track['song']}\nby **{track['artist']}**',
|
"description": f'## {track['song']}\nby\n## {track['artist']}',
|
||||||
"color": 0x30c56f,
|
"color": 0x30c56f,
|
||||||
|
"thumbnail": {
|
||||||
|
"url": f"https://api.codey.lol/radio/album_art?track_id={track['id']}&{time.time()}",
|
||||||
|
},
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"name": "Duration",
|
"name": "Duration",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user