The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
refactor(i18n): Android 文案改按 N() 标记同步
XiaoYouChRe689240bdafb
diff --git a/features/bili_pack/android.py b/features/bili_pack/android.pyindex 68ecdd3b..62200a81 100644--- a/features/bili_pack/android.py+++ b/features/bili_pack/android.py@@ -3,7 +3,9 @@ from __future__ import annotationsimport jsonfrom dataclasses import dataclass-from typing import TYPE_CHECKING+from typing import TYPE_CHECKING, Any++from app.i18n import Nfrom .account import (QR_EXPIRED,@@ -97,8 +99,8 @@ def fileGroups(task: BilibiliTask) -> dict[int, list[str]]:}-def toDraftOptions(pairs: list[tuple[str, str]]) -> list[dict[str, str]]:- return [{"key": key, "label": label} for key, label in pairs]+def toDraftOptions(pairs: list[tuple[str, str]], **params: Any) -> list[dict]:+ return [{"key": key, "label": label, "params": params} for key, label in pairs]def activeTracks(task: BilibiliTask) -> set[str]:@@ -123,21 +125,21 @@ def draftFields(task: BilibiliTask) -> dict:"controls": [{"id": "video",- "title": "视频",+ "title": N("TrackBar", "视频"),"value": currentVideoTier(task) if task.isVideoEnabled else "","options": toDraftOptions(videoTiers(task)),"isOptional": bool(tracks - {"video"}),},{"id": "audio",- "title": "音频",+ "title": N("TrackBar", "音频"),"value": currentAudioTier(task) if task.isAudioEnabled else "","options": toDraftOptions(audioTiers(task)),"isOptional": bool(tracks - {"audio"}),},{"id": "danmaku",- "title": "弹幕",+ "title": N("BilibiliDraftCard", "弹幕"),"value": task.danmakuFormat,"options": toDraftOptions(DANMAKU_OPTIONS),"isOptional": bool(tracks - {"danmaku"}),@@ -145,7 +147,9 @@ def draftFields(task: BilibiliTask) -> dict:],"isCoverEnabled": task.isCoverEnabled,"hasCover": bool(task.coverUrl),- "subtitles": toDraftOptions(subtitleChoices(task)) if task.hasMedia else [],+ "subtitles": toDraftOptions(+ subtitleChoices(task, "{auto}"), auto=N("BilibiliDraftCard", "(自动生成)"),+ ) if task.hasMedia else [],"subtitleLanguages": list(task.subtitleLanguages),"duration": page._duration if page else 0,"startTime": page.startTime if page else 0,diff --git a/features/bili_pack/cards.py b/features/bili_pack/cards.pyindex e6f131a9..7c96ecaa 100644--- a/features/bili_pack/cards.py+++ b/features/bili_pack/cards.py@@ -460,7 +460,7 @@ class BilibiliDraftCard(MultiFileDraftCard):self._trackBar.audioButton.setTrackEnabled(False)self._trackBar.audioButton.setChecked(False)- self._subtitleChoices = subtitleChoices(task)+ self._subtitleChoices = subtitleChoices(task, self.tr("(自动生成)"))self._trackBar.subtitleButton.setTrackEnabled(bool(self._subtitleChoices))self._trackBar.coverButton.setTrackEnabled(bool(self._task.coverUrl))diff --git a/features/bili_pack/task.py b/features/bili_pack/task.pyindex 4d6ee560..45a11090 100644--- a/features/bili_pack/task.py+++ b/features/bili_pack/task.py@@ -7,7 +7,6 @@ from pathlib import Pathfrom app.models.task import Task, TaskError, TaskFile, TaskStep, TaskStatus, SpecialFileSize, deletePlaceholderfrom app.platform.filesystem import toSafeFilename-from app.i18n import Nfrom http_pack.task import HttpTaskStepfrom ffmpeg_pack.container import buildTimeSuffixfrom ffmpeg_pack.task import FFmpegResourceStep, FFmpegStep@@ -73,7 +72,7 @@ def currentAudioTier(task: BilibiliTask) -> str:)-def subtitleChoices(task: BilibiliTask) -> list[tuple[str, str]]:+def subtitleChoices(task: BilibiliTask, automaticLabel: str) -> list[tuple[str, str]]:seen = set()choices = []for page in task.files or []:@@ -84,7 +83,7 @@ def subtitleChoices(task: BilibiliTask) -> list[tuple[str, str]]:seen.add(lan)label = sub.get("lan_doc", lan)if sub.get("isAi"):- label += N("BilibiliDraftCard", "(自动生成)")+ label += automaticLabelchoices.append((lan, label))return choicesdiff --git a/features/m3u8_pack/android.py b/features/m3u8_pack/android.pyindex 96ea6ba6..032387c6 100644--- a/features/m3u8_pack/android.py+++ b/features/m3u8_pack/android.py@@ -31,7 +31,7 @@ def optionFields(task: M3U8Task) -> dict:def toStreamOptions(streams: list[dict]) -> list[dict[str, str]]:- options = [{"key": "", "label": "默认(最佳)"}]+ options = [{"key": "", "label": N("StreamSelectCard", "默认(最佳)")}]for stream in streams:width, height = stream.get("width", 0), stream.get("height", 0)details = [v for v in (stream.get("codecs") or "",diff --git a/features/yt_dlp_pack/android.py b/features/yt_dlp_pack/android.pyindex 15cb39f6..db2f283f 100644--- a/features/yt_dlp_pack/android.py+++ b/features/yt_dlp_pack/android.py@@ -3,6 +3,8 @@ from __future__ import annotationsfrom typing import TYPE_CHECKING, Any+from app.i18n import N+from .choices import buildAudioLanguageChoices, buildAudioTiers, buildSubtitleChoices, buildVideoTiersfrom .task import YouTubeFile, buildFormatPair, probeFormats, probePlaylist, parseLanguages@@ -30,21 +32,21 @@ def draftFields(task: YouTubeTask) -> dict:"controls": [{"id": "video",- "title": "视频",+ "title": N("TrackBar", "视频"),"value": str(task.maxVideoHeight) if task.isVideoEnabled else "",- "options": toDraftOptions(videoTiers, best="最佳画质"),+ "options": toDraftOptions(videoTiers, best=N("YtDlpDraftCard", "最佳画质")),"isOptional": task.isAudioEnabled,},{"id": "audio",- "title": "音频",+ "title": N("TrackBar", "音频"),"value": str(task.maxAudioBitrate) if task.isAudioEnabled else "",- "options": toDraftOptions(audioTiers, best="最佳音质"),+ "options": toDraftOptions(audioTiers, best=N("YtDlpDraftCard", "最佳音质")),"isOptional": task.isVideoEnabled,},{"id": "language",- "title": "音频语言",+ "title": N("YtDlpDraftCard", "音频语言"),"value": task.audioLanguages if task.isAudioEnabled else "","options": toDraftOptions(buildAudioLanguageChoices(info)),"isMultiple": True,@@ -53,7 +55,7 @@ def draftFields(task: YouTubeTask) -> dict:],"isCoverEnabled": task.isCoverEnabled,"hasCover": bool(task.coverUrl),- "subtitles": toDraftOptions(subtitles, auto="自动"),+ "subtitles": toDraftOptions(subtitles, auto=N("YtDlpDraftCard", "自动")),"subtitleLanguages": [s for s in task.subtitleLanguages.split(",") if s],"duration": int(info.get("duration") or 0) if not task.isPlaylist else 0,"startTime": page.startTime if page else 0,diff --git a/scripts/sync_i18n_res.py b/scripts/sync_i18n_res.pyindex 7bca4268..1633de13 100644--- a/scripts/sync_i18n_res.py+++ b/scripts/sync_i18n_res.py@@ -1,3 +1,4 @@+import astimport hashlibimport osimport re@@ -19,12 +20,6 @@ FALLBACK_LOCALE = "en_US"# Qt 按系统语言查 gd3.yue 找粤语,Crowdin 导出的粤语文件却叫 zh_HKEXTRA_FAMILY_ALIASES = {"yue": "zh_HK"}-ENGINE_CONTEXTS = [- "TaskErrors", "BinaryRuntime", "TaskState",- "TrackBar", "YtDlpDraftCard", "StreamSelectCard",- "Categories", "Presets",-]-ANDROID_RES_DIR = REPO / "android" / "app" / "src" / "main" / "res"ANDROID_I18N_KT = (REPO / "android" / "app" / "src" / "main" / "java" / "com" / "xychr"@@ -144,17 +139,30 @@ def toAndroidFolder(locale: str) -> Path | None:return None-def loadEngineCatalog(locale: str, fallback: dict[tuple[str, str], str]) -> dict[str, tuple[str, str, str]]:+def loadMarkedMessages(sources: list[str]) -> set[tuple[str, str]]:+ # 引擎交给 Android 显示的文案都在写出处用 N() 标记,按标记同步就不必列出 Pack 的类名+ marked = set()+ for source in sources:+ for node in ast.walk(ast.parse((REPO / source).read_text(encoding="utf-8"))):+ if (isinstance(node, ast.Call) and isinstance(node.func, ast.Name) and node.func.id == "N"+ and len(node.args) == 2 and all(isinstance(arg, ast.Constant) for arg in node.args)):+ marked.add((node.args[0].value, node.args[1].value))+ return marked+++def loadEngineCatalog(+ locale: str, fallback: dict[tuple[str, str], str], marked: set[tuple[str, str]],+) -> dict[str, tuple[str, str, str]]:translations = loadTranslations(locale)entries = {}root = ET.parse(I18N_DIR / f"gd3.{SOURCE_LOCALE}.ts").getroot()for context in root.findall("context"):contextName = context.findtext("name")- if contextName not in ENGINE_CONTEXTS:- continuefor message in context.findall("message"):source = message.findtext("source") or ""key = (contextName, source)+ if key not in marked:+ continuetext = source if locale == SOURCE_LOCALE else translations.get(key) or fallback.get(key)if source and text:digest = hashlib.sha1(source.encode("utf-8")).hexdigest()[:8]@@ -169,11 +177,11 @@ def escapeAndroidString(text: str) -> str:return text-def buildAndroidEngineStrings(locales: list[str]) -> None:+def buildAndroidEngineStrings(locales: list[str], marked: set[tuple[str, str]]) -> None:fallback = loadTranslations(FALLBACK_LOCALE)- source = loadEngineCatalog(SOURCE_LOCALE, fallback)+ source = loadEngineCatalog(SOURCE_LOCALE, fallback, marked)if not source:- raise SystemExit(f"No messages found for contexts {ENGINE_CONTEXTS}")+ raise SystemExit("No messages marked with N()")nameToSource = {}for name, (_, text, _) in source.items():@@ -185,7 +193,7 @@ def buildAndroidEngineStrings(locales: list[str]) -> None:folder = toAndroidFolder(locale)if folder is None:continue- entries = loadEngineCatalog(locale, fallback)+ entries = loadEngineCatalog(locale, fallback, marked)xmlLines = ["<!-- Generated by scripts/sync_i18n_res.py -->", "<resources>"]for resource in sorted(entries):text = escapeAndroidString(entries[resource][2])@@ -254,12 +262,13 @@ def buildResources() -> None:def main() -> int:- updateSourceTs(findSources())+ sources = findSources()+ updateSourceTs(sources)locales = findLocales()buildQmFiles(locales)updateQrcI18n(locales)if ANDROID_RES_DIR.exists():- buildAndroidEngineStrings(locales)+ buildAndroidEngineStrings(locales, loadMarkedMessages(sources))buildAndroidFallbackStrings(locales)buildResources()return 0