|
|
|
@ -17,12 +17,15 @@ mod progress;
|
|
|
|
|
/// Decode a loli from path
|
|
|
|
|
pub async fn decode(from: impl AsRef<Path>, to: impl AsRef<Path>, progress: &mut progress::CommandSender) -> Result<loli::Loli, error::Error>
|
|
|
|
|
{
|
|
|
|
|
prog_send!(link progress.println("Mapping child"));
|
|
|
|
|
prog_send!(progress.println("Mapping child"));
|
|
|
|
|
let base = loli::BasedLoli::map(from)?;
|
|
|
|
|
prog_send!(link progress.println("Calculating bounds"));
|
|
|
|
|
prog_send!(progress.println("Calculating bounds"));
|
|
|
|
|
let bounds = base.calculate_bounds()?; // If server is returning error code, this will fail.
|
|
|
|
|
prog_send!(link progress.println(format!("Decoding ({:?}) {} -> {} bytes", bounds, base.as_ref().len(), base.decoded_size())));
|
|
|
|
|
let mut decoded = bounds.create_child(to)?;
|
|
|
|
|
prog_send!(progress.println(format!("Finding bounds ({:?}) {} -> {} bytes", bounds, base.as_ref().len(), base.decoded_size())));
|
|
|
|
|
|
|
|
|
|
//Find extension
|
|
|
|
|
|
|
|
|
|
let mut decoded = bounds.create_child(to.as_ref().with_extension(bounds.image().ext()))?;
|
|
|
|
|
prog_send!(progress.println("Decoding..."));
|
|
|
|
|
let sz = bounds.decode(&mut decoded)?;
|
|
|
|
|
prog_send!(link progress.println(format!("Decode complete ({} bytes)", sz)));
|
|
|
|
@ -37,7 +40,7 @@ pub async fn perform(url: impl AsRef<str>, path: impl AsRef<Path>, progress: &mu
|
|
|
|
|
let path = path.as_ref();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut resp = reqwest::get(url).await?;
|
|
|
|
|
let resp = reqwest::get(url).await?;
|
|
|
|
|
let len = resp.content_length();
|
|
|
|
|
|
|
|
|
|
//prog_send!(link progress.push_task(&task));
|
|
|
|
@ -93,39 +96,54 @@ pub async fn work(conf: config::Config) -> Result<(), Box<dyn std::error::Error>
|
|
|
|
|
|
|
|
|
|
let task = format!("{:?}", path); //TODO: Real task name
|
|
|
|
|
prog_send!(link unwind prog.push_task(&task));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let temp = tempfile::TempFile::new();
|
|
|
|
|
match perform(&url, &temp, &mut prog).await {
|
|
|
|
|
Err(e) => panic!("Failed downloading {} -> {:?}: {}", url, temp, e), //TODO: Make real error handler
|
|
|
|
|
Ok(_) => {
|
|
|
|
|
let path = match path {
|
|
|
|
|
config::OutputType::File(file) => file,
|
|
|
|
|
config::OutputType::Directory(dir) => unimplemented!(), //TODO: implement get hash to file
|
|
|
|
|
};
|
|
|
|
|
let loli = match decode(&temp, &path, &mut prog).await {
|
|
|
|
|
Ok(v) => v,
|
|
|
|
|
Err(e) => panic!("Failed decoding: {}", e),
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prog_send!(link prog.pop_task(task)); //TODO: Make sure we don't return gracefully before this is called.
|
|
|
|
|
let return_value = 'clean: {
|
|
|
|
|
match perform(&url, &temp, &mut prog).await {
|
|
|
|
|
Err(e) => prog_send!(link prog.println(format!("Failed downloading {} -> {:?}: {}", url, temp, e))),
|
|
|
|
|
Ok(_) => {
|
|
|
|
|
let path = match path {
|
|
|
|
|
config::OutputType::File(file) => file,
|
|
|
|
|
config::OutputType::Directory(dir) => unimplemented!(), //TODO: implement get hash to file
|
|
|
|
|
};
|
|
|
|
|
let loli = match decode(&temp, &path, &mut prog).await {
|
|
|
|
|
Ok(v) => v,
|
|
|
|
|
Err(e) => {
|
|
|
|
|
prog_send!(link prog.println(format!("Failed decoding: {}", e)));
|
|
|
|
|
break 'clean false;
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
prog_send!(link prog.println(format!("{:?} Complete", loli)));
|
|
|
|
|
break 'clean true;
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
false
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
prog_send!(link prog.pop_task(task));
|
|
|
|
|
return_value
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prog_send!(link prog_writer.println("Children working..."));
|
|
|
|
|
let mut done =0;
|
|
|
|
|
let total = children.len();
|
|
|
|
|
for child in children.into_iter()
|
|
|
|
|
{
|
|
|
|
|
match child.await {
|
|
|
|
|
Ok(v) => (),
|
|
|
|
|
Ok(true) => done+=1,
|
|
|
|
|
Err(err) => {
|
|
|
|
|
println!("Child failed: {}", err);
|
|
|
|
|
prog_send!(try link unwind prog_writer.println(format!("Child panic: {}", err)));
|
|
|
|
|
},
|
|
|
|
|
_ => (),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
prog_send!(link prog_writer.set_title(""));
|
|
|
|
|
prog_send!(try link prog_writer.kill());
|
|
|
|
|
prog.await.expect("mpsc fatal");
|
|
|
|
|
println!("Completed {} / {} lolis ({} failed).", done, total, total-done);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|