cleanup
This commit is contained in:
@@ -20,13 +20,17 @@ from .constructors import RadioException
|
||||
double_space = regex.compile(r'\s{2,}')
|
||||
|
||||
class RadioUtil:
|
||||
"""
|
||||
Radio Utils
|
||||
"""
|
||||
def __init__(self, constants) -> None:
|
||||
self.constants = constants
|
||||
self.gpt = gpt.GPT(self.constants)
|
||||
self.ls_uri: str = "http://10.10.10.101:29000"
|
||||
self.sqlite_exts: list[str] = ['/home/singer/api/solibs/spellfix1.cpython-311-x86_64-linux-gnu.so']
|
||||
self.active_playlist_path: str|LiteralString = os.path.join("/usr/local/share",
|
||||
"sqlite_dbs", "track_file_map.db")
|
||||
self.active_playlist_path: Union[str, LiteralString] = os.path\
|
||||
.join("/usr/local/share",
|
||||
"sqlite_dbs", "track_file_map.db")
|
||||
self.active_playlist_name = "default" # not used
|
||||
self.active_playlist: list[dict] = []
|
||||
self.now_playing: dict = {
|
||||
@@ -49,17 +53,19 @@ class RadioUtil:
|
||||
}
|
||||
}
|
||||
|
||||
def duration_conv(self, s: int|float) -> str:
|
||||
def duration_conv(self,
|
||||
s: Union[int, float]) -> str:
|
||||
"""
|
||||
Convert duration given in seconds to hours, minutes, and seconds (h:m:s)
|
||||
Args:
|
||||
s (int|float): seconds to convert
|
||||
s (Union[int, float]): seconds to convert
|
||||
Returns:
|
||||
str
|
||||
"""
|
||||
return str(datetime.timedelta(seconds=s)).split(".", maxsplit=1)[0]
|
||||
|
||||
async def search_playlist(self, artistsong: Optional[str] = None, artist: Optional[str] = None,
|
||||
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
|
||||
@@ -137,7 +143,7 @@ class RadioUtil:
|
||||
LIMITED TO ONE ARTIST...
|
||||
"""
|
||||
|
||||
# db_query: str = 'SELECT distinct(artist || " - " || song) AS artistdashsong, id, artist, song, genre, file_path, duration FROM tracks\
|
||||
# db_query = 'SELECT distinct(artist || " - " || song) AS artistdashsong, id, artist, song, genre, file_path, duration FROM tracks\
|
||||
# WHERE artist LIKE "%bad omens%" GROUP BY artistdashsong ORDER BY RANDOM()'
|
||||
|
||||
async with sqlite3.connect(self.active_playlist_path,
|
||||
@@ -160,7 +166,8 @@ class RadioUtil:
|
||||
except:
|
||||
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:
|
||||
@@ -201,7 +208,7 @@ class RadioUtil:
|
||||
|
||||
async with await db_conn.execute(query,
|
||||
query_params) as db_cursor:
|
||||
result: Optional[sqlite3.Row|bool] = await db_cursor.fetchone()
|
||||
result: Optional[Union[sqlite3.Row, bool]] = await db_cursor.fetchone()
|
||||
if not result or not isinstance(result, sqlite3.Row):
|
||||
return None
|
||||
return result['album_art']
|
||||
@@ -209,13 +216,14 @@ class RadioUtil:
|
||||
traceback.print_exc()
|
||||
return None
|
||||
|
||||
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]]:
|
||||
"""
|
||||
Get queue item by UUID
|
||||
Args:
|
||||
uuid: The UUID to search
|
||||
Returns:
|
||||
dict|None
|
||||
Optional[tuple[int, dict]]
|
||||
"""
|
||||
for x, item in enumerate(self.active_playlist):
|
||||
if item.get('uuid') == uuid:
|
||||
@@ -242,16 +250,18 @@ class RadioUtil:
|
||||
|
||||
return False # failsafe
|
||||
|
||||
async def get_ai_song_info(self, artist: str, song: str) -> Optional[str]:
|
||||
async def get_ai_song_info(self, artist: str,
|
||||
song: str) -> Optional[str]:
|
||||
"""
|
||||
Get AI Song Info
|
||||
Args:
|
||||
artist (str)
|
||||
song (str)
|
||||
Returns:
|
||||
str|None
|
||||
Optional[str]
|
||||
"""
|
||||
response: Optional[str] = await self.gpt.get_completion(prompt=f"I am going to listen to {song} by {artist}.")
|
||||
prompt: str = f" am going to listen to {song} by {artist}."
|
||||
response: Optional[str] = await self.gpt.get_completion(prompt)
|
||||
if not response:
|
||||
logging.critical("No response received from GPT?")
|
||||
return None
|
||||
@@ -298,7 +308,7 @@ class RadioUtil:
|
||||
},
|
||||
{
|
||||
"name": "Higher Res",
|
||||
"value": "[stream/icecast](https://relay.sfm.codey.lol/aces.ogg) || [web player](https://codey.lol/radio)",
|
||||
"value": "[stream/icecast](https://relay.sfm.codey.lol/aces.ogg) | [web player](https://codey.lol/radio)",
|
||||
"inline": True,
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user