mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-07-08 01:32:41 +08:00
update
This commit is contained in:
@@ -23,7 +23,6 @@ use crate::utils::get_file_name_from_url;
|
||||
use crate::webclient::WebClient;
|
||||
use crate::Main;
|
||||
use indicatif::MultiProgress;
|
||||
use indicatif::ProgressStyle;
|
||||
use json::JsonValue;
|
||||
use reqwest::IntoUrl;
|
||||
use std::path::PathBuf;
|
||||
@@ -77,30 +76,18 @@ impl Main {
|
||||
let downloader = Downloader::<LocalFile>::new(link, json::object!{"referer": "https://www.pixiv.net/"}, Some(&file_name), helper.overwrite())?;
|
||||
match downloader {
|
||||
DownloaderResult::Ok(d) => {
|
||||
if helper.use_progress_bar() {
|
||||
let style = ProgressStyle::default_bar()
|
||||
.template(helper.progress_bar_template().as_ref()).unwrap()
|
||||
.progress_chars("#>-");
|
||||
match progress_bars {
|
||||
Some(b) => {
|
||||
d.enable_progress_bar(style, Some(&b));
|
||||
}
|
||||
None => {
|
||||
d.enable_progress_bar(style, None);
|
||||
}
|
||||
}
|
||||
d.download();
|
||||
d.join().await?;
|
||||
if d.is_downloaded() {
|
||||
#[cfg(feature = "exif")]
|
||||
{
|
||||
if add_exifdata_to_image(&file_name, &datas, np).is_err() {
|
||||
println!(
|
||||
"{} {}",
|
||||
gettext("Failed to add exif data to image:"),
|
||||
file_name.to_str().unwrap_or("(null)")
|
||||
);
|
||||
}
|
||||
d.handle_options(&helper, progress_bars);
|
||||
d.download();
|
||||
d.join().await?;
|
||||
if d.is_downloaded() {
|
||||
#[cfg(feature = "exif")]
|
||||
{
|
||||
if add_exifdata_to_image(&file_name, &datas, np).is_err() {
|
||||
println!(
|
||||
"{} {}",
|
||||
gettext("Failed to add exif data to image:"),
|
||||
file_name.to_str().unwrap_or("(null)")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ use crate::ext::io::ClearFile;
|
||||
use crate::ext::replace::ReplaceWith2;
|
||||
use crate::ext::rw_lock::GetRwLock;
|
||||
use crate::gettext;
|
||||
use crate::opthelper::OptHelper;
|
||||
use crate::utils::ask_need_overwrite;
|
||||
use crate::utils::get_file_name_from_url;
|
||||
use crate::webclient::WebClient;
|
||||
@@ -369,17 +370,35 @@ impl <T: Write + Seek + Send + Sync + ClearFile + GetTargetFileName + 'static> D
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Disable progress bar
|
||||
pub fn disable_progress_bar(&self) {
|
||||
self.downloader.disable_progress_bar()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Enable the progress bar
|
||||
/// * `style` - The style of the progress bar
|
||||
/// * `mults` - The instance of [MultiProgress] if multiple progress bars are needed.
|
||||
pub fn enable_progress_bar(&self, style: ProgressStyle, mults: Option<&MultiProgress>) {
|
||||
self.downloader.enable_progress_bar(style, mults)
|
||||
}
|
||||
|
||||
/// Handle options
|
||||
/// * `mults` - The instance of [MultiProgress] if multiple progress bars are needed.
|
||||
pub fn handle_options(&self, helper: &OptHelper, mults: Option<Arc<MultiProgress>>) {
|
||||
if helper.use_progress_bar() {
|
||||
let style = ProgressStyle::default_bar()
|
||||
.template(helper.progress_bar_template().as_ref()).unwrap()
|
||||
.progress_chars("#>-");
|
||||
match mults {
|
||||
Some(v) => { self.enable_progress_bar(style, Some(&v)); }
|
||||
None => { self.enable_progress_bar(style, None); }
|
||||
}
|
||||
} else {
|
||||
self.disable_progress_bar();
|
||||
}
|
||||
}
|
||||
define_downloader_fn!(is_created, bool, "Returns true if the downloader is created just now.");
|
||||
define_downloader_fn!(is_downloading, bool, "Returns true if the downloader is downloading now.");
|
||||
define_downloader_fn!(is_multi_threads, bool, "Returns true if is multiple thread mode.");
|
||||
|
||||
Reference in New Issue
Block a user