animekai.be fronted two server backends per episode: megaplay.buzz (same player/CDN family as hianime — 403s our egress IP) and my.1anime.site (direct progressive MP4, independent CDN — verified serving our IP at ~2.4MB/s). This is the rescue path around the MegaPlay Cloudflare block, per the ani-cli #1945/#1918 work. - providers/animekai.py: standard interface, per-episode backend dispatch (1anime first, then megaplay), same listed-but-dead -> raise semantics as hianime. All endpoints ride the shared TTL cache (no re-fetching on repeat UI hits). - upstream.py: megaplay_master() moved out of hianime — the MegaPlay chain (embed -> data-id -> getSourcesNew -> enc decrypt -> CDN proof) is now shared by every provider fronting that player. - app.py: /stream forwards Range for progressive files (206 + Content-Range passthrough, partial bodies never LRU-cached, 8MB cap on the parallel path so a 250MB MP4 can't pin RAM). api_stream reports hls=true/false from the URL — the player kind is a property of the URL, so future stream types slot in without app changes. - app.js: hls===false -> native <video> (existing Range-seeking), hls.js path untouched. - run.sh: ANI_SOURCE=animekai,hianime,anidb,anikoto (revert to the old chain when the MegaPlay block lifts). - tests: test_animekai.py (offline: interface, enc decrypt, /stream Range via monkeypatched network) + test_animekai_live.py (opt-in ANI_LIVE=1 end-to-end, skipped by default so the suite never touches animekai.be).
37 lines
1.9 KiB
Bash
Executable File
37 lines
1.9 KiB
Bash
Executable File
#!/bin/sh
|
|
# launch (or restart) the ani-web server
|
|
cd "$(dirname "$0")" || exit 1
|
|
[ -x .venv/bin/python ] || { echo "no .venv — run: uv venv .venv && uv pip install --python .venv/bin/python -r requirements.txt"; exit 1; }
|
|
|
|
# stop the old instance via its PID file. Only when no pid file exists (first
|
|
# boot under this scheme) fall back to pkill — and then PORT-SCOPED: the old
|
|
# global "uvicorn .*app:app" pattern also matched the throwaway test server
|
|
# (server.app:app --host 127.0.0.1 --port 8399), so an ani-web restart killed
|
|
# running test sessions, and a stray test server kept port 8321's holder alive.
|
|
PIDF=server.pid
|
|
if [ -f "$PIDF" ]; then
|
|
oldpid=$(cat "$PIDF" 2>/dev/null)
|
|
if [ -n "$oldpid" ] && kill -0 "$oldpid" 2>/dev/null; then
|
|
kill "$oldpid" 2>/dev/null
|
|
i=0
|
|
while kill -0 "$oldpid" 2>/dev/null && [ "$i" -lt 10 ]; do sleep 0.5; i=$((i + 1)); done
|
|
kill -9 "$oldpid" 2>/dev/null
|
|
fi
|
|
rm -f "$PIDF"
|
|
else
|
|
pkill -f "app:app --host 0.0.0.0 --port 8321" 2>/dev/null
|
|
sleep 1
|
|
fi
|
|
|
|
# ANIWEB_SECURE=1: session cookie is Secure — only usable via the HTTPS
|
|
# proxy (plain http://<this machine>:8321 can no longer hold a session).
|
|
# ANIWEB_TRUST_XFF=1: prod traffic arrives via the local HTTPS proxy, so the
|
|
# per-IP login budget keys on X-Forwarded-For; without the flag auth.py uses
|
|
# the socket peer only (the header is spoofable on a direct connection).
|
|
# ANI_SOURCE: animekai leads while MegaPlay's CDN 403s our egress IP (its
|
|
# 1anime servers use an independent CDN); the hianime/anidb/anikoto chain
|
|
# stays as fallback. Restore "hianime,anidb,anikoto" once the block lifts.
|
|
ANIWEB_SECURE=1 ANIWEB_TRUST_XFF=1 ANI_SOURCE=animekai,hianime,anidb,anikoto nohup .venv/bin/python -m uvicorn server.app:app --host 0.0.0.0 --port 8321 --timeout-graceful-shutdown 3 > server.log 2>&1 &
|
|
echo $! > "$PIDF"
|
|
echo "ani-web on http://localhost:8321 (pid $(cat "$PIDF")) — use the HTTPS proxy to log in"
|