#!/usr/bin/env python3
"""Force MiroTalk default zh-CN + nomadro loading/init UI (no MiroTalk chrome)."""
from __future__ import annotations
import re
import sys
from pathlib import Path
import paramiko
HOST = "82.157.112.245"
USER = "ubuntu"
PASS = "Xiao4669805"
BASE = "/opt/nomadro-services/mirotalk"
LOCAL_CSS = Path(__file__).with_name("nomadro-embed.css")
LOADING_HTML = """
正在进入活动厅
请允许摄像头 / 麦克风权限
游民社区 · nomadro
"""
QR_HTML = """
"""
def ssh() -> paramiko.SSHClient:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(
HOST, username=USER, password=PASS, timeout=30, allow_agent=False, look_for_keys=False
)
return c
def run(c: paramiko.SSHClient, cmd: str, timeout: int = 120) -> tuple[str, int]:
_i, o, e = c.exec_command(cmd, timeout=timeout)
out = o.read().decode("utf-8", "ignore")
err = e.read().decode("utf-8", "ignore")
return out + (("\n" + err) if err.strip() else ""), o.channel.recv_exit_status()
def write(c: paramiko.SSHClient, remote: str, data: str) -> None:
tmp = f"/tmp/{Path(remote).name}"
sftp = c.open_sftp()
with sftp.file(tmp, "w") as f:
f.write(data.encode("utf-8"))
sftp.close()
out, code = run(c, f"sudo mv {tmp} {remote} && sudo chmod 644 {remote}")
if code != 0:
raise RuntimeError(out)
def patch_config(text: str) -> str:
text = re.sub(r"language:\s*'en'", "language: 'zh-CN'", text, count=1)
text = re.sub(r"name:\s*'MiroTalk'", "name: 'nomadro'", text, count=1)
text = text.replace(
"customizeRoomButtonLabel: 'CUSTOMIZE ROOM'",
"customizeRoomButtonLabel: '自定义房间'",
)
text = text.replace(
"joinLastLabel: 'Your recent room:'",
"joinLastLabel: '最近房间:'",
)
# Chinese site titles (landing / client)
replacements = {
"landingTitle: 'MiroTalk a Free Secure Video Calls, Chat & Screen Sharing.'":
"landingTitle: 'nomadro 游民社区 · 线上视频厅'",
"newCallTitle: 'MiroTalk a Free Secure Video Calls, Chat & Screen Sharing.'":
"newCallTitle: 'nomadro 游民社区 · 线上视频厅'",
"newCallRoomTitle: 'Pick name.
Share URL.
Start conference.'":
"newCallRoomTitle: '进入房间
开始活动'",
"clientTitle: 'MiroTalk WebRTC Video call, Chat Room & Screen Sharing.'":
"clientTitle: 'nomadro 视频厅'",
"joinRoomTitle: 'Pick name.
Share URL.
Start conference.'":
"joinRoomTitle: '进入活动房间'",
"joinRoomButtonLabel: 'JOIN ROOM'":
"joinRoomButtonLabel: '进入房间'",
"loginTitle: 'MiroTalk - Host Protected login required.'":
"loginTitle: 'nomadro · 需要登录'",
"privacyPolicyTitle: 'MiroTalk - privacy and policy.'":
"privacyPolicyTitle: 'nomadro 隐私政策'",
"notFoundTitle: 'MiroTalk - 404 Page not found.'":
"notFoundTitle: '页面不存在'",
"waitingRoomTitle: 'MiroTalk - Waiting for host to start the meeting'":
"waitingRoomTitle: '等待主持人开始'",
"waitingRoomHeading: 'Waiting for host...'":
"waitingRoomHeading: '等待主持人…'",
"waitingRoomStatus: 'Checking room status...'":
"waitingRoomStatus: '检查房间状态…'",
"waitingRoomReady: 'Room is ready! Joining...'":
"waitingRoomReady: '房间已就绪,正在进入…'",
"waitingRoomWaiting: 'Waiting for host to start the meeting...'":
"waitingRoomWaiting: '等待主持人开始活动…'",
"waitingRoomHostLink: 'Are you the host?'":
"waitingRoomHostLink: '你是主持人?'",
"waitingRoomLoginLink: 'Login here'":
"waitingRoomLoginLink: '点此登录'",
"image: 'https://p2p.mirotalk.com/images/preview.png'":
"image: 'https://nomadro.cn/favicon.ico'",
"url: 'https://p2p.mirotalk.com'":
"url: 'https://nomadro.cn/social'",
}
for a, b in replacements.items():
text = text.replace(a, b)
return text
def patch_brand_js(text: str) -> str:
text = text.replace("language: 'en'", "language: 'zh-CN'", 1)
text = text.replace("name: 'MiroTalk'", "name: 'nomadro'", 1)
text = text.replace(
"title: 'MiroTalk
Free browser based Real-time video calls.
Simple, Secure, Fast.'",
"title: 'nomadro
游民社区 · 线上活动厅'",
1,
)
text = text.replace(
"clientTitle: 'MiroTalk WebRTC Video call, Chat Room & Screen Sharing.'",
"clientTitle: 'nomadro 视频厅'",
1,
)
# hide marketing sections in client-side fallback
for key in (
"topSponsors",
"features",
"browsers",
"teams",
"tryEasier",
"poweredBy",
"sponsors",
"pastSponsors",
"advertisers",
"supportUs",
"footer",
):
text = re.sub(rf"{key}:\s*true", f"{key}: false", text)
text = re.sub(
r"about:\s*\{[\s\S]*?\n \},",
"about: {\n"
" imageUrl: '../images/logo.svg',\n"
" title: 'nomadro 视频厅',\n"
" html: '游民社区 · 线上活动',\n"
" },",
text,
count=1,
)
return text
def patch_client_html(text: str) -> str:
text = text.replace('', '', 1)
text = re.sub(
r'[\s\S]*?
\s*\n\s*\n\s*',
LOADING_HTML + "\n\n ",
text,
count=1,
)
text = re.sub(
r'