路径跨平台兼容优化 - 修改相对路径,兼容Windows/Linux/Mac

This commit is contained in:
Tony Zhang
2025-12-15 16:58:44 +08:00
parent 54fff30ee0
commit da721ad8e2
5 changed files with 39 additions and 28 deletions

View File

@@ -18,20 +18,25 @@ logger = logging.getLogger(__name__)
FFMPEG_PATH = str(config.BASE_DIR / "bin" / "ffmpeg") if (config.BASE_DIR / "bin" / "ffmpeg").exists() else "ffmpeg"
FFPROBE_PATH = str(config.BASE_DIR / "bin" / "ffprobe") if (config.BASE_DIR / "bin" / "ffprobe").exists() else "ffprobe"
# 字体路径优先使用项目自带中文字体,其次使用 Linux 系统字体,最后再回退到 macOS 路径
# 字体路径优先使用项目内置字体,然后按平台回退到系统字体
DEFAULT_FONT_PATHS = [
# 优先使用 Linux 系统级中文字体 (服务器环境最稳健)
"/usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf",
"/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc",
# 项目内字体 (注意:需确保文件不是 LFS 指针)
# 优先使用项目内置字体 (跨平台通用)
str(config.FONTS_DIR / "NotoSansSC-Regular.otf"),
str(config.FONTS_DIR / "HarmonyOS-Sans-SC-Regular.ttf"),
str(config.FONTS_DIR / "AlibabaPuHuiTi-Regular.ttf"),
# macOS 字体(仅本地调试生效)
# Linux 系统字体
"/usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf",
"/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc",
"/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc",
# macOS 系统字体
"/System/Library/Fonts/PingFang.ttc",
"/System/Library/Fonts/STHeiti Medium.ttc",
"/System/Library/Fonts/Supplemental/Arial Unicode.ttf",
# Windows 系统字体
"C:/Windows/Fonts/msyh.ttc",
"C:/Windows/Fonts/simhei.ttf",
]
@@ -495,12 +500,8 @@ def add_multiple_subtitles(
return output_path
default_style = default_style or {}
# 强制使用完整字体(先用项目内 NotoSansSC如果不存在则回退 Droid
font = "/root/video-flow/assets/fonts/NotoSansSC-Regular.otf"
if not (os.path.exists(font) and os.path.getsize(font) > 1024 * 100): # 至少100KB以上认为有效
font = "/usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf"
if not (os.path.exists(font) and os.path.getsize(font) > 1024 * 100):
font = _get_font_path()
# 使用统一的字体查找逻辑(跨平台兼容
font = _get_font_path()
print(f"[SubDebug] Using font for subtitles: {font}", flush=True)