fix(naming): 修编码/位深/封面图/字节截断,来源改为读文件名
- 视频流选择跳过 attached_pic:内嵌封面(jpeg/png)不再被当成主画面, 否则编码与分辨率都会读错 - 编码不再「非 HEVC 即 H264」:补全 HEVC/H264/AV1/VP9/MPEG2/MPEG4/VC1/ProRes, 未知编码用 ffprobe 原名(实测 mpeg4 文件此前被标成 H264) - 位深区分 8bit/10bit/12bit(此前 12bit 会被标成 10bit) - 来源改为「读文件名 token」优先:REMUX/BluRay/BDRip/WEBRip/WEB-DL/HDTV/DVDRip, 没有 token 才回退码率判断。实测流参数猜来源与文件名一致率仅 33%, WEB-DL 与 WEBRip 无法从流特征区分 - media_title 改为按 UTF-8 字节截断(120 字节),避免 CJK 长标题撞 255 字节上限 - docs/naming.md 补充编码/位深/来源/截断规则
This commit is contained in:
+17
-2
@@ -12,7 +12,8 @@ class StringUtil:
|
||||
|
||||
# media_title 允许的最大字符数(留足技术标签,避免触碰文件系统 255 字节上限)
|
||||
MAX_MEDIA_TITLE = 120
|
||||
|
||||
# 字节上限:文件名总长受 255 字节限制,CJK 一个字 3 字节,不能只按字符截
|
||||
MAX_MEDIA_TITLE_BYTES = 120
|
||||
# 前后带空格的破折号(- – — −)整体视为分隔符 → 点
|
||||
# 例:Mission: Impossible - The Final Reckoning → Mission.Impossible.The.Final.Reckoning
|
||||
_SPACED_DASH = re.compile(r"\s+[-–—−]\s+")
|
||||
@@ -43,6 +44,19 @@ class StringUtil:
|
||||
s = re.sub(r"\.{2,}", ".", s)
|
||||
return s.strip(". -")
|
||||
|
||||
@staticmethod
|
||||
def truncate_bytes(text: str, limit: int) -> str:
|
||||
"""按 UTF-8 字节截断(不切坏多字节字符),末尾多余的点去掉。
|
||||
|
||||
文件系统上限是 255 字节,CJK 一个字占 3 字节,只按字符数截会超限。
|
||||
"""
|
||||
if not text:
|
||||
return ""
|
||||
raw = text.encode("utf-8")
|
||||
if len(raw) <= limit:
|
||||
return text
|
||||
return raw[:limit].decode("utf-8", errors="ignore").rstrip(". ")
|
||||
|
||||
@staticmethod
|
||||
def media_title(title: str, fallback: str = "") -> str:
|
||||
"""生成可直接用作文件名的标题:白名单清洗 + 超长截断。
|
||||
@@ -52,7 +66,8 @@ class StringUtil:
|
||||
for candidate in (title, fallback):
|
||||
s = StringUtil.sanitize_title(candidate)
|
||||
if s:
|
||||
return s[:StringUtil.MAX_MEDIA_TITLE].strip(".")
|
||||
s = s[:StringUtil.MAX_MEDIA_TITLE]
|
||||
return StringUtil.truncate_bytes(s, StringUtil.MAX_MEDIA_TITLE_BYTES).strip('.')
|
||||
return ""
|
||||
|
||||
class FFprobeUtil:
|
||||
|
||||
Reference in New Issue
Block a user