Web player served by stemserve

Plex browsing, stem mixer with presets, shuffle, repeat all/one, playback
speed, queue, waveform seek. stemserve serves web/ at / without the token.
stemserve image now builds from the repo root.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
cdnutterandClaude Opus 5.5 committed 2026-10-20 11:30:02 -07:00
1 parent 605b88f1eb
commit 9299fee9a0
8 files changed
+1113 -20

No files matched your search

+5 -2
View File
@@ -1,8 +1,11 @@
# Build from the repo root so the web player comes along:
# docker build -f server/Dockerfile -t stemserve .
FROM python:3.12-alpine
RUN apk add --no-cache ffmpeg
COPY stemserve.py /app/stemserve.py
COPY server/stemserve.py /app/server/stemserve.py
COPY web /app/web
ENV STEMS_DIR=/stems CACHE_DIR=/cache PORT=8765 PYTHONUNBUFFERED=1
EXPOSE 8765
# Unraid shares belong to nobody:users.
USER 99:100
CMD ["python", "/app/stemserve.py"]
CMD ["python", "/app/server/stemserve.py"]
+3 -2
View File
@@ -15,8 +15,9 @@ from the desktop). From an unraid terminal:
```sh
mkdir -p /mnt/user/appdata/stemserve/cache /mnt/user/appdata/stemd/state/queue
chown -R 99:100 /mnt/user/appdata/stemserve /mnt/user/appdata/stemd
cp -r /path/to/stemify/server /mnt/user/appdata/stemserve/src # or copy over SMB
docker build -t stemserve /mnt/user/appdata/stemserve/src
mkdir -p /mnt/user/appdata/stemserve/src # needs server/ and web/ from the repo
cp -r /path/to/stemify/{server,web} /mnt/user/appdata/stemserve/src/ # or copy over SMB
docker build -f /mnt/user/appdata/stemserve/src/server/Dockerfile -t stemserve /mnt/user/appdata/stemserve/src
docker run -d --name stemserve --restart unless-stopped -p 8765:8765 \
-v /mnt/user/Music/Stems:/stems:ro \
-v /mnt/user/appdata/stemserve/cache:/cache \
+1 -1
View File
@@ -1,6 +1,6 @@
services:
stemserve:
build: .
build: {context: .., dockerfile: server/Dockerfile}
image: stemserve:latest
container_name: stemserve
restart: unless-stopped
+18
View File
@@ -16,6 +16,7 @@ Endpoints (all GET unless noted; add ?token=... or X-Stem-Token when TOKEN is se
POST /api/prepare?key=<key>&fmt=opus&br=160 start transcodes in the background
POST /api/stem {"paths": [...]} "Stem Now": stemd separates these Plex files next
/file/<key>/<file>[?fmt=opus&br=160] the stem itself, with Range support
/ the web player (web/, or WEB_DIR); no token needed
<key> is the track's folder relative to STEMS_DIR, e.g. "Artist/Album/01 Song".
"""
@@ -50,6 +51,10 @@ FFMPEG = shutil.which("ffmpeg")
OPUS_RATES = (64, 96, 128, 160, 192, 256)
PEAK_RATE = 2000 # Hz the envelope is computed at; plenty for a few hundred bars
CHUNK = 1 << 20
# The web player. Served without the token; it asks for one in its settings when TOKEN is set.
WEB_DIR = os.path.realpath(os.environ.get("WEB_DIR", os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "web")))
WEB_TYPES = {".html": "text/html; charset=utf-8", ".js": "text/javascript; charset=utf-8", ".css": "text/css; charset=utf-8",
".svg": "image/svg+xml", ".png": "image/png", ".ico": "image/x-icon", ".json": "application/json"}
_pool = ThreadPoolExecutor(max_workers=max(2, (os.cpu_count() or 2) // 2))
_locks: dict[str, threading.Lock] = {}
@@ -267,6 +272,17 @@ class Handler(BaseHTTPRequestHandler):
def _error(self, status, msg):
self._send(status, json.dumps({"error": msg}).encode())
def _web(self, path):
if path == "/":
path = "/index.html"
full = os.path.realpath(os.path.join(WEB_DIR, path.lstrip("/")))
if not full.startswith(WEB_DIR + os.sep) or not os.path.isfile(full):
return self._error(404, "not found")
with open(full, "rb") as f:
body = f.read()
ctype = WEB_TYPES.get(os.path.splitext(full)[1], "application/octet-stream")
self._send(200, body, ctype, {"Cache-Control": "no-cache"})
def do_HEAD(self):
self.do_GET()
@@ -277,6 +293,8 @@ class Handler(BaseHTTPRequestHandler):
url = urllib.parse.urlsplit(self.path)
query = urllib.parse.parse_qs(url.query)
path = urllib.parse.unquote(url.path)
if not path.startswith(("/api/", "/file/")):
return self._web(path)
if not self._authorized(query):
return self._error(HTTPStatus.UNAUTHORIZED, "bad token")
try: