cleanup/refactor
This commit is contained in:
parent
128019423b
commit
9f615ad0d9
@ -143,8 +143,10 @@ class Radio(FastAPI):
|
|||||||
Otherwise, current track album art will be pulled.
|
Otherwise, current track album art will be pulled.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
if not track_id:
|
||||||
|
track_id = self.radio_util.now_playing.get('id')
|
||||||
logging.debug("Seeking album art with trackId: %s", track_id)
|
logging.debug("Seeking album art with trackId: %s", track_id)
|
||||||
album_art: Optional[bytes] = await self.radio_util._get_album_art(track_id=track_id)
|
album_art: Optional[bytes] = await self.radio_util.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)
|
||||||
@ -205,7 +207,7 @@ class Radio(FastAPI):
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
try:
|
try:
|
||||||
if not await self.radio_util.get_album_art(file_path=next['file_path']):
|
if not await self.radio_util.get_album_art(file_path=next['file_path']):
|
||||||
album_art = await self.radio_util._get_album_art(next['file_path'])
|
album_art = await self.radio_util.get_album_art(file_path=next['file_path'])
|
||||||
await self.radio_util.cache_album_art(next['id'], album_art)
|
await self.radio_util.cache_album_art(next['id'], album_art)
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
@ -59,7 +59,17 @@ class RadioUtil:
|
|||||||
"""
|
"""
|
||||||
return str(datetime.timedelta(seconds=s)).split(".", maxsplit=1)[0]
|
return str(datetime.timedelta(seconds=s)).split(".", maxsplit=1)[0]
|
||||||
|
|
||||||
async def search_playlist(self, artistsong: str|None = None, artist: str|None = None, song: str|None = None) -> bool:
|
async def search_playlist(self, artistsong: Optional[str] = None, artist: Optional[str] = None,
|
||||||
|
song: Optional[str] = None) -> bool:
|
||||||
|
"""
|
||||||
|
Search for track, add it up next in play queue if found
|
||||||
|
Args:
|
||||||
|
artistsong (Optional[str]): Artist - Song combo to search [ignored if artist/song are specified]
|
||||||
|
artist (Optional[str]): Artist to search (ignored if artistsong is specified)
|
||||||
|
song (Optional[str]): Song to search (ignored if artistsong is specified)
|
||||||
|
Returns:
|
||||||
|
bool
|
||||||
|
"""
|
||||||
if artistsong and (artist or song):
|
if artistsong and (artist or song):
|
||||||
raise RadioException("Cannot search using combination provided")
|
raise RadioException("Cannot search using combination provided")
|
||||||
if not artistsong and (not artist or not song):
|
if not artistsong and (not artist or not song):
|
||||||
@ -107,6 +117,7 @@ class RadioUtil:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
async def load_playlist(self):
|
async def load_playlist(self):
|
||||||
|
"""Load Playlist"""
|
||||||
try:
|
try:
|
||||||
logging.info(f"Loading playlist...")
|
logging.info(f"Loading playlist...")
|
||||||
self.active_playlist.clear()
|
self.active_playlist.clear()
|
||||||
@ -118,7 +129,8 @@ class RadioUtil:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
db_query: str = 'SELECT distinct(artist || " - " || song) AS artistdashsong, id, artist, song, genre, file_path, duration FROM tracks\
|
db_query: str = 'SELECT distinct(artist || " - " || song) AS artistdashsong, id, artist, song, genre, file_path, duration FROM tracks\
|
||||||
WHERE genre IN ("metalcore", "pop punk", "punk rock", "metal", "punk", "electronic", "nu metal", "EDM",\
|
WHERE genre IN ("metalcore", "rock", "pop punk", "math rock", "punk rock",\
|
||||||
|
"metal", "punk", "electronic", "nu metal", "EDM",\
|
||||||
"post-hardcore", "pop rock", "experimental", "post-punk", "death metal", "electronicore", "hard rock", "psychedelic rock",\
|
"post-hardcore", "pop rock", "experimental", "post-punk", "death metal", "electronicore", "hard rock", "psychedelic rock",\
|
||||||
"grunge", "house", "dubstep", "hardcore", "hair metal", "horror punk", "folk punk", "breakcore",\
|
"grunge", "house", "dubstep", "hardcore", "hair metal", "horror punk", "folk punk", "breakcore",\
|
||||||
"post-rock", "deathcore", "hardcore punk", "synthwave", "trap") GROUP BY artistdashsong ORDER BY RANDOM()'
|
"post-rock", "deathcore", "hardcore punk", "synthwave", "trap") GROUP BY artistdashsong ORDER BY RANDOM()'
|
||||||
@ -144,6 +156,14 @@ class RadioUtil:
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
async def cache_album_art(self, track_id: int, album_art: bytes) -> None:
|
async def cache_album_art(self, track_id: int, album_art: bytes) -> None:
|
||||||
|
"""
|
||||||
|
Cache Album Art to SQLite DB
|
||||||
|
Args:
|
||||||
|
track_id (int): Track ID to update
|
||||||
|
album_art (bytes): Album art data
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
async with sqlite3.connect(self.active_playlist_path,
|
async with sqlite3.connect(self.active_playlist_path,
|
||||||
timeout=2) as db_conn:
|
timeout=2) as db_conn:
|
||||||
@ -155,6 +175,14 @@ class RadioUtil:
|
|||||||
|
|
||||||
async def get_album_art(self, track_id: Optional[int] = None,
|
async def get_album_art(self, track_id: Optional[int] = None,
|
||||||
file_path: Optional[str] = None) -> bytes:
|
file_path: Optional[str] = None) -> bytes:
|
||||||
|
"""
|
||||||
|
Get Album Art
|
||||||
|
Args:
|
||||||
|
track_id (Optional[int]): Track ID to query (ignored if file_path is specified)
|
||||||
|
file_path (Optional[str]): file_path to query (ignored if track_id is specified)
|
||||||
|
Returns:
|
||||||
|
bytes
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
async with sqlite3.connect(self.active_playlist_path,
|
async with sqlite3.connect(self.active_playlist_path,
|
||||||
timeout=2) as db_conn:
|
timeout=2) as db_conn:
|
||||||
@ -175,24 +203,6 @@ class RadioUtil:
|
|||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return
|
return
|
||||||
|
|
||||||
async def _get_album_art(self, track_id: Optional[int] = None, file_path: Optional[str] = None) -> Optional[bytes]:
|
|
||||||
try:
|
|
||||||
if not file_path:
|
|
||||||
file_path: Optional[str] = self.now_playing.get('file_path')
|
|
||||||
|
|
||||||
if not file_path:
|
|
||||||
logging.critical("_get_album_art:: No current file")
|
|
||||||
return
|
|
||||||
original_file_path: Optional[str] = file_path
|
|
||||||
file_path: Optional[str] = file_path.replace("/paul/toons/",
|
|
||||||
"/singer/gogs_toons/")
|
|
||||||
cached_album_art: Optional[bytes|bool] = await self.get_album_art(file_path=original_file_path,
|
|
||||||
track_id=track_id)
|
|
||||||
if cached_album_art:
|
|
||||||
return cached_album_art
|
|
||||||
except:
|
|
||||||
traceback.print_exc()
|
|
||||||
|
|
||||||
def get_queue_item_by_uuid(self, uuid: str) -> Optional[tuple[int, dict]]:
|
def get_queue_item_by_uuid(self, uuid: str) -> Optional[tuple[int, dict]]:
|
||||||
"""
|
"""
|
||||||
@ -208,6 +218,13 @@ class RadioUtil:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
async def _ls_skip(self) -> bool:
|
async def _ls_skip(self) -> bool:
|
||||||
|
"""
|
||||||
|
Ask LiquidSoap server to skip to the next track
|
||||||
|
Args:
|
||||||
|
None
|
||||||
|
Returns:
|
||||||
|
bool
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
async with ClientSession() as session:
|
async with ClientSession() as session:
|
||||||
async with session.get(f"{self.ls_uri}/next",
|
async with session.get(f"{self.ls_uri}/next",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user