fix: 修改状态码定义,修复单页视频封面错误
This commit is contained in:
@@ -159,24 +159,15 @@ pub async fn download_video_pages(
|
||||
downloader,
|
||||
base_path.join("poster.jpg"),
|
||||
)),
|
||||
// 分发分页下载的任务
|
||||
Box::pin(dispatch_download_page(
|
||||
seprate_status[1],
|
||||
bili_client,
|
||||
&video_model,
|
||||
pages,
|
||||
connection,
|
||||
downloader,
|
||||
)),
|
||||
// 生成视频信息的 nfo
|
||||
Box::pin(generate_video_nfo(
|
||||
seprate_status[2] && !is_single_page,
|
||||
seprate_status[1] && !is_single_page,
|
||||
&video_model,
|
||||
base_path.join("tvshow.nfo"),
|
||||
)),
|
||||
// 下载 Up 主头像
|
||||
Box::pin(fetch_upper_face(
|
||||
seprate_status[3],
|
||||
seprate_status[2],
|
||||
&video_model,
|
||||
downloader,
|
||||
&upper_mutex.0,
|
||||
@@ -184,11 +175,19 @@ pub async fn download_video_pages(
|
||||
)),
|
||||
// 生成 Up 主信息的 nfo
|
||||
Box::pin(generate_upper_nfo(
|
||||
seprate_status[4],
|
||||
seprate_status[3],
|
||||
&video_model,
|
||||
&upper_mutex.1,
|
||||
base_upper_path.join("person.nfo"),
|
||||
)),
|
||||
// 对于多页视频下载的任务,无论如何都会执行
|
||||
Box::pin(dispatch_download_page(
|
||||
bili_client,
|
||||
&video_model,
|
||||
pages,
|
||||
connection,
|
||||
downloader,
|
||||
)),
|
||||
];
|
||||
let results = futures::future::join_all(tasks).await;
|
||||
status.update_status(&results);
|
||||
@@ -199,16 +198,12 @@ pub async fn download_video_pages(
|
||||
}
|
||||
|
||||
pub async fn dispatch_download_page(
|
||||
should_run: bool,
|
||||
bili_client: &BiliClient,
|
||||
video_model: &video::Model,
|
||||
pages: Vec<page::Model>,
|
||||
connection: &DatabaseConnection,
|
||||
downloader: &Downloader,
|
||||
) -> Result<()> {
|
||||
if !should_run {
|
||||
return Ok(());
|
||||
}
|
||||
// 对于视频的分页,允许同时下载三个同时下载(绝大部分是单页视频)
|
||||
let child_semaphore = Semaphore::new(5);
|
||||
let mut tasks = FuturesUnordered::new();
|
||||
@@ -322,10 +317,16 @@ pub async fn fetch_page_poster(
|
||||
if !should_run {
|
||||
return Ok(());
|
||||
}
|
||||
// 如果单页没有封面,就使用视频的封面
|
||||
let url = match &page_model.image {
|
||||
Some(url) => url.as_str(),
|
||||
None => video_model.cover.as_str(),
|
||||
let single_page = video_model.single_page.unwrap();
|
||||
let url = if single_page {
|
||||
// 单页视频直接用视频的封面
|
||||
video_model.cover.as_str()
|
||||
} else {
|
||||
// 多页视频,如果单页没有封面,就使用视频的封面
|
||||
match &page_model.image {
|
||||
Some(url) => url.as_str(),
|
||||
None => video_model.cover.as_str(),
|
||||
}
|
||||
};
|
||||
downloader.fetch(url, &poster_path).await
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ impl From<Status> for u32 {
|
||||
}
|
||||
}
|
||||
|
||||
/// 从前到后分别表示:视频封面、分页下载、视频信息、Up 主头像、Up 主信息
|
||||
/// 从前到后分别表示:视频封面、视频信息、Up 主头像、Up 主信息
|
||||
#[derive(Clone)]
|
||||
pub struct VideoStatus(Status);
|
||||
|
||||
@@ -107,12 +107,15 @@ impl VideoStatus {
|
||||
}
|
||||
|
||||
pub fn should_run(&self) -> Vec<bool> {
|
||||
self.0.should_run(5)
|
||||
self.0.should_run(4)
|
||||
}
|
||||
|
||||
pub fn update_status(&mut self, result: &[Result<()>]) {
|
||||
assert!(result.len() == 5, "VideoStatus should have 5 status");
|
||||
self.0.update_status(result)
|
||||
assert!(
|
||||
result.len() >= 4,
|
||||
"VideoStatus should have 4 status, more status will be ignored"
|
||||
);
|
||||
self.0.update_status(&result[..4])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,8 +153,11 @@ impl PageStatus {
|
||||
}
|
||||
|
||||
pub fn update_status(&mut self, result: &[Result<()>]) {
|
||||
assert!(result.len() == 3, "PageStatus should have 3 status");
|
||||
self.0.update_status(result)
|
||||
assert!(
|
||||
result.len() >= 3,
|
||||
"PageStatus should have at least 3 status, more status will be ignored"
|
||||
);
|
||||
self.0.update_status(&result[..3])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user