mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-06-27 18:32:43 +08:00
feat: 限制最多同时处理四个视频,支持收藏夹翻页下载
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
- [x] 支持并行下载
|
||||
- [x] 支持作为 daemon 运行
|
||||
- [x] 构建 nfo 和 poster 文件,方便以单集形式导入 emby
|
||||
- [x] 支持收藏夹翻页,下载全部历史视频
|
||||
- [ ] 添加下载进度条
|
||||
- [ ] 支持收藏夹翻页,下载全部历史视频
|
||||
- [ ] 对接数据库,提前检查,按需下载
|
||||
- [ ] 提供简单易用的打包(如 docker)
|
||||
|
||||
45
processor.py
45
processor.py
@@ -36,42 +36,47 @@ async def process():
|
||||
except Exception:
|
||||
logger.exception("Failed to refresh credential.")
|
||||
return
|
||||
favorite_ids, tasks = [], []
|
||||
for favorite_id in settings.favorite_ids:
|
||||
if favorite_id not in settings.path_mapper:
|
||||
logger.warning(f"Favorite {favorite_id} not in path mapper, ignored.")
|
||||
continue
|
||||
favorite_ids.append(favorite_id)
|
||||
tasks.append(process_favorite(favorite_id))
|
||||
favorite_result = await asyncio.gather(*tasks, return_exceptions=True)
|
||||
for idx, result in enumerate(favorite_result):
|
||||
if isinstance(result, Exception):
|
||||
logger.error("Failed to process favorite {}: {}", favorite_ids[idx], result)
|
||||
continue
|
||||
logger.info("Favorite {} processed successfully.", favorite_ids[idx])
|
||||
await process_favorite(favorite_id)
|
||||
|
||||
|
||||
async def process_favorite(favorite_id: int) -> None:
|
||||
save_path = Path(settings.path_mapper[favorite_id])
|
||||
save_path.mkdir(parents=True, exist_ok=True)
|
||||
favorite_video_list = await favorite_list.get_video_favorite_list_content(
|
||||
favorite_id, credential=credential
|
||||
)
|
||||
logger.info("start to process favorite {}", favorite_video_list["info"]["title"])
|
||||
medias = favorite_video_list["medias"][:4]
|
||||
tasks = [process_video(save_path, media) for media in medias]
|
||||
video_result = await asyncio.gather(*tasks, return_exceptions=True)
|
||||
for idx, result in enumerate(video_result):
|
||||
if isinstance(result, Exception):
|
||||
logger.error("Failed to process video {}: {}", medias[idx]["title"], result)
|
||||
page = 1
|
||||
while True:
|
||||
favorite_video_list = await favorite_list.get_video_favorite_list_content(
|
||||
favorite_id, page=page, credential=credential
|
||||
)
|
||||
if page == 1:
|
||||
logger.info(
|
||||
"start to process favorite {}: {}",
|
||||
favorite_id,
|
||||
favorite_video_list["info"]["title"],
|
||||
)
|
||||
for i in range(0, len(favorite_video_list["medias"]), 4):
|
||||
medias = favorite_video_list["medias"][i : i + 4]
|
||||
tasks = [process_video(save_path, media) for media in medias]
|
||||
video_result = await asyncio.gather(*tasks, return_exceptions=True)
|
||||
for idx, result in enumerate(video_result):
|
||||
if isinstance(result, Exception):
|
||||
logger.error(
|
||||
"Failed to process video {}: {}", medias[idx]["title"], result
|
||||
)
|
||||
if not favorite_video_list["has_more"]:
|
||||
return
|
||||
page += 1
|
||||
|
||||
|
||||
async def process_video(save_path: Path, media: dict) -> None:
|
||||
title = media["title"]
|
||||
logger.info("start to process video {}", title)
|
||||
if media["type"] != MediaType.VIDEO:
|
||||
logger.warning("Media {} is not a video, skipped.", title)
|
||||
return
|
||||
logger.info("start to process video {}", title)
|
||||
final_path = save_path / f"{title}.mp4"
|
||||
if final_path.exists():
|
||||
logger.info(f"{final_path} already exists, skipped.")
|
||||
|
||||
Reference in New Issue
Block a user