Skip to content

Commit

Permalink
feat: 拷贝一份 poster 作为 fanart 使用 (#84)
Browse files Browse the repository at this point in the history
* feat: 拷贝一份 poster 作为 fanart 使用

* feat: 添加对于现有视频的迁移脚本
  • Loading branch information
amtoaer authored Apr 28, 2024
1 parent db62f55 commit 8d9266b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
37 changes: 37 additions & 0 deletions scripts/2.0.3_add_fanart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
2.0.2 -> 2.0.3 时添加了将 poster 拷贝为 fanart 的行为
该行为对已存在的视频不会生效,所以可以手动执行该脚本
具体来说,该脚本会:
1. 遍历命令行参数中所有存在的路径
2. 找到路径中所有以 poster.jpg 结尾的文件
3. 将 poster.jpg 替换为 fanart.jpg,拷贝到同一目录
"""

import os
import sys
import shutil
from pathlib import Path


def main():
if len(sys.argv) <= 1:
print("用法: python 2.0.3_add_fanart.py <path1> <path2> ...")
exit(1)
paths = [Path(path) for path in sys.argv[1:]]
for path in paths:
if not path.exists():
print(f"路径 {path} 不存在,跳过..")
continue
for root, _, files in os.walk(path):
for file in files:
if file.endswith("poster.jpg"):
poster_path = Path(root) / file
print(f"已找到 poster: {poster_path}")
fanart_path = Path(root) / file.replace("poster.jpg", "fanart.jpg")
shutil.copyfile(poster_path, fanart_path)
print(f"已将 {poster_path} 拷贝至 {fanart_path}")
print("操作完成")


if __name__ == "__main__":
main()
19 changes: 16 additions & 3 deletions src/core/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ pub async fn download_video_pages(
&video_model,
downloader,
base_path.join("poster.jpg"),
base_path.join("fanart.jpg"),
)),
// 生成视频信息的 nfo
Box::pin(generate_video_nfo(
Expand Down Expand Up @@ -390,12 +391,13 @@ pub async fn download_page(
"pid": page_model.pid,
}),
)?);
let (poster_path, video_path, nfo_path, danmaku_path) = if is_single_page {
let (poster_path, video_path, nfo_path, danmaku_path, fanart_path) = if is_single_page {
(
base_path.join(format!("{}-poster.jpg", &base_name)),
base_path.join(format!("{}.mp4", &base_name)),
base_path.join(format!("{}.nfo", &base_name)),
base_path.join(format!("{}.zh-CN.default.ass", &base_name)),
Some(base_path.join(format!("{}-fanart.jpg", &base_name))),
)
} else {
(
Expand All @@ -411,6 +413,8 @@ pub async fn download_page(
base_path
.join("Season 1")
.join(format!("{} - S01E{:0>2}.zh-CN.default.ass", &base_name, page_model.pid)),
// 对于多页视频,会在上一步 fetch_video_poster 中获取剧集的 fanart,无需在此处下载单集的
None,
)
};
let dimension = if page_model.width.is_some() && page_model.height.is_some() {
Expand All @@ -435,6 +439,7 @@ pub async fn download_page(
&page_model,
downloader,
poster_path,
fanart_path,
)),
Box::pin(fetch_page_video(
seprate_status[1],
Expand Down Expand Up @@ -487,6 +492,7 @@ pub async fn fetch_page_poster(
page_model: &page::Model,
downloader: &Downloader,
poster_path: PathBuf,
fanart_path: Option<PathBuf>,
) -> Result<()> {
if !should_run {
return Ok(());
Expand All @@ -502,7 +508,11 @@ pub async fn fetch_page_poster(
None => video_model.cover.as_str(),
}
};
downloader.fetch(url, &poster_path).await
downloader.fetch(url, &poster_path).await?;
if let Some(fanart_path) = fanart_path {
fs::copy(&poster_path, &fanart_path).await?;
}
Ok(())
}

pub async fn fetch_page_video(
Expand Down Expand Up @@ -589,11 +599,14 @@ pub async fn fetch_video_poster(
video_model: &video::Model,
downloader: &Downloader,
poster_path: PathBuf,
fanart_path: PathBuf,
) -> Result<()> {
if !should_run {
return Ok(());
}
downloader.fetch(&video_model.cover, &poster_path).await
downloader.fetch(&video_model.cover, &poster_path).await?;
fs::copy(&poster_path, &fanart_path).await?;
Ok(())
}

pub async fn fetch_upper_face(
Expand Down

0 comments on commit 8d9266b

Please sign in to comment.