cleanup
This commit is contained in:
parent
55bd485af4
commit
d4809e1b30
@ -251,13 +251,11 @@ class Radio(FastAPI):
|
||||
|
||||
async def cache_album_art(self, track_id: int, album_art: bytes) -> None:
|
||||
try:
|
||||
logging.info("Attempting cache for %s", track_id)
|
||||
async with sqlite3.connect(self.active_playlist_path,
|
||||
timeout=2) as db_conn:
|
||||
async with await db_conn.execute("UPDATE tracks SET album_art = ? WHERE id = ?",
|
||||
(album_art, track_id,)) as db_cursor:
|
||||
await db_conn.commit()
|
||||
logging.info("Committed %s", track_id)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
|
||||
@ -271,7 +269,6 @@ class Radio(FastAPI):
|
||||
query_params = (track_id,)
|
||||
|
||||
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_params = (file_path,)
|
||||
|
||||
@ -291,29 +288,22 @@ class Radio(FastAPI):
|
||||
file_path = self.now_playing.get('file_path')
|
||||
|
||||
if not file_path:
|
||||
logging.info("_get_album_art:: No current file")
|
||||
logging.critical("_get_album_art:: No current file")
|
||||
return
|
||||
original_file_path = file_path
|
||||
file_path = file_path.replace("/paul/toons/",
|
||||
"/singer/gogs_toons/")
|
||||
logging.info("Seeking %s", original_file_path)
|
||||
cached_album_art = await self.get_album_art(file_path=original_file_path,
|
||||
track_id=track_id)
|
||||
if cached_album_art:
|
||||
logging.info("Returning from cache!")
|
||||
return cached_album_art
|
||||
# Not cached, read from file
|
||||
tagged = music_tag.load_file(file_path)
|
||||
album_art = tagged.get('artwork').first
|
||||
logging.info("Returning from file read!")
|
||||
return album_art.data
|
||||
except:
|
||||
traceback.print_exc()
|
||||
|
||||
# TODO: Optimize/cache
|
||||
async def album_art_handler(self, request: Request, track_id: Optional[int] = None) -> bytes:
|
||||
try:
|
||||
logging.info("Seeking album art with trackId: %s", track_id)
|
||||
logging.debug("Seeking album art with trackId: %s", track_id)
|
||||
album_art = await self._get_album_art(track_id=track_id)
|
||||
if not album_art:
|
||||
return RedirectResponse(url="https://codey.lol/images/radio_art_default.jpg",
|
||||
@ -359,7 +349,7 @@ class Radio(FastAPI):
|
||||
return
|
||||
next = self.active_playlist.pop(0)
|
||||
if not isinstance(next, dict):
|
||||
logging.info("next is of type: %s, reloading playlist...", type(next))
|
||||
logging.critical("next is of type: %s, reloading playlist...", type(next))
|
||||
await self.load_playlist()
|
||||
await self._ls_skip()
|
||||
return
|
||||
@ -373,9 +363,6 @@ class Radio(FastAPI):
|
||||
else:
|
||||
await self.load_playlist()
|
||||
|
||||
logging.info("Returning %s", next['artistsong'])
|
||||
# logging.info("Top 5 songs in playlist: %s, bottom: %s",
|
||||
# self.active_playlist[0:6], self.active_playlist[-6:])
|
||||
self.now_playing = next
|
||||
next['start'] = time_started
|
||||
next['end'] = time_ends
|
||||
|
Loading…
x
Reference in New Issue
Block a user