mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-07-08 01:32:41 +08:00
Remove unneed functions
This commit is contained in:
@@ -18,9 +18,7 @@ use crate::pixiv_link::PixivID;
|
||||
use crate::pixiv_web::PixivWebClient;
|
||||
#[cfg(feature = "ugoira")]
|
||||
use crate::ugoira::{convert_ugoira_to_mp4, UgoiraFrames};
|
||||
use crate::utils::ask_need_overwrite;
|
||||
use crate::utils::get_file_name_from_url;
|
||||
use crate::webclient::WebClient;
|
||||
use crate::Main;
|
||||
use indicatif::MultiProgress;
|
||||
use json::JsonValue;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::downloader::pd_file::PdFile;
|
||||
use crate::ext::atomic::AtomicQuick;
|
||||
use crate::ext::rw_lock::GetRwLock;
|
||||
use crate::gettext;
|
||||
@@ -220,29 +219,6 @@ impl PixivWebClient {
|
||||
Some(r)
|
||||
}
|
||||
|
||||
pub async fn adownload_image<U: IntoUrl + Clone>(
|
||||
&self,
|
||||
url: U,
|
||||
pdf: &Option<PdFile>,
|
||||
) -> Option<Response> {
|
||||
self.auto_init();
|
||||
let r = self
|
||||
.client
|
||||
.get(url, json::object! {"referer": "https://www.pixiv.net/"})
|
||||
.await;
|
||||
if r.is_none() {
|
||||
return None;
|
||||
}
|
||||
let r = r.unwrap();
|
||||
let status = r.status();
|
||||
let code = status.as_u16();
|
||||
if code >= 400 {
|
||||
println!("{} {}", gettext("Failed to download image:"), status);
|
||||
return None;
|
||||
}
|
||||
Some(r)
|
||||
}
|
||||
|
||||
pub async fn get_artwork_ajax(&self, id: u64) -> Option<JsonValue> {
|
||||
self.auto_init();
|
||||
let r = self
|
||||
|
||||
@@ -7,20 +7,12 @@ use crate::ext::json::ToJson;
|
||||
use crate::gettext;
|
||||
use crate::list::NonTailList;
|
||||
use crate::opthelper::get_helper;
|
||||
use futures_util::StreamExt;
|
||||
use indicatif::ProgressBar;
|
||||
use indicatif::ProgressStyle;
|
||||
use json::JsonValue;
|
||||
use reqwest::{Client, IntoUrl, RequestBuilder, Response};
|
||||
use spin_on::spin_on;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
use std::default::Default;
|
||||
use std::ffi::OsStr;
|
||||
use std::fs::remove_file;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::atomic::AtomicI64;
|
||||
use std::sync::Arc;
|
||||
@@ -464,78 +456,6 @@ impl WebClient {
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
/// Download a stream
|
||||
/// * `file_name` - File name
|
||||
/// * `r` - Response
|
||||
/// * `opt` - Options
|
||||
///
|
||||
/// Note: If file already exists, will remove existing file first.
|
||||
pub fn download_stream<S: AsRef<OsStr> + ?Sized>(file_name: &S, r: Response) -> Result<(), ()> {
|
||||
let content_length = r.content_length();
|
||||
let opt = get_helper();
|
||||
let use_progress_bar = match &content_length {
|
||||
Some(_) => opt.use_progress_bar(),
|
||||
None => false,
|
||||
};
|
||||
let mut bar = if use_progress_bar {
|
||||
Some(ProgressBar::new(content_length.unwrap()))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if bar.is_some() {
|
||||
bar.as_mut().unwrap().set_style(
|
||||
ProgressStyle::default_bar()
|
||||
.template(opt.progress_bar_template().as_ref())
|
||||
.unwrap()
|
||||
.progress_chars("#>-"),
|
||||
);
|
||||
}
|
||||
let mut downloaded = 0usize;
|
||||
let p = Path::new(file_name);
|
||||
if p.exists() {
|
||||
let re = remove_file(p);
|
||||
if re.is_err() {
|
||||
println!("{} {}", gettext("Failed to remove file:"), re.unwrap_err());
|
||||
return Err(());
|
||||
}
|
||||
}
|
||||
if bar.is_some() {
|
||||
let tmp = p.file_name().unwrap_or(p.as_os_str());
|
||||
bar.as_mut().unwrap().set_message(
|
||||
gettext("Downloading \"<loc>\".")
|
||||
.replace("<loc>", tmp.to_str().unwrap_or("<NULL>")),
|
||||
);
|
||||
}
|
||||
let f = File::create(p);
|
||||
if f.is_err() {
|
||||
println!("{} {}", gettext("Failed to create file:"), f.unwrap_err());
|
||||
return Err(());
|
||||
}
|
||||
let mut f = f.unwrap();
|
||||
let mut stream = r.bytes_stream();
|
||||
while let Some(data) = spin_on(stream.next()) {
|
||||
if data.is_err() {
|
||||
println!(
|
||||
"{} {}",
|
||||
gettext("Error when downloading file:"),
|
||||
data.unwrap_err()
|
||||
);
|
||||
return Err(());
|
||||
}
|
||||
let data = data.unwrap();
|
||||
downloaded += data.len();
|
||||
if bar.is_some() {
|
||||
bar.as_mut().unwrap().set_position(downloaded as u64);
|
||||
}
|
||||
let r = f.write(&data);
|
||||
if r.is_err() {
|
||||
println!("{} {}", gettext("Failed to write file:"), r.unwrap_err());
|
||||
return Err(());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for WebClient {
|
||||
|
||||
Reference in New Issue
Block a user