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