The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
refactor(m3u8): 输出行解析改为公开方法 parseOutputLine
XiaoYouChR8033329b9042
diff --git a/features/m3u8_pack/task.py b/features/m3u8_pack/task.pyindex 2995de1c..201e43d4 100644--- a/features/m3u8_pack/task.py+++ b/features/m3u8_pack/task.py@@ -288,7 +288,7 @@ class M3U8TaskStep(TaskStep):return args- def _parseOutputLine(self, line: str):+ def parseOutputLine(self, line: str):text = line.strip()if not text:return@@ -342,13 +342,13 @@ class M3U8TaskStep(TaskStep):lines = buffer.split("\n")buffer = lines.pop()for line in lines:- self._parseOutputLine(line)+ self.parseOutputLine(line)# NonAnsiWriter 可能剥掉换行符,进度更新堆积在 buffer 里- self._parseOutputLine(buffer)+ self.parseOutputLine(buffer)if len(buffer) > 8192:buffer = buffer[-4096:]if buffer.strip():- self._parseOutputLine(buffer)+ self.parseOutputLine(buffer)self._processOutput = "".join(rawChunks)def _findOutputFile(self) -> bool:diff --git a/tests/test_m3u8_progress.py b/tests/test_m3u8_progress.pyindex 1c6acfaf..a4e96ffa 100644--- a/tests/test_m3u8_progress.py+++ b/tests/test_m3u8_progress.py@@ -1,6 +1,6 @@-"""M3U8TaskStep._parseOutputLine 的输出格式解析测试。+"""M3U8TaskStep.parseOutputLine 的输出格式解析测试。-Seam: _parseOutputLine — 输入一行 N_m3u8DL-RE stdout 文本,+Seam: parseOutputLine — 输入一行 N_m3u8DL-RE stdout 文本,观察 progress / speed / receivedBytes / task.fileSize 的更新。"""from __future__ import annotations@@ -32,7 +32,7 @@ class TestVodProgressV06:def test_with_sizes_no_spaces(self):step = makeStep()- step._parseOutputLine(+ step.parseOutputLine("Vid 1280x720 | 2000 Kbps ━━━━━━ 6/6857 0.09% 3.12MB/3.48GB1.55MBps01:27:07")assert step.progress == pytest.approx(0.09)@@ -42,7 +42,7 @@ class TestVodProgressV06:def test_dash_speed_only(self):step = makeStep()- step._parseOutputLine(+ step.parseOutputLine("Vid 1280x720 | 2000 Kbps ━━━━━━ 0/6857 0.00% -191.58KBps --:--:--")assert step.progress == pytest.approx(0.0)@@ -50,7 +50,7 @@ class TestVodProgressV06:def test_dash_speed_with_retries(self):step = makeStep()- step._parseOutputLine(+ step.parseOutputLine("Vid 1280x720 | 2000 Kbps ━━━━━━ 0/6857 0.00% -0.00Bps(9) --:--:--")assert step.progress == pytest.approx(0.0)@@ -58,7 +58,7 @@ class TestVodProgressV06:def test_zero_bps(self):step = makeStep()- step._parseOutputLine(+ step.parseOutputLine("Vid 1920x1080 | 6221 Kbps ━━━━━━ 0/64 0.00% -0.00Bps --:--:--")assert step.progress == pytest.approx(0.0)@@ -70,7 +70,7 @@ class TestVodProgressLegacy:def test_legacy_format(self):step = makeStep()- step._parseOutputLine(+ step.parseOutputLine("12/64 18.75% 12.34MB/56.78MB 1.23MBps 00:01:30")assert step.progress == pytest.approx(18.75)@@ -89,7 +89,7 @@ class TestConcatenatedBuffer:"Vid 1280x720 | 1650 Kbps | 30 ━━━━━━ 35/155 22.58% 30.99MB/137.26MB28.45MBps00:00:06""Vid 1280x720 | 1650 Kbps | 30 ━━━━━━ 100/155 64.52% 71.82MB/148.43MB40.83MBps00:00:02")- step._parseOutputLine(blob)+ step.parseOutputLine(blob)assert step.progress == pytest.approx(64.52)assert step.speed == toBytes("40.83", "MBps")assert step.receivedBytes == toBytes("71.82", "MB")@@ -98,7 +98,7 @@ class TestConcatenatedBuffer:def test_last_message_takes_tail(self):step = makeStep()filler = "x" * 2000- step._parseOutputLine(filler)+ step.parseOutputLine(filler)assert step.lastMessage == filler[-1000:]@@ -107,7 +107,7 @@ class TestLiveProgress:def test_basic(self):step = makeStep()- step._parseOutputLine(+ step.parseOutputLine("Vid ━━━━━━ 01m30s/02m00s 125/250 Recording 50% 1.55MBps")assert step.liveElapsed == "01m30s"@@ -118,7 +118,7 @@ class TestLiveProgress:def test_over_one_hour(self):step = makeStep()- step._parseOutputLine(+ step.parseOutputLine("Vid ━━━━━━ 01h05m30s/01h30m00s 3000/4500 Recording 66% 2.10MBps")assert step.liveElapsed == "01h05m30s"@@ -127,7 +127,7 @@ class TestLiveProgress:def test_waiting_with_dash_speed(self):step = makeStep()- step._parseOutputLine(+ step.parseOutputLine("Vid ━━━━━━ 00m00s/00m00s 0/0 Waiting 0% -")assert step.liveStatus == "Waiting"@@ -140,7 +140,7 @@ class TestLiveRecordProgress:def test_basic(self):step = makeStep()- step._parseOutputLine(+ step.parseOutputLine("Vid ━━━━━━ 01m30s/02m00s 130.00MB 125/250 Recording 1.55MBps")assert step.liveElapsed == "01m30s"@@ -151,7 +151,7 @@ class TestLiveRecordProgress:def test_over_one_hour(self):step = makeStep()- step._parseOutputLine(+ step.parseOutputLine("Vid ━━━━━━ 02h10m00s/02h15m30s 5.12GB 9000/9500 Recording 30.00MBps")assert step.liveElapsed == "02h10m00s"@@ -160,7 +160,7 @@ class TestLiveRecordProgress:def test_dash_speed(self):step = makeStep()- step._parseOutputLine(+ step.parseOutputLine("Vid ━━━━━━ 00m10s/00m30s 0.50MB 5/15 Recording -")assert step.liveStatus == "Recording"