Compare commits

...

4 commits

Author SHA1 Message Date
85f7dd0e45 Merge branch 'wip' 2024-11-08 14:04:04 +01:00
2cf198e52b Cargo.lock updated 2024-11-08 14:03:41 +01:00
445662727e strip release builds 2024-11-07 14:26:52 +01:00
23c126ec9a deps updated
particularly quick_xml which caused some code changes. Lots of testing should be done.
2024-11-05 14:01:48 +01:00
3 changed files with 309 additions and 100 deletions

322
Cargo.lock generated
View file

@ -21,26 +21,30 @@ dependencies = [
[[package]] [[package]]
name = "ahash" name = "ahash"
version = "0.7.8" version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011"
dependencies = [ dependencies = [
"getrandom", "cfg-if",
"once_cell", "once_cell",
"version_check", "version_check",
"zerocopy",
] ]
[[package]] [[package]]
name = "base64ct" name = "arbitrary"
version = "1.6.0" version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" checksum = "775a8770d29db3dadcb858482cc240af7b2ffde4ac4de67d1d4955728103f0e2"
dependencies = [
"derive_arbitrary",
]
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.3.2" version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
[[package]] [[package]]
name = "block-buffer" name = "block-buffer"
@ -51,6 +55,12 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "bumpalo"
version = "3.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
[[package]] [[package]]
name = "byteorder" name = "byteorder"
version = "1.5.0" version = "1.5.0"
@ -107,9 +117,9 @@ dependencies = [
[[package]] [[package]]
name = "constant_time_eq" name = "constant_time_eq"
version = "0.1.5" version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6"
[[package]] [[package]]
name = "cpufeatures" name = "cpufeatures"
@ -120,6 +130,21 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "crc"
version = "3.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636"
dependencies = [
"crc-catalog",
]
[[package]]
name = "crc-catalog"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5"
[[package]] [[package]]
name = "crc32fast" name = "crc32fast"
version = "1.4.2" version = "1.4.2"
@ -145,6 +170,12 @@ dependencies = [
"typenum", "typenum",
] ]
[[package]]
name = "deflate64"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da692b8d1080ea3045efaab14434d40468c3d8657e42abddfffca87b428f4c1b"
[[package]] [[package]]
name = "deranged" name = "deranged"
version = "0.3.11" version = "0.3.11"
@ -154,6 +185,17 @@ dependencies = [
"powerfmt", "powerfmt",
] ]
[[package]]
name = "derive_arbitrary"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d475dfebcb4854d596b17b09f477616f80f17a550517f2b3615d8c205d5c802b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "digest" name = "digest"
version = "0.10.7" version = "0.10.7"
@ -166,10 +208,27 @@ dependencies = [
] ]
[[package]] [[package]]
name = "fallible-iterator" name = "displaydoc"
version = "0.2.0" version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "fallible-iterator"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649"
[[package]] [[package]]
name = "fallible-streaming-iterator" name = "fallible-streaming-iterator"
@ -210,20 +269,26 @@ dependencies = [
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.11.2" version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
dependencies = [ dependencies = [
"ahash", "ahash",
] ]
[[package]] [[package]]
name = "hashlink" name = "hashbrown"
version = "0.7.0" version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7249a3129cbc1ffccd74857f81464a323a152173cdb134e0fd81bc803b29facf" checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3"
[[package]]
name = "hashlink"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af"
dependencies = [ dependencies = [
"hashbrown", "hashbrown 0.14.5",
] ]
[[package]] [[package]]
@ -235,6 +300,16 @@ dependencies = [
"digest", "digest",
] ]
[[package]]
name = "indexmap"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da"
dependencies = [
"equivalent",
"hashbrown 0.15.1",
]
[[package]] [[package]]
name = "inout" name = "inout"
version = "0.1.3" version = "0.1.3"
@ -255,21 +330,43 @@ dependencies = [
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.161" version = "0.2.162"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398"
[[package]] [[package]]
name = "libsqlite3-sys" name = "libsqlite3-sys"
version = "0.24.2" version = "0.30.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "898745e570c7d0453cc1fbc4a701eb6c662ed54e8fec8b7d14be137ebeeb9d14" checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149"
dependencies = [ dependencies = [
"cc", "cc",
"pkg-config", "pkg-config",
"vcpkg", "vcpkg",
] ]
[[package]]
name = "lockfree-object-pool"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9374ef4228402d4b7e403e5838cb880d9ee663314b0a900d5a6aabf0c213552e"
[[package]]
name = "log"
version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
[[package]]
name = "lzma-rs"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "297e814c836ae64db86b36cf2a557ba54368d03f6afcd7d947c266692f71115e"
dependencies = [
"byteorder",
"crc",
]
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.7.4" version = "2.7.4"
@ -297,17 +394,6 @@ version = "1.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
[[package]]
name = "password-hash"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700"
dependencies = [
"base64ct",
"rand_core",
"subtle",
]
[[package]] [[package]]
name = "pbdbfixer" name = "pbdbfixer"
version = "0.8.3" version = "0.8.3"
@ -319,14 +405,12 @@ dependencies = [
[[package]] [[package]]
name = "pbkdf2" name = "pbkdf2"
version = "0.11.0" version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2"
dependencies = [ dependencies = [
"digest", "digest",
"hmac", "hmac",
"password-hash",
"sha2",
] ]
[[package]] [[package]]
@ -341,6 +425,15 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
[[package]]
name = "ppv-lite86"
version = "0.2.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04"
dependencies = [
"zerocopy",
]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.89" version = "1.0.89"
@ -352,9 +445,9 @@ dependencies = [
[[package]] [[package]]
name = "quick-xml" name = "quick-xml"
version = "0.23.1" version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11bafc859c6815fbaffbbbf4229ecb767ac913fecb27f9ad4343662e9ef099ea" checksum = "ffbfb3ddf5364c9cfcd65549a1e7b801d0e8d1b14c1a1590a6408aa93cfbfa84"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
@ -368,24 +461,47 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]] [[package]]
name = "rand_core" name = "rand_core"
version = "0.6.4" version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]] [[package]]
name = "rusqlite" name = "rusqlite"
version = "0.27.0" version = "0.32.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85127183a999f7db96d1a976a309eebbfb6ea3b0b400ddd8340190129de6eb7a" checksum = "7753b721174eb8ff87a9a0e799e2d7bc3749323e773db92e0984debb00019d6e"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"fallible-iterator", "fallible-iterator",
"fallible-streaming-iterator", "fallible-streaming-iterator",
"hashlink", "hashlink",
"libsqlite3-sys", "libsqlite3-sys",
"memchr",
"smallvec", "smallvec",
] ]
@ -420,23 +536,18 @@ dependencies = [
"digest", "digest",
] ]
[[package]]
name = "sha2"
version = "0.10.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]] [[package]]
name = "shlex" name = "shlex"
version = "1.3.0" version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "simd-adler32"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
[[package]] [[package]]
name = "smallvec" name = "smallvec"
version = "1.13.2" version = "1.13.2"
@ -460,6 +571,26 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "thiserror"
version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7c61ec9a6f64d2793d8a45faba21efbe3ced62a886d44c36a009b2b519b4c7e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.36" version = "0.3.36"
@ -510,41 +641,104 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]] [[package]]
name = "zip" name = "zerocopy"
version = "0.6.6" version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
dependencies = [
"byteorder",
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "zeroize"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde"
dependencies = [
"zeroize_derive",
]
[[package]]
name = "zeroize_derive"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "zip"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc5e4288ea4057ae23afc69a4472434a87a2495cafce6632fd1c4ec9f5cf3494"
dependencies = [ dependencies = [
"aes", "aes",
"byteorder", "arbitrary",
"bzip2", "bzip2",
"constant_time_eq", "constant_time_eq",
"crc32fast", "crc32fast",
"crossbeam-utils", "crossbeam-utils",
"deflate64",
"displaydoc",
"flate2", "flate2",
"hmac", "hmac",
"indexmap",
"lzma-rs",
"memchr",
"pbkdf2", "pbkdf2",
"rand",
"sha1", "sha1",
"thiserror",
"time", "time",
"zeroize",
"zopfli",
"zstd", "zstd",
] ]
[[package]] [[package]]
name = "zstd" name = "zopfli"
version = "0.11.2+zstd.1.5.2" version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" checksum = "e5019f391bac5cf252e93bbcc53d039ffd62c7bfb7c150414d61369afe57e946"
dependencies = [
"bumpalo",
"crc32fast",
"lockfree-object-pool",
"log",
"once_cell",
"simd-adler32",
]
[[package]]
name = "zstd"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcf2b778a664581e31e389454a7072dab1647606d44f7feea22cd5abb9c9f3f9"
dependencies = [ dependencies = [
"zstd-safe", "zstd-safe",
] ]
[[package]] [[package]]
name = "zstd-safe" name = "zstd-safe"
version = "5.0.2+zstd.1.5.2" version = "7.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" checksum = "54a3ab4db68cea366acc5c897c7b4d4d1b8994a9cd6e6f841f8964566a419059"
dependencies = [ dependencies = [
"libc",
"zstd-sys", "zstd-sys",
] ]

View file

@ -7,9 +7,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
zip = "0.6" zip = "2.2.0"
quick-xml = "0.23" quick-xml = "0.37"
[dependencies.rusqlite] [dependencies.rusqlite]
version = "0.27" version = "0.32.1"
features = ["bundled"] features = ["bundled"]
[profile.release]
strip = true

View file

@ -1,4 +1,5 @@
use std::{ use std::{
borrow::Borrow,
collections::HashMap, collections::HashMap,
fs::{self, File}, fs::{self, File},
io::Read, io::Read,
@ -52,17 +53,19 @@ fn get_rootfile(archive: &mut ZipArchive<File>) -> String {
container.read_to_string(&mut xml_str_buffer).unwrap(); container.read_to_string(&mut xml_str_buffer).unwrap();
let mut reader = Reader::from_str(&xml_str_buffer); let mut reader = Reader::from_str(&xml_str_buffer);
reader.trim_text(true); reader.config_mut().trim_text(true);
let mut buf = Vec::new(); let mut buf = Vec::new();
let mut opf_filename = String::new(); let mut opf_filename = String::new();
loop { loop {
match reader.read_event(&mut buf) { match reader.read_event_into(&mut buf) {
Ok(Event::Start(ref e)) | Ok(Event::Empty(ref e)) if e.local_name() == b"rootfile" => { Ok(Event::Start(ref e)) | Ok(Event::Empty(ref e))
if e.local_name().into_inner() == b"rootfile" =>
{
opf_filename = String::from_utf8( opf_filename = String::from_utf8(
e.attributes() e.attributes()
.filter(|attr| attr.as_ref().unwrap().key == b"full-path") .filter(|attr| attr.as_ref().unwrap().key.into_inner() == b"full-path")
.next() .next()
.unwrap() .unwrap()
.unwrap() .unwrap()
@ -128,22 +131,22 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
let mut xml_authors = HashMap::new(); let mut xml_authors = HashMap::new();
loop { loop {
match reader.read_event(&mut buf) { match reader.read_event_into(&mut buf) {
// See if we have EPUB3 or EPUB2 // See if we have EPUB3 or EPUB2
Ok(Event::Start(ref e)) if e.local_name() == b"package" => { Ok(Event::Start(ref e)) if e.local_name().into_inner() == b"package" => {
if e.attributes().any(|attr| { if e.attributes().any(|attr| {
attr.as_ref().unwrap().key == b"version" attr.as_ref().unwrap().key.into_inner() == b"version"
&& attr.as_ref().unwrap().value.starts_with(b"3") && attr.as_ref().unwrap().value.starts_with(b"3")
}) { }) {
is_epub3 = true; is_epub3 = true;
} }
} }
Ok(Event::Start(ref e)) if e.local_name() == b"creator" => { Ok(Event::Start(ref e)) if e.local_name().into_inner() == b"creator" => {
creator_found = true; creator_found = true;
if is_epub3 { if is_epub3 {
if let Some(idval) = e if let Some(idval) = e
.attributes() .attributes()
.filter(|attr| attr.as_ref().unwrap().key == b"id") .filter(|attr| attr.as_ref().unwrap().key.into_inner() == b"id")
.next() .next()
{ {
curr_id = "#".to_string() curr_id = "#".to_string()
@ -159,19 +162,26 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
} else { } else {
if let Some(file_as_val) = e if let Some(file_as_val) = e
.attributes() .attributes()
.filter(|attr| attr.as_ref().unwrap().key.ends_with(b"file-as")) .filter(|attr| {
attr.as_ref()
.unwrap()
.key
.into_inner()
.ends_with(b"file-as")
})
.next() .next()
{ {
curr_id = "none".to_string() + xml_authors.len().to_string().as_str(); curr_id = "none".to_string() + xml_authors.len().to_string().as_str();
let entry = xml_authors.entry(curr_id.clone()).or_insert(XmlAut::new()); let entry = xml_authors.entry(curr_id.clone()).or_insert(XmlAut::new());
entry.sort = file_as_val entry.sort = file_as_val
.unwrap() .unwrap()
.unescape_and_decode_value(&reader) .decode_and_unescape_value(*reader.decoder().borrow())
.unwrap_or_default(); .unwrap_or_default()
.to_string();
entry.role = "aut".to_string(); entry.role = "aut".to_string();
} else if let Some(_role_val) = e } else if let Some(_role_val) = e
.attributes() .attributes()
.filter(|attr| attr.as_ref().unwrap().key.ends_with(b"role")) .filter(|attr| attr.as_ref().unwrap().key.into_inner().ends_with(b"role"))
.next() .next()
{ {
curr_id = "none".to_string() + xml_authors.len().to_string().as_str(); curr_id = "none".to_string() + xml_authors.len().to_string().as_str();
@ -190,33 +200,33 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
creator_found = false; creator_found = false;
} }
Ok(Event::Start(ref e)) if e.local_name() == b"meta" && is_epub3 => { Ok(Event::Start(ref e)) if e.local_name().into_inner() == b"meta" && is_epub3 => {
if let Some(refines) = e if let Some(refines) = e
.attributes() .attributes()
.filter(|attr| attr.as_ref().unwrap().key == b"refines") .filter(|attr| attr.as_ref().unwrap().key.into_inner() == b"refines")
.next() .next()
{ {
if e.attributes().any(|attr| { if e.attributes().any(|attr| {
attr.as_ref().unwrap().key == b"property" attr.as_ref().unwrap().key.into_inner() == b"property"
&& attr.as_ref().unwrap().value.ends_with(b"file-as") && attr.as_ref().unwrap().value.ends_with(b"file-as")
}) { }) {
curr_id = String::from_utf8(refines.unwrap().value.to_vec()).unwrap(); curr_id = String::from_utf8(refines.unwrap().value.to_vec()).unwrap();
file_as_found = true; file_as_found = true;
} else if e.attributes().any(|attr| { } else if e.attributes().any(|attr| {
attr.as_ref().unwrap().key == b"property" attr.as_ref().unwrap().key.into_inner() == b"property"
&& attr.as_ref().unwrap().value.ends_with(b"role") && attr.as_ref().unwrap().value.ends_with(b"role")
}) { }) {
curr_id = String::from_utf8(refines.unwrap().value.to_vec()).unwrap(); curr_id = String::from_utf8(refines.unwrap().value.to_vec()).unwrap();
role_found = true; role_found = true;
} else if e.attributes().any(|attr| { } else if e.attributes().any(|attr| {
attr.as_ref().unwrap().key == b"property" attr.as_ref().unwrap().key.into_inner() == b"property"
&& attr.as_ref().unwrap().value.ends_with(b"group-position") && attr.as_ref().unwrap().value.ends_with(b"group-position")
}) { }) {
series_index_found = true; series_index_found = true;
} }
} }
if e.attributes().any(|attr| { if e.attributes().any(|attr| {
attr.as_ref().unwrap().key == b"property" attr.as_ref().unwrap().key.into_inner() == b"property"
&& attr && attr
.as_ref() .as_ref()
.unwrap() .unwrap()
@ -226,40 +236,41 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
series_found = true; series_found = true;
} }
} }
Ok(Event::Empty(ref e)) if e.local_name() == b"meta" && !is_epub3 => { Ok(Event::Empty(ref e)) if e.local_name().into_inner() == b"meta" && !is_epub3 => {
if e.attributes().any(|attr| { if e.attributes().any(|attr| {
attr.as_ref().unwrap().key == b"name" attr.as_ref().unwrap().key.into_inner() == b"name"
&& attr && attr
.as_ref() .as_ref()
.unwrap() .unwrap()
.unescaped_value() .unescape_value()
.unwrap() .unwrap()
.ends_with(b"series") .ends_with("series")
}) { }) {
epub_meta.series.name = e epub_meta.series.name = e
.attributes() .attributes()
.filter(|attr| attr.as_ref().unwrap().key == b"content") .filter(|attr| attr.as_ref().unwrap().key.into_inner() == b"content")
.next() .next()
.unwrap() .unwrap()
.unwrap() .unwrap()
.unescape_and_decode_value(&reader) .decode_and_unescape_value(*reader.decoder().borrow())
.unwrap_or_default(); .unwrap_or_default()
.to_string();
} else if e.attributes().any(|attr| { } else if e.attributes().any(|attr| {
attr.as_ref().unwrap().key == b"name" attr.as_ref().unwrap().key.into_inner() == b"name"
&& attr && attr
.as_ref() .as_ref()
.unwrap() .unwrap()
.unescaped_value() .unescape_value()
.unwrap() .unwrap()
.ends_with(b"series_index") .ends_with("series_index")
}) { }) {
let index_float = e let index_float = e
.attributes() .attributes()
.filter(|attr| attr.as_ref().unwrap().key == b"content") .filter(|attr| attr.as_ref().unwrap().key.into_inner() == b"content")
.next() .next()
.unwrap() .unwrap()
.unwrap() .unwrap()
.unescape_and_decode_value(&reader) .decode_and_unescape_value(*reader.decoder().borrow())
.unwrap_or_default() .unwrap_or_default()
.parse::<f32>() .parse::<f32>()
.unwrap_or_default(); .unwrap_or_default();
@ -291,11 +302,12 @@ pub fn get_epub_metadata(filename: &str) -> Option<EpubMetadata> {
series_index_found = false; series_index_found = false;
} }
Ok(Event::Start(ref e)) if e.local_name() == b"subject" => { Ok(Event::Start(ref e)) if e.local_name().into_inner() == b"subject" => {
genre_found = true; genre_found = true;
} }
Ok(Event::Text(ref e)) if genre_found => { Ok(Event::Text(ref e)) if genre_found => {
epub_meta.genre = e.unescape_and_decode(&reader).unwrap(); //epub_meta.genre = e.unescape_and_decode(&reader).unwrap();
epub_meta.genre = e.unescape().unwrap().to_string();
genre_found = false; genre_found = false;
} }
Ok(Event::Eof) => break, Ok(Event::Eof) => break,