refactor: fake room routing moved to connect-time, fully decoupled from production
- server.py / main.py no longer reference fake_room at all (no import, no --fake-room flag, no _apply_fake_room) - Routing decision happens at connect time in DanmakuClient.start(): room_id == 1 dynamically imports fake_room.py and patches blivedm; any other room id returns immediately without touching fake_room - Switching back from room 1 to another room unpatches to real Bilibili - Production (packaged, no fake_room.py) is completely unaffected for normal room ids; room 1 without fake_room.py raises a clear error - Rebuild portable zip (83.9 MB)
This commit is contained in:
@@ -151,21 +151,6 @@ async def index_handler(request: web.Request) -> web.Response:
|
||||
return web.FileResponse(STATIC_DIR / "index.html")
|
||||
|
||||
|
||||
FAKE_ROOM_PORT = 8081 # fake_room.py default = bot web UI port (8080) + 1
|
||||
|
||||
|
||||
def _apply_fake_room(room_id: int) -> None:
|
||||
"""room_id == 1 routes to the local fake room (dev/testing); otherwise restore real Bilibili."""
|
||||
import importlib
|
||||
|
||||
fake = importlib.import_module("fake_room")
|
||||
if room_id == 1:
|
||||
fake.patch_blivedm(FAKE_ROOM_PORT)
|
||||
logger.info("[dev] room 1 -> fake room on port %d", FAKE_ROOM_PORT)
|
||||
else:
|
||||
fake.unpatch_blivedm()
|
||||
|
||||
|
||||
async def api_start(request: web.Request) -> web.Response:
|
||||
try:
|
||||
config = await request.json()
|
||||
@@ -188,7 +173,6 @@ async def api_start(request: web.Request) -> web.Response:
|
||||
await tts_service.stop()
|
||||
except Exception:
|
||||
pass
|
||||
_apply_fake_room(room_id)
|
||||
tts_service.set_cookies(login_session.cookies if login_session.is_logged_in else None)
|
||||
try:
|
||||
await tts_service.start(config)
|
||||
@@ -316,8 +300,6 @@ def parse_args() -> argparse.Namespace:
|
||||
parser.add_argument("--port", "-p", type=int, default=8080)
|
||||
parser.add_argument("--host", type=str, default="127.0.0.1")
|
||||
parser.add_argument("--debug", "-d", action="store_true")
|
||||
parser.add_argument("--fake-room", type=int, default=0, metavar="PORT",
|
||||
help="connect to local fake_room.py instead of real Bilibili (dev/testing only)")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@@ -330,12 +312,6 @@ def main() -> int:
|
||||
)
|
||||
logging.getLogger("aiohttp.access").setLevel(logging.WARNING)
|
||||
|
||||
if args.fake_room:
|
||||
import importlib
|
||||
fake = importlib.import_module("fake_room")
|
||||
fake.patch_blivedm(args.fake_room)
|
||||
print(f" [dev] connected to fake room on port {args.fake_room}")
|
||||
|
||||
app = create_app()
|
||||
print(f"\n Bilibili Live → Yukkuri TTS Web UI")
|
||||
print(f" Open: http://{args.host}:{args.port}\n")
|
||||
|
||||
Reference in New Issue
Block a user