-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eco): New binary "eco" and normalization of api
- Loading branch information
Showing
33 changed files
with
380 additions
and
162 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#[derive(Debug, thiserror::Error)] | ||
pub enum Error { | ||
#[error("io error {0}")] | ||
Io(#[from] std::io::Error), | ||
|
||
#[error("cbz error {0}")] | ||
Cbz(#[from] eco_cbz::Error), | ||
|
||
#[error("mobi error {0}")] | ||
Mobi(#[from] mobi::MobiError), | ||
|
||
#[error("pdf error {0}")] | ||
Pdf(#[from] pdf::PdfError), | ||
|
||
#[error("ts parse error {0}")] | ||
TlParse(#[from] tl::ParseError), | ||
|
||
#[error("pack error {0}")] | ||
Pack(#[from] eco_pack::Error), | ||
|
||
#[error("invalid mobi version {0}")] | ||
InvalidMobiVersion(u32), | ||
} | ||
|
||
pub type Result<T, E = Error> = std::result::Result<T, E>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#![deny(clippy::all, clippy::pedantic)] | ||
|
||
use std::fs; | ||
|
||
use camino::Utf8PathBuf; | ||
use eco_cbz::image::ReadingOrder; | ||
use eco_pack::pack_imgs_to_cbz; | ||
use tracing::info; | ||
|
||
pub use crate::errors::{Error, Result}; | ||
pub use crate::mobi::convert_to_imgs as mobi_to_imgs; | ||
pub use crate::pdf::convert_to_imgs as pdf_to_imgs; | ||
|
||
pub mod errors; | ||
mod mobi; | ||
mod pdf; | ||
mod utils; | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
pub enum Format { | ||
Mobi, | ||
Azw3, | ||
Pdf, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct ConvertOptions { | ||
/// Path to the source file | ||
pub path: Utf8PathBuf, | ||
|
||
/// Source format | ||
pub from: Format, | ||
|
||
/// Dir to output images | ||
pub outdir: Utf8PathBuf, | ||
|
||
/// The archive name | ||
pub name: String, | ||
|
||
/// Adjust images contrast | ||
pub contrast: Option<f32>, | ||
|
||
/// Adjust images brightness | ||
pub brightness: Option<i32>, | ||
|
||
/// Blur image (slow with big numbers) | ||
pub blur: Option<f32>, | ||
|
||
/// Automatically split landscape images into 2 pages | ||
pub autosplit: bool, | ||
|
||
/// Reading order | ||
pub reading_order: ReadingOrder, | ||
} | ||
|
||
#[allow(clippy::missing_errors_doc)] | ||
pub fn convert(opts: ConvertOptions) -> Result<()> { | ||
fs::create_dir_all(&opts.outdir)?; | ||
let imgs = match opts.from { | ||
Format::Mobi | Format::Azw3 => mobi_to_imgs(opts.path)?, | ||
Format::Pdf => pdf_to_imgs(opts.path)?, | ||
}; | ||
info!("found {} imgs", imgs.len()); | ||
|
||
let cbz_writer = pack_imgs_to_cbz( | ||
imgs, | ||
opts.contrast, | ||
opts.brightness, | ||
opts.blur, | ||
opts.autosplit, | ||
opts.reading_order, | ||
)?; | ||
|
||
cbz_writer.write_to_path(opts.outdir.join(format!("{}.cbz", opts.name)))?; | ||
|
||
Ok(()) | ||
} |
4 changes: 2 additions & 2 deletions
4
eco-converter/src/mobi/html5ever_parser.rs → eco-convert/src/mobi/html5ever_parser.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.