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