feat: DramaBox 全量走 App 接口,清单可停止并避免卡死

分类按 App 翻页,精选走推荐接口。清单顶部显示进度,停止后不再拉新剧,已拿到的封面继续加载。列表只绘制可见卡片,避免大量剧目占满主线程。
This commit is contained in:
Nixevol
2026-10-24 03:03:27 +08:00
parent 241762451c
commit cea741eead
25 changed files with 2923 additions and 1070 deletions
+14 -8
View File
@@ -70,6 +70,7 @@ class DownloadManager:
read_cover=None,
current_auth=None,
headers: dict | None = None,
prepare_file=None,
) -> None:
self._lock = threading.Lock()
self._jobs: dict[str, dict] = {}
@@ -83,6 +84,7 @@ class DownloadManager:
self._read_cover_fn = read_cover
self._current_auth = current_auth
self._headers = dict(headers or {})
self._prepare_file = prepare_file
self._worker_limit = DEFAULT_WORKERS
self._alive_workers = 0
self._wake = threading.Event()
@@ -723,18 +725,22 @@ class DownloadManager:
self._set_phase(drama_id, row["cid"], "downloading")
source_dir.mkdir(parents=True, exist_ok=True)
target = source_dir / "video.mp4"
if not target.is_file() or target.stat().st_size <= 0:
http.download_file(
row["src"],
target,
on_chunk=lambda size, job_id=drama_id: self._note_bytes(job_id, size),
stop=lambda job_id=drama_id: self._stopped(job_id),
headers=self._headers or None,
)
# 成品不存在时,半截文件重新下,不把不完整的视频当成已经下完。
if target.is_file():
target.unlink()
http.download_file(
row["src"],
target,
on_chunk=lambda size, job_id=drama_id: self._note_bytes(job_id, size),
stop=lambda job_id=drama_id: self._stopped(job_id),
headers=self._headers or None,
)
if self._stopped(drama_id):
raise RuntimeError("已停止")
if not target.is_file() or target.stat().st_size <= 0:
raise RuntimeError("试看文件没有下下来")
if self._prepare_file is not None:
self._prepare_file(target)
mp4_path.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(target, mp4_path)
if not has_audio(mp4_path):