anbeime/skill / skills/native-subtitle-quote-image/native-subtitle-quote-image
native-subtitle-quote-image
Verified将本地视频或用户有权处理的在线视频,经过来源获取、文字稿定位、选题选句、精确取帧、紧凑裁切、拼图和逐张质检,制作成 3:4 或保留画面原比例的视频字幕长图。支持两种明确分开的输出:保留画面内已烧录字幕的原生字幕模式,以及把已审核的时间点与台词绘制到真实视频帧上的脚本字幕模式。用户要求原生字幕截图、字幕帧拼图、YouTube 金句长图、台词截图、不重绘字幕、自定义中文台词,或调整主图比例、字幕区域、台词间隔和美感时使用。
tests/test_text_encoding.py
View on GitHubimport ast
import importlib.util
import unittest
from pathlib import Path
from unittest import mock
ROOT = Path(__file__).resolve().parents[1]
ENV_SCRIPT = (
ROOT / "skills" / "native-subtitle-quote-image" / "scripts" / "check_environment.py"
)
SPEC = importlib.util.spec_from_file_location("check_environment", ENV_SCRIPT)
MODULE = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(MODULE)
SOURCE_DIRS = ("skills/native-subtitle-quote-image/scripts", "scripts", "tests")
def keyword_names(call):
return {keyword.arg for keyword in call.keywords}
def missing_encoding(call):
"""返回未显式指定编码的文本 I/O 调用描述,否则返回 None。"""
func = call.func
name = func.attr if isinstance(func, ast.Attribute) else getattr(func, "id", "")
keywords = keyword_names(call)
if name in ("read_text", "write_text") and "encoding" not in keywords:
return name
if name == "open" and not ast.unparse(func).endswith("Image.open"):
# Path.open(mode) 或内置 open(path, mode):二进制模式无需编码。
mode_args = [a for a in call.args if isinstance(a, ast.Constant) and isinstance(a.value, str)]
mode = next((k.value.value for k in call.keywords if k.arg == "mode"), None)
modes = [m.value for m in mode_args] + ([mode] if isinstance(mode, str) else [])
if not any("b" in m for m in modes) and "encoding" not in keywords:
if not (isinstance(func, ast.Name) and not call.args):
return name
if name == "run" and "text" in keywords and "encoding" not in keywords:
return "subprocess.run(text=True)"
return None
class TextEncodingTests(unittest.TestCase):
def test_utf8_default_detection(self):
with mock.patch.object(MODULE.sys, "flags", mock.Mock(utf8_mode=1)):
self.assertTrue(MODULE.utf8_default())
with mock.patch.object(MODULE.sys, "flags", mock.Mock(utf8_mode=0)):
with mock.patch.object(MODULE.locale, "getpreferredencoding", return_value="cp936"):
self.assertFalse(MODULE.utf8_default())
with mock.patch.object(MODULE.locale, "getpreferredencoding", return_value="UTF-8"):
self.assertTrue(MODULE.utf8_default())
def test_non_utf8_default_adds_hint_row(self):
with mock.patch.object(MODULE, "utf8_default", return_value=False):
rows = MODULE.inspect_environment()
row = next(r for r in rows if r["component"] == "UTF-8 encoding")
self.assertIn("PYTHONUTF8=1", row["detail"])
self.assertFalse(MODULE.is_blocking(row, True, True))
def test_no_implicit_locale_text_io(self):
problems = []
for directory in SOURCE_DIRS:
for path in sorted((ROOT / directory).glob("*.py")):
tree = ast.parse(path.read_text(encoding="utf-8"))
for node in ast.walk(tree):
if isinstance(node, ast.Call):
found = missing_encoding(node)
if found:
problems.append(f"{path.relative_to(ROOT)}:{node.lineno} {found}")
self.assertEqual(problems, [])
if __name__ == "__main__":
unittest.main()
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |