The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
fix(m3u8): 修复清单后缀导致成品落盘失败 #1155
XiaoYouChR7232b0cb804f
diff --git a/dist/packs/m3u8_pack.zip b/dist/packs/m3u8_pack.zipindex d32e61d7..a65fe381 100644Binary files a/dist/packs/m3u8_pack.zip and b/dist/packs/m3u8_pack.zip differdiff --git a/features/m3u8_pack/manifest.toml b/features/m3u8_pack/manifest.tomlindex 13ddd9a0..ac0525c1 100644--- a/features/m3u8_pack/manifest.toml+++ b/features/m3u8_pack/manifest.toml@@ -2,5 +2,5 @@entry = "pack.py"class = "M3U8Pack"dependencies = ["ffmpeg_pack"]-version = "1.3.1"+version = "1.3.2"gdMinVersion = "4.5.0"diff --git a/features/m3u8_pack/pack.py b/features/m3u8_pack/pack.pyindex 45798875..d9d88a75 100644--- a/features/m3u8_pack/pack.py+++ b/features/m3u8_pack/pack.py@@ -19,7 +19,7 @@ from app.models.pack import FeaturePack, TaskParser, FileTypefrom app.models.task import PageTaskOptions, ResourceTaskOptions, Task, TaskOptionsfrom app.platform.filesystem import localFilePath, toSafeFilenamefrom .config import m3u8Config, m3u8Runtime-from .task import M3U8SubtitleStep, M3U8Task, M3U8TaskStep+from .task import MANIFEST_SUFFIXES, M3U8SubtitleStep, M3U8Task, M3U8TaskStepfrom .vimeo import buildVimeoFiles, matchVimeoPlaylistif TYPE_CHECKING:@@ -34,7 +34,6 @@ MEDIA_SUFFIXES = {".m3u8", ".m3u", ".mpd", ".mp4", ".mkv",".ts", ".webm", ".m4a", ".m4v", ".vtt", ".srt",}-MANIFEST_SUFFIXES = {".m3u8", ".m3u", ".mpd"}MANIFEST_CONTENT_TYPES = {"application/vnd.apple.mpegurl", "application/x-mpegurl", "application/mpegurl","audio/mpegurl", "audio/x-mpegurl", "application/dash+xml"}# Only the tags we read: m3u8 crashes on vendor attributes in other tags, which RFC 8216 says to ignore.diff --git a/features/m3u8_pack/task.py b/features/m3u8_pack/task.pyindex 7103c221..8c708d4f 100644--- a/features/m3u8_pack/task.py+++ b/features/m3u8_pack/task.py@@ -31,6 +31,7 @@ LIVE_PROGRESS_PATTERN = re.compile(LIVE_RECORD_PATTERN = re.compile(rf"({_DURATION})/({_DURATION})\s+\d+\.\d+(?:KB|MB|GB|B)\s+\d+/\d+\s+(Recording|Waiting)\s+(-|{_SPEED})")+MANIFEST_SUFFIXES = {".m3u8", ".m3u", ".mpd"}IGNORED_OUTPUT_SUFFIXES = {".json", ".txt", ".log", ".tmp", ".ghd"}DECRYPTION_ENGINES = {"FFmpeg": "FFMPEG",@@ -138,6 +139,13 @@ class M3U8Task(Task):return step.key in self.subtitleLanguagesreturn True+ def setName(self, name: str) -> None:+ suffix = Path(name).suffix+ if suffix.lower() in MANIFEST_SUFFIXES:+ targetSuffix = Path(self.name).suffix or (".ts" if self.isLive else ".mp4")+ name = f"{name[:-len(suffix)]}{targetSuffix}"+ super().setName(name)+def setOptions(self, options: dict) -> None:previousPaths = [(step, step.outputPath) for step in self.steps]super().setOptions(options)@@ -427,14 +435,11 @@ class M3U8TaskStep(TaskStep):(c for c in self.task.partPath.glob("*")if c.is_file() and c.suffix.lower() not in IGNORED_OUTPUT_SUFFIXESand c.name.lower().startswith(prefix)),- key=lambda c: c.stat().st_mtime,+ key=lambda c: (c.suffix.lower() == target.suffix.lower(), c.stat().st_mtime),default=None,)if found is None:return False- if found.suffix.lower() != target.suffix.lower():- raise TaskError("N_m3u8DL-RE 输出了 {actual} 文件,与任务的 {expected} 不符",- actual=found.suffix, expected=target.suffix)self.task.fileSize = max(self.task.fileSize, found.stat().st_size)os.replace(found, target)return Truediff --git a/tests/m3u8_pack/test_task.py b/tests/m3u8_pack/test_task.pynew file mode 100644index 00000000..9c91ecaa--- /dev/null+++ b/tests/m3u8_pack/test_task.py@@ -0,0 +1,33 @@+from __future__ import annotations++from pathlib import Path++from features.m3u8_pack.task import M3U8Task, M3U8TaskStep+++def buildTask(name: str = "test.mp4", *, isLive: bool = False) -> M3U8Task:+ task = M3U8Task(name=name, url="http://test", fileSize=1, outputFolder=Path("."), isLive=isLive)+ task.addStep(M3U8TaskStep(stepIndex=1))+ return task+++def test_set_name_replaces_manifest_suffix():+ vod = buildTask()+ vod.setName("clip.m3u8")+ assert vod.name == "clip.mp4"++ vod.setName("clip.MPD")+ assert vod.name == "clip.mp4"++ live = buildTask("live.ts", isLive=True)+ live.setName("channel.m3u8")+ assert live.name == "channel.ts"+++def test_set_name_keeps_non_manifest_suffix():+ task = buildTask()+ task.setName("clip.mkv")+ assert task.name == "clip.mkv"++ task.setName("clip")+ assert task.name == "clip"diff --git a/versions.json b/versions.jsonindex c8a12ea4..e3e145ba 100644--- a/versions.json+++ b/versions.json@@ -100,9 +100,9 @@"gdMinVersion": "4.5.0"},"m3u8_pack": {- "version": "1.3.1",+ "version": "1.3.2","file": "m3u8_pack.zip",- "sha256": "8a5cd3f94314e8e90317dc7f836dc31bff4b8caa44847a43d2fe1d5eb1322260",+ "sha256": "256ff6ea4069dec8bcdc27992fb99be541feb03994105a766ba08a83bb70c223","gdMinVersion": "4.5.0"},"yt_dlp_pack": {