feat: LiveSub 2차 — 자막 on/off, 모니터·위치 선택, GPU 저부하, 게임 용어집

이름을 Hearo → LiveSub 로 변경. 말장난보다 하는 일이 바로 보이는 쪽이 낫다.

자막 on/off
- 전역 단축키 Ctrl+Alt+S (자막) / Ctrl+Alt+D (번역) — Windows RegisterHotKey +
  네이티브 이벤트 필터라 게임 창이 떠 있어도 동작. 다른 OS 에서는 no-op
- 단축키·체크박스·우클릭 메뉴가 모두 같은 경로를 타도록 통합

모니터 선택 + 디스코드식 배치
- placement.py: Qt 비의존 배치 계산 (모니터 목록 → 9분할 좌표)
- AnchorGrid 위젯으로 3x3 위치 선택, 드래그하면 자유 배치로 전환
- 모니터 구성이 바뀌어도 자막이 화면 밖으로 사라지지 않도록 클램프

GPU 저부하 모드 (기본 켜짐)
- 연산 정밀도 int8 강등, VRAM 상한 35%, 추론 후 60ms 양보,
  300초 무음 시 모델 언로드, 중간 결과 비활성
- 기본 티어를 균형(6GB) → 신속(4GB) 으로 하향
- 8GB GPU 기준 자막 2.8GB / 게임 5.2GB

게임 용어집 번들 (304개)
- 롤 74 · 발로란트 59 · 오버워치2 49 · FPS공통 46 · 마크 38 · 방송 38
- 체크박스로 켜고 끄며, 사용자가 직접 등록한 항목이 항상 우선

검증: pytest 91개 통과 (배치 14 + 팩 12 + UI 6 신규), ruff clean

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-09-21 17:49:26 +09:00
parent 5596f905d1
commit 8b36b244ff
60 changed files with 1939 additions and 300 deletions

92
tests/test_packs.py Normal file
View File

@@ -0,0 +1,92 @@
"""기본 제공 게임 용어집 팩."""
from __future__ import annotations
from livesub.constants import LANGUAGE_CODES
from livesub.models.glossary import Glossary, GlossaryEntry
from livesub.models.packs import available_packs, build_glossary, get_pack
EXPECTED_PACKS = {"lol", "valorant", "overwatch", "fps-common", "minecraft", "streaming"}
def test_bundled_packs_are_loadable():
keys = {p.key for p in available_packs()}
assert keys >= EXPECTED_PACKS, f"빠진 팩: {EXPECTED_PACKS - keys}"
def test_every_pack_has_entries_and_metadata():
for pack in available_packs():
assert pack.name, pack.key
assert pack.description, pack.key
assert len(pack) >= 30, f"{pack.key} 는 용어가 너무 적습니다 ({len(pack)}개)"
def test_every_entry_has_a_korean_target():
"""주 용도가 '외국어 → 한국어' 이므로 한국어 역어는 반드시 있어야 한다."""
for pack in available_packs():
for entry in pack.entries:
assert entry.target_for("ko"), f"{pack.key}: {entry.source} 에 한국어 역어 없음"
def test_targets_only_use_supported_languages():
for pack in available_packs():
for entry in pack.entries:
unknown = set(entry.targets) - set(LANGUAGE_CODES)
assert not unknown, f"{pack.key}: {entry.source} 에 미지원 언어 {unknown}"
def test_no_duplicate_sources_inside_a_pack():
for pack in available_packs():
seen = [e.source.casefold() for e in pack.entries]
dupes = {s for s in seen if seen.count(s) > 1}
assert not dupes, f"{pack.key} 에 중복 용어: {dupes}"
def test_known_terms_are_present():
lol = get_pack("lol")
sources = {e.source.casefold() for e in lol.entries}
assert {"baron", "gank", "nexus", "ult"} <= sources
valorant = get_pack("valorant")
sources = {e.source.casefold() for e in valorant.entries}
assert {"spike", "defuse", "eco", "retake"} <= sources
def test_get_pack_returns_none_for_unknown():
assert get_pack("no-such-game") is None
def test_build_glossary_merges_packs():
merged = build_glossary(Glossary(), ["lol"])
protected, repl = merged.protect("push to the Nexus", "ko")
# 'push' 와 'Nexus' 둘 다 LoL 팩에 있으므로 둘 다 잡힌다.
assert repl == ["푸시", "넥서스"]
assert "Nexus" not in protected
assert Glossary.restore(protected, repl) == "푸시 to the 넥서스"
def test_user_entry_beats_pack_entry():
"""기본 팩 역어가 마음에 안 들면 직접 등록한 것이 이겨야 한다."""
user = Glossary([GlossaryEntry("baron", {"ko": "바론둥이"})])
merged = build_glossary(user, ["lol"])
_, repl = merged.protect("baron", "ko")
assert repl == ["바론둥이"]
def test_unknown_pack_key_is_ignored_not_fatal():
merged = build_glossary(Glossary(), ["lol", "does-not-exist"])
assert len(merged) > 0
def test_multiple_packs_combine():
only_lol = build_glossary(Glossary(), ["lol"])
both = build_glossary(Glossary(), ["lol", "minecraft"])
assert len(both) > len(only_lol)
_, repl = both.protect("creeper", "ko")
assert repl == ["크리퍼"]
def test_no_packs_means_only_user_entries():
user = Glossary([GlossaryEntry("foo", {"ko": "푸"})])
merged = build_glossary(user, [])
assert len(merged) == 1