minor
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
from typing import Optional
|
||||
import logging
|
||||
import os
|
||||
import asyncio
|
||||
from streamrip.client import TidalClient
|
||||
from streamrip.config import Config as StreamripConfig
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ class SRUtil:
|
||||
)
|
||||
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]:
|
||||
deduped = {}
|
||||
@@ -111,7 +112,7 @@ class SRUtil:
|
||||
if not metadata:
|
||||
logging.warning("No metadata found for artist ID: %s", artist_id)
|
||||
return None
|
||||
albums = metadata.get("albums", [])
|
||||
albums = self.dedupe_by_key("title", metadata.get("albums", []))
|
||||
albums_out = [
|
||||
{
|
||||
"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
|
||||
]
|
||||
|
||||
logging.info("Retrieved albums: %s", albums_out)
|
||||
logging.debug("Retrieved albums: %s", albums_out)
|
||||
return albums_out
|
||||
|
||||
async def get_tracks_by_album_id(self, album_id: int) -> Optional[list | dict]:
|
||||
@@ -178,10 +179,29 @@ class SRUtil:
|
||||
Returns:
|
||||
Optional[str]: The stream URL or None if not found.
|
||||
"""
|
||||
track_id_str = str(track_id)
|
||||
track = await self.streamrip_client.get_downloadable(
|
||||
track_id=track_id_str, quality=self.streamrip_config.session.tidal.quality
|
||||
)
|
||||
if quality not in ["LOSSLESS", "HIGH", "LOW"]:
|
||||
logging.error("Invalid quality requested: %s",
|
||||
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:
|
||||
logging.warning("No track found for ID: %s", track_id)
|
||||
return None
|
||||
|
Reference in New Issue
Block a user