feat: 添加开关,允许尝试下载未充电的视频 (#666)
This commit is contained in:
@@ -50,6 +50,8 @@ pub struct Config {
|
||||
pub concurrent_limit: ConcurrentLimit,
|
||||
pub time_format: String,
|
||||
pub cdn_sorting: bool,
|
||||
#[serde(default)]
|
||||
pub try_upower_anyway: bool,
|
||||
pub version: u64,
|
||||
}
|
||||
|
||||
@@ -131,6 +133,7 @@ impl Default for Config {
|
||||
concurrent_limit: ConcurrentLimit::default(),
|
||||
time_format: default_time_format(),
|
||||
cdn_sorting: false,
|
||||
try_upower_anyway: false,
|
||||
version: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +120,12 @@ impl VideoInfo {
|
||||
|
||||
/// 填充视频详情时调用,该方法会将视频详情附加到原有的 Model 上
|
||||
/// 特殊地,如果在检测视频更新时记录了 favtime,那么 favtime 会维持原样,否则会使用 pubtime 填充
|
||||
pub fn into_detail_model(self, base_model: bili_sync_entity::video::Model) -> bili_sync_entity::video::ActiveModel {
|
||||
/// 如果开启 try_upower_anyway,标记视频状态时不再检测是否充电,一律进入后面的下载环节
|
||||
pub fn into_detail_model(
|
||||
self,
|
||||
base_model: bili_sync_entity::video::Model,
|
||||
try_upower_anyway: bool,
|
||||
) -> bili_sync_entity::video::ActiveModel {
|
||||
match self {
|
||||
VideoInfo::Detail {
|
||||
title,
|
||||
@@ -154,7 +159,9 @@ impl VideoInfo {
|
||||
// 2. 都为 false,表示视频是非充电视频
|
||||
// redirect_url 仅在视频为番剧、影视、纪录片等特殊视频时才会有值,如果为空说明是普通视频
|
||||
// 仅在三种条件都满足时,才认为视频是可下载的
|
||||
valid: Set(state == 0 && (is_upower_exclusive == is_upower_play) && redirect_url.is_none()),
|
||||
valid: Set(state == 0
|
||||
&& (try_upower_anyway || (is_upower_exclusive == is_upower_play))
|
||||
&& redirect_url.is_none()),
|
||||
upper_id: Set(upper.mid),
|
||||
upper_name: Set(upper.name),
|
||||
upper_face: Set(upper.face),
|
||||
|
||||
@@ -150,7 +150,7 @@ pub async fn fetch_video_details(
|
||||
.map(|p| p.into_active_model(video_model.id))
|
||||
.collect::<Vec<page::ActiveModel>>();
|
||||
// 更新 video model 的各项有关属性
|
||||
let mut video_active_model = view_info.into_detail_model(video_model);
|
||||
let mut video_active_model = view_info.into_detail_model(video_model, config.try_upower_anyway);
|
||||
video_source.set_relation_id(&mut video_active_model);
|
||||
video_active_model.single_page = Set(Some(pages.len() == 1));
|
||||
video_active_model.tags = Set(Some(tags.into()));
|
||||
|
||||
Reference in New Issue
Block a user