This is a teeny tiny API/Proxy to run on my server so you can see what I'm listening to on my website.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

reformat and reintro salt

+19 -10
+17 -8
src/main.py
··· 4 4 import sys 5 5 import traceback 6 6 7 - from fastapi.websockets import WebSocketState 8 7 import uvicorn 9 8 from fastapi import FastAPI, Request, Response, WebSocket 10 9 from fastapi.middleware.cors import CORSMiddleware 10 + from fastapi.websockets import WebSocketState 11 11 12 12 from subsonic import get_cover_art, get_now_playing 13 13 ··· 172 172 }, 173 173 } 174 174 175 + 175 176 @app.get("/coverart") 176 177 async def cover_art(request: Request): 177 178 await ensure_updating() 178 179 size = now_playing.get_cover_art_size(512) 179 180 if not size: 180 181 return Response(status_code=404) 181 - return Response(status_code=307, headers={ 182 - "Cache-Control": "no-cache", 183 - "Location": f"{get_base_url(request)}/coverart/{size}", 184 - }) 182 + return Response( 183 + status_code=307, 184 + headers={ 185 + "Cache-Control": "no-cache", 186 + "Location": f"{get_base_url(request)}/coverart/{size}", 187 + }, 188 + ) 189 + 185 190 186 191 @app.get("/coverart/{res}") 187 192 async def cover_art_res(res: int, lower: bool = False): ··· 190 195 res = now_playing.get_cover_art_size(res) 191 196 if res not in now_playing.cover_art: 192 197 return {"error": "No cover art of that size available."} 193 - return Response(content=now_playing.cover_art[res], media_type="image/png", headers={ 194 - "Cache-Control": "no-cache", 195 - }) 198 + return Response( 199 + content=now_playing.cover_art[res], 200 + media_type="image/png", 201 + headers={ 202 + "Cache-Control": "no-cache", 203 + }, 204 + ) 196 205 197 206 198 207 @app.websocket("/ws")
+2 -2
src/subsonic.py
··· 7 7 from bs4 import BeautifulSoup 8 8 9 9 SALT = bcrypt.gensalt() 10 - PWHASH = hashlib.md5(os.environ.get("NAVI_PASS").encode()).hexdigest() 10 + PWHASH = hashlib.md5(os.environ.get("NAVI_PASS").encode() + SALT).hexdigest() 11 11 QUERY_ARGS = "u=%s&t=%s&s=%s&v=0.1.0&c=listenalong" % ( 12 12 os.environ.get("NAVI_USER"), 13 13 PWHASH, 14 - "" # SALT.decode(), 14 + SALT.decode(), 15 15 ) 16 16 ORIGIN = os.environ.get("NAVI_HOST", "http://localhost:3000") 17 17