Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New binary "eco" and normalization of api #9

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["eco-cbz", "eco-converter", "eco-merge", "eco-pack", "eco-viewer"]
members = ["eco", "eco-cbz", "eco-convert", "eco-merge", "eco-pack", "eco-view"]

[workspace.package]
rust-version = "1.73.0"
Expand All @@ -21,7 +21,10 @@ dioxus = "0.4.0"
dioxus-desktop = "0.4.0"
dunce = "1.0.4"
eco-cbz = { path = "./eco-cbz" }
eco-convert = { path = "./eco-convert" }
eco-merge = { path = "./eco-merge" }
eco-pack = { path = "./eco-pack" }
eco-view = { path = "./eco-view" }
epub = "2.1.1"
futures = "0.3.28"
glob = "0.3.1"
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ The repository host multiple cli and gui that allows you to edit, convert, merge

## Tools (with supported format):

- `eco-converter` - cli - Convert e-books to any format (from pdf, mobi, and DRM-free azw3, to cbz only for now)
- `eco-merge` - cli - Merge e-books together when it makes sense (cbz)
- `eco-pack` - cli - pack images into an e-book file (cbz)
- `eco-viewer` - gui - A dead simple e-book reader (cbz)
- `eco convert` - cli - Convert e-books to any format (from pdf, mobi, and DRM-free azw3, to cbz only for now)
- `eco merge` - cli - Merge e-books together when it makes sense (cbz)
- `eco pack` - cli - pack images into an e-book file (cbz)
- `eco view` - gui - A dead simple e-book reader (cbz)

## Eco Converter

Converts e-books from \* to \* (only pdf, mobi, and DRM-free azw3 to cbz supported for the moment):

```bash
eco-converter "archive.azw3" --from azw3 --outdir out
eco convert "archive.azw3" --from azw3 --outdir out
```

## Eco Merge (cbz only for now)

This will look for all the e-books in `path` and which file name contains `something` and merge them into `output/merged_archive.cbz`:

```bash
eco-merge --archives-glob "path/**/*something*" --outdir "output" --name "merged_archive"
eco merge --archives-glob "path/**/*something*" --outdir "output" --name "merged_archive"
```

## Eco Pack (cbz only for now)

Takes all the `png` files under `source` and pack them into the `archive.cbz` file:

```bash
eco-pack "source/*.png" --name archive --autosplit
eco pack "source/*.png" --name archive --autosplit
```

Options include:
Expand All @@ -39,10 +39,10 @@ Options include:
- `--contrast`: change contrast
- `--brightness`: change brightness

## Eco Viewer (cbz only for now)
## Eco View (cbz only for now)

View any e-book file with this simple gui:

```bash
eco-viewer "my_archive.cbz"
eco view "my_archive.cbz"
```
2 changes: 0 additions & 2 deletions eco-cbz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ edition.workspace = true
rust-version.workspace = true

[dependencies]
clap = { workspace = true, optional = true }
camino.workspace = true
chrono = { workspace = true, features = ["serde"], optional = true }
image = { workspace = true, features = ["webp-encoder"] }
Expand All @@ -19,5 +18,4 @@ zip.workspace = true

[features]
default = []
clap = ["dep:clap"]
metadata = ["dep:chrono", "dep:serde", "dep:serde_json", "dep:serde_repr"]
2 changes: 0 additions & 2 deletions eco-cbz/src/cbz.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![deny(clippy::all, clippy::pedantic)]

