Skip to content

Commit

Permalink
🎶 /lyrics Endpoint Added
Browse files Browse the repository at this point in the history
  • Loading branch information
0x64 committed Apr 11, 2024
1 parent f373694 commit 0500dac
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions src/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down

1 comment on commit 0500dac

@vercel
Copy link

@vercel vercel bot commented on 0500dac Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.