- Shared moderated MP3 profile music (with floating mini-player and MediaSession controls, zero bubble when absent) - AI video dubbing into Russian with burned-in ASS subtitles inside AgentChat (`services/members/dub.py`) - Picture-in-Picture 9:16 and background audio playback (`PlayControl` + `play_patch.py`) - System/custom .ttf fonts & emoji packs (`FontsAndEmoji`), account cleaner (`AccountCleaner`) - Feed blacklist, muted sound restoration, OLED burn-in shift, A/B flag editor, presets, long comments - Updated site homepage (`src/web/index.html`) for LihonT 2.3.0 Serena
79 lines
3.2 KiB
Python
79 lines
3.2 KiB
Python
import importlib.util
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
MEMBERS_DIR = ROOT / "services" / "members"
|
|
if str(MEMBERS_DIR) not in sys.path:
|
|
sys.path.insert(0, str(MEMBERS_DIR))
|
|
|
|
SPEC = importlib.util.spec_from_file_location("members_server", MEMBERS_DIR / "server.py")
|
|
try:
|
|
server = importlib.util.module_from_spec(SPEC)
|
|
SPEC.loader.exec_module(server)
|
|
except ModuleNotFoundError:
|
|
server = None
|
|
|
|
DUB_SPEC = importlib.util.spec_from_file_location("members_dub", MEMBERS_DIR / "dub.py")
|
|
try:
|
|
dub = importlib.util.module_from_spec(DUB_SPEC)
|
|
DUB_SPEC.loader.exec_module(dub)
|
|
except ModuleNotFoundError:
|
|
dub = None
|
|
|
|
|
|
@unittest.skipIf(server is None or dub is None, "private moderation module excluded")
|
|
class DubTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(self.tmp.cleanup)
|
|
self.now = 1_790_000_000
|
|
self.registry = server.Registry(Path(self.tmp.name) / "r.sqlite3", clock=lambda: self.now)
|
|
self.registry.dub.run_async = False
|
|
self.inst = "c" * 64
|
|
self._sign_in(555000, self.inst)
|
|
|
|
def _sign_in(self, tg_id, installation):
|
|
token = self.registry.accounts.call("tg_start", {"installation": installation})["token"]
|
|
self.assertTrue(self.registry.accounts.bot_link(token, tg_id)["ok"])
|
|
self.assertEqual("linked", self.registry.accounts.call("tg_poll", {"installation": installation, "token": token})["status"])
|
|
|
|
def test_extract_url_and_ass_generation(self):
|
|
self.assertEqual(
|
|
"https://vt.tiktok.com/ZSr123abc/",
|
|
dub.extract_tiktok_url("озвучь пожалуйста https://vt.tiktok.com/ZSr123abc/ срочно"),
|
|
)
|
|
self.assertIsNone(dub.extract_tiktok_url("просто текст без ссылки https://youtube.com/watch?v=1"))
|
|
|
|
ass = dub.build_ass([{"start": 0.5, "end": 2.25, "ru": "Привет\\мир"}], 1080, 1920)
|
|
self.assertIn("PlayResX: 1080", ass)
|
|
self.assertIn("PlayResY: 1920", ass)
|
|
self.assertIn("Dialogue: 0,0:00:00.50,0:00:02.25,Default,,0,0,0,,Привет мир", ass)
|
|
|
|
def test_parse_translation_json(self):
|
|
raw = '```json\n[{"i":0,"ru":"Первая строка"},{"i":1,"ru":"Вторая"}]\n```'
|
|
out = dub.parse_translation_json(raw, 2)
|
|
self.assertEqual(["Первая строка", "Вторая"], out)
|
|
|
|
def test_start_and_status_lifecycle(self):
|
|
with self.assertRaises(ValueError):
|
|
self.registry.dub.start({"installation": self.inst, "url": "not a link"})
|
|
|
|
started = self.registry.dub.start({"installation": self.inst, "url": "https://www.tiktok.com/@bob/video/7123456789"})
|
|
job_id = started["job_id"]
|
|
self.assertEqual("queued", started["status"])
|
|
|
|
st = self.registry.dub.status({"installation": self.inst, "job_id": job_id})
|
|
self.assertEqual("queued", st["status"])
|
|
|
|
# Another installation cannot inspect someone else's job.
|
|
self._sign_in(999111, "d" * 64)
|
|
with self.assertRaises(ValueError):
|
|
self.registry.dub.status({"installation": "d" * 64, "job_id": job_id})
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|