use std::{
fs::{File, OpenOptions},
io::{Cursor, Read, Seek, Write},
Expand Down
12 changes: 5 additions & 7 deletions eco-cbz/src/cbz_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub enum Month {
}

impl Month {
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
Self::Jan => "January",
Expand Down Expand Up @@ -150,6 +151,7 @@ pub struct ComicBookInfoV1 {
}

impl ComicBookInfoV1 {
#[must_use]
pub fn new() -> Self {
Self::default()
}
Expand Down Expand Up @@ -264,6 +266,7 @@ pub struct UnofficialMetadata {
}

impl UnofficialMetadata {
#[must_use]
pub fn new() -> Self {
Self::default()
}
Expand Down Expand Up @@ -300,13 +303,8 @@ impl UnofficialMetadata {
key: impl Into<String>,
value: impl Serialize,
) -> Result<Self> {
if self.extra.is_none() {
self.extra = Some(HashMap::new());
}
self.extra
.as_mut()
.unwrap()
.insert(key.into(), serde_json::to_value(value)?);
let extra = self.extra.get_or_insert(HashMap::new());
extra.insert(key.into(), serde_json::to_value(value)?);

Ok(self)
}
Expand Down
32 changes: 15 additions & 17 deletions eco-cbz/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
use std::{io, result};

use zip::result::ZipError;

#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("IO error {0}")]
IO(#[from] io::Error),
#[error("io error {0}")]
IO(#[from] std::io::Error),

#[error("Zip error {0}")]
#[error("zip error {0}")]
Zip(#[from] ZipError),

#[error("Cbz file size couldn't be converted")]
#[error("cbz file size couldn't be converted")]
CbzFileSizeConversion,

#[error("Cbz file name is empty")]
#[error("cbz file name is empty")]
CbzFileNameEmpty,

#[error("Cbz file invalid index {0}")]
#[error("cbz file invalid index {0}")]
CbzFileInvalidIndex(String),

#[error("File at index {0} not found in cbz")]
#[error("file at index {0} not found in cbz")]
CbzNotFound(usize),

#[error("Cbz is too large, it can contain a maximum of {0} files")]
#[error("cbz is too large, it can contain a maximum of {0} files")]
CbzTooLarge(usize),

#[error("Cbz file insertion's extension not provided")]
#[error("cbz file insertion's extension not provided")]
CbzInsertionNoExtension,

#[error("Cbz file insertion: no bytes set")]
#[error("cbz file insertion: no bytes set")]
CbzInsertionNoBytes,

#[error("Cbz metadata is too large: {0} > 65,535")]
#[error("cbz metadata is too large: {0} > 65,535")]
CbzMetadataSize(usize),

#[error("Image error: {0}")]
#[error("image error: {0}")]
Image(#[from] image::ImageError),

#[cfg(feature = "metadata")]
#[error("Metadata error: {0}")]
#[error("metadata error: {0}")]
MetadataFormat(#[from] serde_json::Error),

#[cfg(feature = "metadata")]
#[error("Metadata value error: {0}")]
#[error("metadata value error: {0}")]
MetadataValue(String),
}

pub type Result<T, E = Error> = result::Result<T, E>;
pub type Result<T, E = Error> = std::result::Result<T, E>;
18 changes: 3 additions & 15 deletions eco-cbz/src/image.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
fmt::Display,
io::{BufRead, Cursor, Read, Seek},
path::Path,
};
Expand All @@ -10,25 +9,11 @@ use zip::read::ZipFile;
use crate::errors::{Error, Result};

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
pub enum ReadingOrder {
Rtl,
Ltr,
}

impl Display for ReadingOrder {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
Self::Ltr => "ltr",
Self::Rtl => "rtl",
}
)
}
}

#[derive(Debug, PartialEq)]
pub struct Image {
dynamic_image: DynamicImage,
Expand Down Expand Up @@ -73,7 +58,9 @@ impl Image {
})
}

#[allow(clippy::missing_errors_doc)]
pub fn try_from_zip_file(mut file: ZipFile<'_>) -> Result<Self> {
#[allow(clippy::cast_possible_truncation)]
let mut buf = Vec::with_capacity(file.size() as usize);
file.read_to_end(&mut buf)?;

Expand Down Expand Up @@ -153,6 +140,7 @@ impl Image {
self
}

#[allow(clippy::missing_errors_doc)]
pub fn try_into_bytes(self) -> Result<Vec<u8>> {
let mut buf = Cursor::new(Vec::new());
self.dynamic_image
Expand Down
2 changes: 2 additions & 0 deletions eco-cbz/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(clippy::all, clippy::pedantic)]

pub mod cbz;
pub mod cbz_metadata;
pub mod errors;
Expand Down
6 changes: 2 additions & 4 deletions eco-converter/Cargo.toml → eco-convert/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
[package]
name = "eco-converter"
name = "eco-convert"
version = "0.1.0"
edition.workspace = true
rust-version.workspace = true

[dependencies]
anyhow.workspace = true
camino.workspace = true
clap.workspace = true
eco-cbz.workspace = true
eco-pack.workspace = true
html5ever = { workspace = true, optional = true }
image.workspace = true
markup5ever_rcdom = { workspace = true, optional = true }
mobi.workspace = true
pdf.workspace = true
thiserror.workspace = true
tl.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true

[features]
default = []
Expand Down
Loading