mirror of
https://github.com/lanyeeee/bilibili-video-downloader.git
synced 2026-09-08 17:16:52 +08:00
feat: 自定义目录格式新增画质、编码、音质字段
This commit is contained in:
@@ -103,7 +103,7 @@ impl DownloadProgress {
|
|||||||
|
|
||||||
let create_ts = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
|
let create_ts = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
|
||||||
|
|
||||||
let mut progress = Self {
|
let progress = Self {
|
||||||
task_id: Uuid::new_v4().to_string(),
|
task_id: Uuid::new_v4().to_string(),
|
||||||
episode_type: EpisodeType::Bangumi,
|
episode_type: EpisodeType::Bangumi,
|
||||||
aid: episode.aid,
|
aid: episode.aid,
|
||||||
@@ -134,10 +134,6 @@ impl DownloadProgress {
|
|||||||
completed_ts: None,
|
completed_ts: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
progress
|
|
||||||
.update_fmt_fields(&config)
|
|
||||||
.context("更新需要格式化的字段失败")?;
|
|
||||||
|
|
||||||
Ok(progress)
|
Ok(progress)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +150,7 @@ impl DownloadProgress {
|
|||||||
|
|
||||||
let create_ts = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
|
let create_ts = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
|
||||||
|
|
||||||
let mut progress = Self {
|
let progress = Self {
|
||||||
task_id: Uuid::new_v4().to_string(),
|
task_id: Uuid::new_v4().to_string(),
|
||||||
episode_type: EpisodeType::Cheese,
|
episode_type: EpisodeType::Cheese,
|
||||||
aid: episode.aid,
|
aid: episode.aid,
|
||||||
@@ -185,10 +181,6 @@ impl DownloadProgress {
|
|||||||
completed_ts: None,
|
completed_ts: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
progress
|
|
||||||
.update_fmt_fields(&config)
|
|
||||||
.context("更新需要格式化的字段失败")?;
|
|
||||||
|
|
||||||
Ok(progress)
|
Ok(progress)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +191,9 @@ impl DownloadProgress {
|
|||||||
let audio_completed = self.audio_task.completed;
|
let audio_completed = self.audio_task.completed;
|
||||||
|
|
||||||
if (!video_selected && !audio_selected) || (video_completed && audio_completed) {
|
if (!video_selected && !audio_selected) || (video_completed && audio_completed) {
|
||||||
// 如果视频和音频都没有选中,或者都已经完成,则不需要准备
|
// 如果视频和音频都没有选中,或者都已经完成,则更新需要格式化的字段就返回
|
||||||
|
self.update_fmt_fields(app)
|
||||||
|
.context("更新需要格式化的字段失败")?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,13 +256,17 @@ impl DownloadProgress {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.update_fmt_fields(app)
|
||||||
|
.context("更新需要格式化的字段失败")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_fmt_fields(&mut self, config: &Config) -> anyhow::Result<()> {
|
fn update_fmt_fields(&mut self, app: &AppHandle) -> anyhow::Result<()> {
|
||||||
let fmt_params = self.create_fmt_params();
|
let fmt_params = self.create_fmt_params();
|
||||||
|
|
||||||
let (episode_dir, filename) = fmt_params.get_episode_dir_and_filename(config)?;
|
let config = app.get_config().read().clone();
|
||||||
|
let (episode_dir, filename) = fmt_params.get_episode_dir_and_filename(&config)?;
|
||||||
|
|
||||||
self.episode_dir = episode_dir;
|
self.episode_dir = episode_dir;
|
||||||
self.filename = filename;
|
self.filename = filename;
|
||||||
@@ -294,6 +292,9 @@ impl DownloadProgress {
|
|||||||
up_name: self.up_name.clone(),
|
up_name: self.up_name.clone(),
|
||||||
up_uid: self.up_uid,
|
up_uid: self.up_uid,
|
||||||
create_ts: self.create_ts,
|
create_ts: self.create_ts,
|
||||||
|
video_quality: self.video_task.video_quality,
|
||||||
|
codec_type: self.video_task.codec_type,
|
||||||
|
audio_quality: self.audio_task.audio_quality,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,7 +363,7 @@ fn create_normal_progresses_for_single(
|
|||||||
let Some(page) = info.pages.iter().find(|p| p.cid == cid) else {
|
let Some(page) = info.pages.iter().find(|p| p.cid == cid) else {
|
||||||
return Err(anyhow!("找不到cid为`{cid}`的分P"));
|
return Err(anyhow!("找不到cid为`{cid}`的分P"));
|
||||||
};
|
};
|
||||||
let mut progress = DownloadProgress {
|
let progress = DownloadProgress {
|
||||||
task_id: Uuid::new_v4().to_string(),
|
task_id: Uuid::new_v4().to_string(),
|
||||||
episode_type: EpisodeType::Normal,
|
episode_type: EpisodeType::Normal,
|
||||||
aid: info.aid,
|
aid: info.aid,
|
||||||
@@ -393,16 +394,12 @@ fn create_normal_progresses_for_single(
|
|||||||
completed_ts: None,
|
completed_ts: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
progress
|
|
||||||
.update_fmt_fields(config)
|
|
||||||
.context("更新需要格式化的字段失败")?;
|
|
||||||
|
|
||||||
return Ok(vec![progress]);
|
return Ok(vec![progress]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.pages.len() == 1 {
|
if info.pages.len() == 1 {
|
||||||
// 如果只有一个分P,则直接创建一个progress
|
// 如果只有一个分P,则直接创建一个progress
|
||||||
let mut progress = DownloadProgress {
|
let progress = DownloadProgress {
|
||||||
task_id: Uuid::new_v4().to_string(),
|
task_id: Uuid::new_v4().to_string(),
|
||||||
episode_type: EpisodeType::Normal,
|
episode_type: EpisodeType::Normal,
|
||||||
aid: info.aid,
|
aid: info.aid,
|
||||||
@@ -433,16 +430,12 @@ fn create_normal_progresses_for_single(
|
|||||||
completed_ts: None,
|
completed_ts: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
progress
|
|
||||||
.update_fmt_fields(config)
|
|
||||||
.context("更新需要格式化的字段失败")?;
|
|
||||||
|
|
||||||
return Ok(vec![progress]);
|
return Ok(vec![progress]);
|
||||||
}
|
}
|
||||||
// 如果有多个分P,则为每个分P创建一个progress
|
// 如果有多个分P,则为每个分P创建一个progress
|
||||||
let mut progresses = Vec::new();
|
let mut progresses = Vec::new();
|
||||||
for page in &info.pages {
|
for page in &info.pages {
|
||||||
let mut progress = DownloadProgress {
|
let progress = DownloadProgress {
|
||||||
task_id: Uuid::new_v4().to_string(),
|
task_id: Uuid::new_v4().to_string(),
|
||||||
episode_type: EpisodeType::Normal,
|
episode_type: EpisodeType::Normal,
|
||||||
aid: info.aid,
|
aid: info.aid,
|
||||||
@@ -473,10 +466,6 @@ fn create_normal_progresses_for_single(
|
|||||||
completed_ts: None,
|
completed_ts: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
progress
|
|
||||||
.update_fmt_fields(config)
|
|
||||||
.context("更新需要格式化的字段失败")?;
|
|
||||||
|
|
||||||
progresses.push(progress);
|
progresses.push(progress);
|
||||||
}
|
}
|
||||||
Ok(progresses)
|
Ok(progresses)
|
||||||
@@ -514,7 +503,7 @@ fn create_normal_progresses_for_season(
|
|||||||
let Some(page) = ep.pages.iter().find(|p| p.cid == cid) else {
|
let Some(page) = ep.pages.iter().find(|p| p.cid == cid) else {
|
||||||
return Err(anyhow!("找不到cid为`{cid}`的分P"));
|
return Err(anyhow!("找不到cid为`{cid}`的分P"));
|
||||||
};
|
};
|
||||||
let mut progress = DownloadProgress {
|
let progress = DownloadProgress {
|
||||||
task_id: Uuid::new_v4().to_string(),
|
task_id: Uuid::new_v4().to_string(),
|
||||||
episode_type: EpisodeType::Normal,
|
episode_type: EpisodeType::Normal,
|
||||||
aid: ep.aid,
|
aid: ep.aid,
|
||||||
@@ -545,16 +534,12 @@ fn create_normal_progresses_for_season(
|
|||||||
completed_ts: None,
|
completed_ts: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
progress
|
|
||||||
.update_fmt_fields(config)
|
|
||||||
.context("更新需要格式化的字段失败")?;
|
|
||||||
|
|
||||||
return Ok(vec![progress]);
|
return Ok(vec![progress]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ep.pages.len() == 1 {
|
if ep.pages.len() == 1 {
|
||||||
// 如果只有一个分P,则直接创建一个progress
|
// 如果只有一个分P,则直接创建一个progress
|
||||||
let mut progress = DownloadProgress {
|
let progress = DownloadProgress {
|
||||||
task_id: Uuid::new_v4().to_string(),
|
task_id: Uuid::new_v4().to_string(),
|
||||||
episode_type: EpisodeType::Normal,
|
episode_type: EpisodeType::Normal,
|
||||||
aid: ep.aid,
|
aid: ep.aid,
|
||||||
@@ -585,17 +570,13 @@ fn create_normal_progresses_for_season(
|
|||||||
completed_ts: None,
|
completed_ts: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
progress
|
|
||||||
.update_fmt_fields(config)
|
|
||||||
.context("更新需要格式化的字段失败")?;
|
|
||||||
|
|
||||||
return Ok(vec![progress]);
|
return Ok(vec![progress]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果有多个分P,则为每个分P创建一个progress
|
// 如果有多个分P,则为每个分P创建一个progress
|
||||||
let mut progresses = Vec::new();
|
let mut progresses = Vec::new();
|
||||||
for page in &ep.pages {
|
for page in &ep.pages {
|
||||||
let mut progress = DownloadProgress {
|
let progress = DownloadProgress {
|
||||||
task_id: Uuid::new_v4().to_string(),
|
task_id: Uuid::new_v4().to_string(),
|
||||||
episode_type: EpisodeType::Normal,
|
episode_type: EpisodeType::Normal,
|
||||||
aid: ep.aid,
|
aid: ep.aid,
|
||||||
@@ -626,10 +607,6 @@ fn create_normal_progresses_for_season(
|
|||||||
completed_ts: None,
|
completed_ts: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
progress
|
|
||||||
.update_fmt_fields(config)
|
|
||||||
.context("更新需要格式化的字段失败")?;
|
|
||||||
|
|
||||||
progresses.push(progress);
|
progresses.push(progress);
|
||||||
}
|
}
|
||||||
Ok(progresses)
|
Ok(progresses)
|
||||||
|
|||||||
@@ -4,7 +4,11 @@ use anyhow::Context;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::{Map, Value};
|
use serde_json::{Map, Value};
|
||||||
|
|
||||||
use crate::{config::Config, utils::filename_filter};
|
use crate::{
|
||||||
|
config::Config,
|
||||||
|
types::{audio_quality::AudioQuality, codec_type::CodecType, video_quality::VideoQuality},
|
||||||
|
utils::filename_filter,
|
||||||
|
};
|
||||||
|
|
||||||
use super::episode_type::EpisodeType;
|
use super::episode_type::EpisodeType;
|
||||||
|
|
||||||
@@ -26,6 +30,9 @@ pub struct FmtParams {
|
|||||||
pub up_name: Option<String>,
|
pub up_name: Option<String>,
|
||||||
pub up_uid: Option<i64>,
|
pub up_uid: Option<i64>,
|
||||||
pub create_ts: u64,
|
pub create_ts: u64,
|
||||||
|
pub video_quality: VideoQuality,
|
||||||
|
pub codec_type: CodecType,
|
||||||
|
pub audio_quality: AudioQuality,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FmtParams {
|
impl FmtParams {
|
||||||
|
|||||||
@@ -87,6 +87,18 @@ function AvailableFmtFields() {
|
|||||||
<span class="rounded bg-gray-500 px-1 select-all">create_ts</span>
|
<span class="rounded bg-gray-500 px-1 select-all">create_ts</span>
|
||||||
<span class="ml-2">下载任务创建的时间</span>
|
<span class="ml-2">下载任务创建的时间</span>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<span class="rounded bg-gray-500 px-1 select-all">video_quality</span>
|
||||||
|
<span class="ml-2">画质(Unknown / 1080P / 1080P60 / AiRepair / 4K / Dolby ...)</span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span class="rounded bg-gray-500 px-1 select-all">codec_type</span>
|
||||||
|
<span class="ml-2">编码(Unknown / AVC / HEVC / AV1 / Audio)</span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span class="rounded bg-gray-500 px-1 select-all">audio_quality</span>
|
||||||
|
<span class="ml-2">音质(Unknown / 64K / 132K / 192K / Dolby / HiRes)</span>
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user