diff --git a/src/index.py b/src/index.py index fdf5ed4..261c941 100644 --- a/src/index.py +++ b/src/index.py @@ -10,6 +10,7 @@ from fastapi import FastAPI, HTTPException, Query from fastapi.responses import FileResponse, HTMLResponse + app = FastAPI(title="HiFi-RestAPI", version="v1.0", description="Tidal Music Proxy") @@ -194,7 +195,7 @@ async def doc(): await removePoweredByTextAndUrl(); }); - async function removePoweredByTextAndUrl() { + function removePoweredByTextAndUrl() { var poweredByLink = document.querySelector('.darklight-reference-promo'); if (poweredByLink) { poweredByLink.textContent = ""; // Setting text content to empty string @@ -277,6 +278,57 @@ async def get_track( ) +@app.api_route("/lyrics/", methods=["GET"]) +async def get_lyrics(id: int): + try: + tokz = await refresh() + tidal_token = tokz + search_url = f"https://api.tidal.com/v1/tracks/{id}/lyrics?countryCode=US&locale=en_US&deviceType=BROWSER" + payload = { + "authorization": f"Bearer {tidal_token}", + } + async with httpx.AsyncClient(http2=True) as clinet: + search_data = await clinet.get(url=search_url, headers=payload) + + return [search_data.json()] + + except KeyError: + raise HTTPException( + status_code=404, + detail="Quality not found. check API docs = https://github.com/sachinsenal0x64/Hifi-Tui?tab=readme-ov-file#-api-documentation", + ) + + except json.JSONDecodeError: + raise HTTPException( + status_code=429, + ) + + except httpx.ConnectTimeout: + raise HTTPException( + status_code=429, + ) + + except httpx.ConnectError: + raise HTTPException( + status_code=429, + ) + + except httpx.ReadTimeout: + raise HTTPException( + status_code=429, + ) + + except httpx.WriteError: + raise HTTPException( + status_code=429, + ) + + except httpx.ReadError: + raise HTTPException( + status_code=429, + ) + + @app.api_route("/song/", methods=["GET"]) async def get_song(q: str, quality: str): try: @@ -580,7 +632,7 @@ async def search_artist(id: int): return [sed_1, json_data] except AttributeError: - return [sed_1] + raise HTTPException(status_code=404) except httpx.ConnectTimeout: raise HTTPException(