Cleanup
This commit is contained in:
parent
789f55ebac
commit
ebd2f3443e
3 changed files with 16 additions and 16 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -244,6 +244,7 @@ dependencies = [
|
||||||
name = "cbz2pdf"
|
name = "cbz2pdf"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
"dialoguer",
|
"dialoguer",
|
||||||
"image",
|
"image",
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
anyhow = "1.0.89"
|
||||||
clap = { version = "4.5.20", features = ["derive"] }
|
clap = { version = "4.5.20", features = ["derive"] }
|
||||||
dialoguer = "0.11.0"
|
dialoguer = "0.11.0"
|
||||||
image = "0.25.2"
|
image = "0.25.2"
|
||||||
|
|
|
||||||
30
src/main.rs
30
src/main.rs
|
|
@ -1,3 +1,4 @@
|
||||||
|
use anyhow::Result;
|
||||||
use clap::{Parser, ValueHint};
|
use clap::{Parser, ValueHint};
|
||||||
use dialoguer::theme::ColorfulTheme;
|
use dialoguer::theme::ColorfulTheme;
|
||||||
use dialoguer::Confirm;
|
use dialoguer::Confirm;
|
||||||
|
|
@ -86,7 +87,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
};
|
};
|
||||||
|
|
||||||
if proceed {
|
if proceed {
|
||||||
process_jobs(jobs);
|
process_jobs(jobs)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -145,7 +146,7 @@ impl Job {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_cbz(cbz_path: &Path, output_path: &Path) -> Result<(), Box<dyn std::error::Error>> {
|
fn convert_cbz(cbz_path: &Path, output_path: &Path) -> Result<()> {
|
||||||
let a4 = Rect::new(0.0, 0.0, 595.0, 842.0);
|
let a4 = Rect::new(0.0, 0.0, 595.0, 842.0);
|
||||||
|
|
||||||
let mut zip = ZipArchive::new(File::open(cbz_path)?)?;
|
let mut zip = ZipArchive::new(File::open(cbz_path)?)?;
|
||||||
|
|
@ -180,13 +181,12 @@ fn convert_cbz(cbz_path: &Path, output_path: &Path) -> Result<(), Box<dyn std::e
|
||||||
pdf.catalog(catalog_id).pages(page_tree_id);
|
pdf.catalog(catalog_id).pages(page_tree_id);
|
||||||
|
|
||||||
let mut pages = Vec::new();
|
let mut pages = Vec::new();
|
||||||
let image_count: i32 = images.len().try_into().unwrap();
|
let image_count = images.len();
|
||||||
|
|
||||||
for (pos, image) in images.iter().enumerate() {
|
for (pos, image) in images.iter().enumerate() {
|
||||||
let npos: i32 = pos.try_into().unwrap();
|
let page_id = Ref::new(pos as i32 + 10);
|
||||||
let page_id = Ref::new(npos + 10);
|
let image_id = Ref::new(image_count as i32 + 10 + pos as i32);
|
||||||
let image_id = Ref::new(image_count + 10 + npos);
|
let content_id = Ref::new(image_count as i32 * 3 + 10 + pos as i32);
|
||||||
let content_id = Ref::new(image_count * 3 + 10 + npos);
|
|
||||||
pages.push(page_id);
|
pages.push(page_id);
|
||||||
let mut page = pdf.page(page_id);
|
let mut page = pdf.page(page_id);
|
||||||
let image_name = Name(b"Im1");
|
let image_name = Name(b"Im1");
|
||||||
|
|
@ -214,22 +214,19 @@ fn convert_cbz(cbz_path: &Path, output_path: &Path) -> Result<(), Box<dyn std::e
|
||||||
}
|
}
|
||||||
|
|
||||||
let page_count = pages.len();
|
let page_count = pages.len();
|
||||||
pdf.pages(page_tree_id)
|
pdf.pages(page_tree_id).kids(pages).count(page_count as i32);
|
||||||
.kids(pages)
|
|
||||||
.count(page_count.try_into().unwrap());
|
|
||||||
|
|
||||||
std::fs::write(output_path, pdf.finish())?;
|
std::fs::write(output_path, pdf.finish())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_jobs(jobs: Vec<Job>) {
|
fn process_jobs(jobs: Vec<Job>) -> Result<()> {
|
||||||
let pb = ProgressBar::new(jobs.len().try_into().unwrap());
|
let pb = ProgressBar::new(jobs.len() as u64);
|
||||||
pb.enable_steady_tick(Duration::from_millis(300));
|
pb.enable_steady_tick(Duration::from_millis(300));
|
||||||
pb.set_style(
|
pb.set_style(ProgressStyle::with_template(
|
||||||
ProgressStyle::with_template("[{elapsed_precise}] {wide_bar} {pos:>7}/{len:7} {msg}")
|
"[{elapsed_precise}] {wide_bar} {pos:>7}/{len:7} {msg}",
|
||||||
.unwrap(),
|
)?);
|
||||||
);
|
|
||||||
|
|
||||||
jobs.par_iter().for_each(|entry| {
|
jobs.par_iter().for_each(|entry| {
|
||||||
convert_cbz(&entry.cbz_path, &entry.pdf_path).unwrap();
|
convert_cbz(&entry.cbz_path, &entry.pdf_path).unwrap();
|
||||||
|
|
@ -237,4 +234,5 @@ fn process_jobs(jobs: Vec<Job>) {
|
||||||
});
|
});
|
||||||
|
|
||||||
pb.finish();
|
pb.finish();
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue