minor
This commit is contained in:
6
base.py
6
base.py
@@ -9,9 +9,10 @@ from fastapi import FastAPI, Request
|
|||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from lyric_search.sources import redis_cache
|
from lyric_search.sources import redis_cache
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
logging.getLogger("aiosqlite").setLevel(logging.WARNING)
|
||||||
|
logging.getLogger("httpx").setLevel(logging.WARNING)
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
logger.setLevel(logging.INFO)
|
|
||||||
|
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
@@ -22,7 +23,6 @@ app = FastAPI(
|
|||||||
loop=loop,
|
loop=loop,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
constants = importlib.import_module("constants").Constants()
|
constants = importlib.import_module("constants").Constants()
|
||||||
util = importlib.import_module("util").Utilities(app, constants)
|
util = importlib.import_module("util").Utilities(app, constants)
|
||||||
|
|
||||||
|
@@ -5,8 +5,6 @@ from fastapi.responses import JSONResponse
|
|||||||
from utils.sr_wrapper import SRUtil
|
from utils.sr_wrapper import SRUtil
|
||||||
from auth.deps import get_current_user
|
from auth.deps import get_current_user
|
||||||
|
|
||||||
logging.getLogger().setLevel(logging.INFO)
|
|
||||||
|
|
||||||
|
|
||||||
class RIP(FastAPI):
|
class RIP(FastAPI):
|
||||||
"""
|
"""
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import asyncio
|
||||||
from streamrip.client import TidalClient
|
from streamrip.client import TidalClient
|
||||||
from streamrip.config import Config as StreamripConfig
|
from streamrip.config import Config as StreamripConfig
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
|
|
||||||
@@ -38,6 +38,7 @@ class SRUtil:
|
|||||||
)
|
)
|
||||||
self.streamrip_config
|
self.streamrip_config
|
||||||
self.streamrip_client = TidalClient(self.streamrip_config)
|
self.streamrip_client = TidalClient(self.streamrip_config)
|
||||||
|
asyncio.get_event_loop().create_task(self.streamrip_client.login())
|
||||||
|
|
||||||
def dedupe_by_key(self, key: str, entries: list[dict]) -> list[dict]:
|
def dedupe_by_key(self, key: str, entries: list[dict]) -> list[dict]:
|
||||||
deduped = {}
|
deduped = {}
|
||||||
@@ -111,7 +112,7 @@ class SRUtil:
|
|||||||
if not metadata:
|
if not metadata:
|
||||||
logging.warning("No metadata found for artist ID: %s", artist_id)
|
logging.warning("No metadata found for artist ID: %s", artist_id)
|
||||||
return None
|
return None
|
||||||
albums = metadata.get("albums", [])
|
albums = self.dedupe_by_key("title", metadata.get("albums", []))
|
||||||
albums_out = [
|
albums_out = [
|
||||||
{
|
{
|
||||||
"artist": ", ".join(artist["name"] for artist in album["artists"]),
|
"artist": ", ".join(artist["name"] for artist in album["artists"]),
|
||||||
@@ -123,7 +124,7 @@ class SRUtil:
|
|||||||
if "title" in album and "id" in album and "artists" in album
|
if "title" in album and "id" in album and "artists" in album
|
||||||
]
|
]
|
||||||
|
|
||||||
logging.info("Retrieved albums: %s", albums_out)
|
logging.debug("Retrieved albums: %s", albums_out)
|
||||||
return albums_out
|
return albums_out
|
||||||
|
|
||||||
async def get_tracks_by_album_id(self, album_id: int) -> Optional[list | dict]:
|
async def get_tracks_by_album_id(self, album_id: int) -> Optional[list | dict]:
|
||||||
@@ -178,10 +179,29 @@ class SRUtil:
|
|||||||
Returns:
|
Returns:
|
||||||
Optional[str]: The stream URL or None if not found.
|
Optional[str]: The stream URL or None if not found.
|
||||||
"""
|
"""
|
||||||
track_id_str = str(track_id)
|
if quality not in ["LOSSLESS", "HIGH", "LOW"]:
|
||||||
track = await self.streamrip_client.get_downloadable(
|
logging.error("Invalid quality requested: %s",
|
||||||
track_id=track_id_str, quality=self.streamrip_config.session.tidal.quality
|
quality)
|
||||||
)
|
quality_int: int = int(self.streamrip_config.session.tidal.quality)
|
||||||
|
match quality:
|
||||||
|
case "HIGH":
|
||||||
|
quality_int = 1
|
||||||
|
case "LOW":
|
||||||
|
quality_int = 0
|
||||||
|
track_id_str: str = str(track_id)
|
||||||
|
|
||||||
|
if not self.streamrip_client.logged_in:
|
||||||
|
await self.streamrip_client.login()
|
||||||
|
|
||||||
|
try:
|
||||||
|
track = await self.streamrip_client.get_downloadable(
|
||||||
|
track_id=track_id_str, quality=quality_int
|
||||||
|
)
|
||||||
|
except AttributeError:
|
||||||
|
await self.streamrip_client.login()
|
||||||
|
track = await self.streamrip_client.get_downloadable(
|
||||||
|
track_id=track_id_str, quality=quality_int
|
||||||
|
)
|
||||||
if not track:
|
if not track:
|
||||||
logging.warning("No track found for ID: %s", track_id)
|
logging.warning("No track found for ID: %s", track_id)
|
||||||
return None
|
return None
|
||||||
|
Reference in New Issue
Block a user