From 186efc8aee3f37927f7a9f07a25c3d954bc50329 Mon Sep 17 00:00:00 2001 From: 9FS <9fs@sussywussy.de> Date: Sat, 23 Nov 2024 16:57:56 +0000 Subject: [PATCH] fixed and polished FILENAME_TITLE_TYPE --- Cargo.lock | 166 +++++++++++++++++++++++--------------------- Cargo.toml | 2 +- docker-compose.yaml | 2 +- readme.md | 16 +++-- src/config.rs | 47 +++++-------- src/hentai.rs | 47 +++++++------ src/main_inner.rs | 11 ++- src/search_api.rs | 1 + 8 files changed, 154 insertions(+), 138 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a104f53..1264b4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,9 +42,9 @@ dependencies = [ [[package]] name = "allocator-api2" -version = "0.2.19" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611cc2ae7d2e242c457e4be7f97036b8ad9ca152b499f53faf99b1ed8fc2553f" +checksum = "45862d1c77f2228b9e10bc609d5bc203d86ebc9b87ad8d5d5167a6c9abf739d9" [[package]] name = "android-tzdata" @@ -147,9 +147,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.19.0" +version = "1.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8334215b81e418a0a7bdb8ef0849474f40bb10c8b71f1c4ed315cff49f32494d" +checksum = "8b37c88a63ffd85d15b406896cc343916d7cf57838a847b3a6f2ca5d39a5695a" [[package]] name = "byteorder" @@ -186,9 +186,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.37" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40545c26d092346d8a8dab71ee48e7685a7a9cba76e634790c215b41a4a7b4cf" +checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47" dependencies = [ "jobserver", "libc", @@ -283,7 +283,7 @@ checksum = "2eac901828f88a5241ee0600950ab981148a18f2f756900ffba1b125ca6a3ef9" dependencies = [ "cookie", "document-features", - "idna 1.0.3", + "idna", "log", "publicsuffix", "serde", @@ -301,9 +301,9 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" -version = "0.2.14" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +checksum = "16b80225097f2e5ae4e7179dd2266824648f3e2f49d9134d584b76389d31c4c3" dependencies = [ "libc", ] @@ -511,9 +511,9 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.34" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0" +checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" dependencies = [ "crc32fast", "miniz_oxide", @@ -634,8 +634,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] @@ -762,9 +764,9 @@ checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] name = "hyper" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbbff0a806a4728c99295b254c8838933b5b082d75e3cb70c8dab21fdfbcfa9a" +checksum = "97818827ef4f364230e16705d4706e2897df2bb60617d6ca15d598025a3c481f" dependencies = [ "bytes", "futures-channel", @@ -957,16 +959,6 @@ dependencies = [ "syn", ] -[[package]] -name = "idna" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "idna" version = "1.0.3" @@ -1032,9 +1024,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.11" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +checksum = "540654e97a3f4470a492cd30ff187bc95d89557a903a2bbf112e2fae98104ef2" [[package]] name = "jobserver" @@ -1065,9 +1057,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.162" +version = "0.2.164" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" +checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f" [[package]] name = "libm" @@ -1094,9 +1086,9 @@ checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "litemap" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" +checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" [[package]] name = "litrs" @@ -1198,7 +1190,7 @@ dependencies = [ [[package]] name = "nhentai_archivist" -version = "3.5.1" +version = "3.6.0" dependencies = [ "chrono", "load_config", @@ -1210,7 +1202,7 @@ dependencies = [ "serde_json", "setup_logging", "sqlx", - "thiserror 2.0.2", + "thiserror 2.0.3", "tokio", "unicode-segmentation", "zip", @@ -1433,9 +1425,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.89" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -1461,19 +1453,19 @@ checksum = "33cb294fe86a74cbcf50d4445b37da762029549ebeea341421c7c70370f86cac" [[package]] name = "publicsuffix" -version = "2.2.3" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96a8c1bda5ae1af7f99a2962e49df150414a43d62404644d98dd5c3a93d07457" +checksum = "6f42ea446cab60335f76979ec15e12619a2165b5ae2c12166bef27d283a9fadf" dependencies = [ - "idna 0.3.0", + "idna", "psl-types", ] [[package]] name = "quinn" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +checksum = "62e96808277ec6f97351a2380e6c25114bc9e67037775464979f3037c92d05ef" dependencies = [ "bytes", "pin-project-lite", @@ -1482,26 +1474,29 @@ dependencies = [ "rustc-hash", "rustls", "socket2", - "thiserror 1.0.69", + "thiserror 2.0.3", "tokio", "tracing", ] [[package]] name = "quinn-proto" -version = "0.11.8" +version = "0.11.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +checksum = "a2fe5ef3495d7d2e377ff17b1a8ce2ee2ec2a18cde8b6ad6619d65d0701c135d" dependencies = [ "bytes", + "getrandom", "rand", "ring", "rustc-hash", "rustls", + "rustls-pki-types", "slab", - "thiserror 1.0.69", + "thiserror 2.0.3", "tinyvec", "tracing", + "web-time", ] [[package]] @@ -1659,9 +1654,9 @@ checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustix" -version = "0.38.40" +version = "0.38.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0" +checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" dependencies = [ "bitflags", "errno", @@ -1672,9 +1667,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.16" +version = "0.23.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eee87ff5d9b36712a58574e12e9f0ea80f915a5b0ac518d322b24a465617925e" +checksum = "9c9cc1d47e243d655ace55ed38201c19ae02c148ae56412ab8750e8f0166ab7f" dependencies = [ "once_cell", "ring", @@ -1698,6 +1693,9 @@ name = "rustls-pki-types" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" +dependencies = [ + "web-time", +] [[package]] name = "rustls-webpki" @@ -1733,9 +1731,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.214" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] @@ -1754,9 +1752,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.214" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", @@ -1765,9 +1763,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.132" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" dependencies = [ "itoa", "memchr", @@ -2134,9 +2132,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.87" +version = "2.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" dependencies = [ "proc-macro2", "quote", @@ -2145,9 +2143,9 @@ dependencies = [ [[package]] name = "sync_wrapper" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" dependencies = [ "futures-core", ] @@ -2187,11 +2185,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.2" +version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "037e29b009aa709f293b974da5cd33b15783c049e07f8435778ce8c4871525d8" +checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" dependencies = [ - "thiserror-impl 2.0.2", + "thiserror-impl 2.0.3", ] [[package]] @@ -2207,9 +2205,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.2" +version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4778c7e8ff768bdb32a58a2349903859fe719a320300d7d4ce8636f19a1e69" +checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" dependencies = [ "proc-macro2", "quote", @@ -2410,9 +2408,9 @@ checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" [[package]] name = "unicode-ident" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "unicode-normalization" @@ -2449,12 +2447,12 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.5.3" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d157f1b96d14500ffdc1f10ba712e780825526c03d9a49b4d0324b0d9113ada" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" dependencies = [ "form_urlencoded", - "idna 1.0.3", + "idna", "percent-encoding", ] @@ -2580,11 +2578,21 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "webpki-roots" -version = "0.26.6" +version = "0.26.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +checksum = "5d642ff16b7e79272ae451b7322067cdc17cadf68c23264be9d94a32319efe7e" dependencies = [ "rustls-pki-types", ] @@ -2843,9 +2851,9 @@ checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" [[package]] name = "yoke" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" dependencies = [ "serde", "stable_deref_trait", @@ -2855,9 +2863,9 @@ dependencies = [ [[package]] name = "yoke-derive" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", @@ -2888,18 +2896,18 @@ dependencies = [ [[package]] name = "zerofrom" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" +checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" dependencies = [ "zerofrom-derive", ] [[package]] name = "zerofrom-derive" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" dependencies = [ "proc-macro2", "quote", @@ -2951,9 +2959,9 @@ dependencies = [ [[package]] name = "zip" -version = "2.2.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc5e4288ea4057ae23afc69a4472434a87a2495cafce6632fd1c4ec9f5cf3494" +checksum = "99d52293fc86ea7cf13971b3bb81eb21683636e7ae24c729cdaf1b7c4157a352" dependencies = [ "aes", "arbitrary", @@ -2971,7 +2979,7 @@ dependencies = [ "pbkdf2", "rand", "sha1", - "thiserror 1.0.69", + "thiserror 2.0.3", "time", "zeroize", "zopfli", diff --git a/Cargo.toml b/Cargo.toml index 885ac0d..c52f4ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" name = "nhentai_archivist" readme = "readme.md" repository = "https://github.com/9-FS/nhentai_archivist" -version = "3.5.1" +version = "3.6.0" [dependencies] chrono = { version = "^0.4.0", features = ["serde"] } diff --git a/docker-compose.yaml b/docker-compose.yaml index 20d8f11..4227465 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,7 +1,7 @@ services: nhentai_archivist: container_name: "nhentai_archivist" - image: "ghcr.io/9-fs/nhentai_archivist:3.5.1" + image: "ghcr.io/9-fs/nhentai_archivist:3.6.0" environment: HOST_OS: "Unraid" TZ: "UTC" diff --git a/readme.md b/readme.md index 4dc6bc5..c841ebe 100644 --- a/readme.md +++ b/readme.md @@ -57,12 +57,17 @@ I'm happy about anyone who finds my software useful and feedback is also always This is the path to the file containing the nHentai ID you want to download, separated by line breaks. If this file exists, it has priority over tag search and console input. -- `FILENAME_TITLE_TYPE`, optional, defaults to `english` +- `FILENAME_TITLE_TYPE`, optional, defaults to `English` - Sets which title to use when naming downloaded files. Available options: - - `english`: Use the English title (default) - - `japanese`: Use the Japanese title if available, falls back to default if not present - - `pretty`: Use the Pretty title if available, falls back to default if not present + Determines which title type to use when naming downloaded hentai files. Available settings: + - `English` + - `Japanese` + - `Pretty` + + If a Japanese or pretty title is not available, the English title will be used instead. + +> [!IMPORTANT] +> If `FILENAME_TITLE_TYPE` is changed after hentai files have already been downloaded, existing files will not be renamed. They also will not be detected as already downloaded any more which can lead to duplicates. I therefore recommend to only change this setting before starting a fresh library. - `LIBRARY_PATH` @@ -152,7 +157,6 @@ CSRFTOKEN = "your token here" DATABASE_URL = "./db/db.sqlite" DONTDOWNLOADME_FILEPATH = "./config/dontdownloadme.txt" DOWNLOADME_FILEPATH = "./config/downloadme.txt" -FILENAME_TITLE_TYPE = "english" LIBRARY_PATH = "./hentai/" LIBRARY_SPLIT = 10000 NHENTAI_TAGS = ['language:"english"'] diff --git a/src/config.rs b/src/config.rs index 55e7034..6eb3ae3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,32 +1,5 @@ // Copyright (c) 2024 구FS, all rights reserved. Subject to the MIT licence in `licence.md`. -/// # Summary -/// Available title types for filenames -#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)] -#[serde(rename_all = "snake_case")] -pub enum Title { - /// Use English title - English, - /// Use Japanese title - Japanese, - /// Use Pretty title - Pretty, -} - -impl std::str::FromStr for Title { - type Err = String; - fn from_str(s: &str) -> Result { - match s.to_lowercase().trim() { - "english" => Ok(Self::English), - "japanese" => Ok(Self::Japanese), - "pretty" => Ok(Self::Pretty), - _ => { - log::warn!("Invalid title type \"{s}\", defaulting to English"); - Ok(Self::English) - } - } - } -} /// # Summary /// Collection of settings making up the configuration of the application. @@ -41,7 +14,7 @@ pub struct Config pub DEBUG: Option, // debug mode? pub DONTDOWNLOADME_FILEPATH: Option, // path to file containing hentai ID to not download, blacklist pub DOWNLOADME_FILEPATH: Option, // path to file containing hentai ID to download - pub FILENAME_TITLE_TYPE: Option, // which title to use for filenames: English,Japanese,Pretty + pub FILENAME_TITLE_TYPE: Option<TitleType>, // which title to use for filenames: English,Japanese,Pretty pub LIBRARY_PATH: String, // path to download hentai to pub LIBRARY_SPLIT: Option<u32>, // split library into subdirectories of maximum this many hentai, None or 0 to disable pub NHENTAI_TAGS: Option<Vec<String>>, // keep creating downloadme.txt from these tags and keep downloading (server mode), normal tags are in format "tag:{tag}" for example "tag:ffm-threesome"; if None: don't generate downloadme.txt, download hentai once (client mode) @@ -62,7 +35,7 @@ impl Default for Config DEBUG: None, // no entry in default config, defaults to false DONTDOWNLOADME_FILEPATH: Some("./config/dontdownloadme.txt".to_owned()), DOWNLOADME_FILEPATH: Some("./config/downloadme.txt".to_owned()), - FILENAME_TITLE_TYPE: Some(Title::English), // Default to English title + FILENAME_TITLE_TYPE: None, // no entry in default config, defaults to English LIBRARY_PATH: "./hentai/".to_owned(), LIBRARY_SPLIT: None, NHENTAI_TAGS: None, @@ -71,3 +44,19 @@ impl Default for Config } } } + + +/// # Summary +/// Title type to use for hentai filenames. +#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)] +pub enum TitleType +{ + English, + Japanese, + Pretty, +} + +impl Default for TitleType +{ + fn default() -> Self {Self::English} +} \ No newline at end of file diff --git a/src/hentai.rs b/src/hentai.rs index e2c23bb..a7e9b30 100644 --- a/src/hentai.rs +++ b/src/hentai.rs @@ -1,6 +1,7 @@ // Copyright (c) 2024 구FS, all rights reserved. Subject to the MIT licence in `licence.md`. use crate::api_response::*; use crate::comicinfoxml::*; +use crate::config::*; use crate::error::*; use crate::search_api::*; use std::io::Read; @@ -44,12 +45,13 @@ impl Hentai /// - `db`: database connection /// - `http_client`: reqwest http client /// - `nhentai_hentai_search_url`: nhentai.net hentai search API URL + /// - `filename_title_type`: which title to use for filenames /// - `library_path`: path to local hentai library /// - `library_split`: split library into subdirectories with maximum this number of hentai, 0 for no split /// /// # Returns /// - created hentai or error - pub async fn new(id: u32, db: &sqlx::sqlite::SqlitePool, http_client: &reqwest::Client, nhentai_hentai_search_url: &str, library_path: &str, library_split: u32, filename_title_type: &Option<Title>) -> Result<Self, HentaiNewError> + pub async fn new(id: u32, db: &sqlx::sqlite::SqlitePool, http_client: &reqwest::Client, nhentai_hentai_search_url: &str, filename_title_type: &TitleType, library_path: &str, library_split: u32) -> Result<Self, HentaiNewError> { const FILENAME_SIZE_MAX: u16 = 255; // maximum filename size [B] const TITLE_CHARACTERS_FORBIDDEN: &str = "\\/:*?\"<>|\t\n"; // forbidden characters in Windows file names @@ -60,7 +62,7 @@ impl Hentai let tags: Vec<Tag>; - if let Ok(Some(s)) = sqlx::query_as("SELECT id, media_id, num_pages, page_types, scanlator, title_english, title_pretty, upload_date FROM Hentai WHERE id = ?") + if let Ok(Some(s)) = sqlx::query_as("SELECT id, media_id, num_pages, page_types, scanlator, title_english, title_japanese, title_pretty, upload_date FROM Hentai WHERE id = ?") .bind(id) .fetch_optional(db).await // load hentai metadata from database { @@ -90,30 +92,33 @@ impl Hentai return Err(HentaiNewError::HentaiLengthInconsistency {page_types: hentai_table_row.page_types.len() as u16, num_pages: hentai_table_row.num_pages}); } - cbz_filename = match filename_title_type { - Some(Title::English) => hentai_table_row.title_english.clone().unwrap_or_default(), //not adding logging as english is default - Some(Title::Japanese) => { - match hentai_table_row.title_japanese.clone() { - Some(title) if !title.is_empty() => title, - _ => { - log::warn!("Japanese title not available for hentai {}, falling back to English title", id); - hentai_table_row.title_japanese.clone().unwrap_or_default() + cbz_filename = match filename_title_type // determine filename title depending on title type + { + TitleType::English => hentai_table_row.title_english.unwrap_or_default(), // english title or fallback to empty string + TitleType::Japanese => // non empty japanese title or fallback to english title + { + match hentai_table_row.title_japanese + { + Some(s) if !s.is_empty() => s, + _ => + { + log::warn!("Japanese title is not available. Falling back to English title for hentai filename."); + hentai_table_row.title_english.unwrap_or_default() // fallback to english title or further to empty string } } }, - Some(Title::Pretty) => { - match hentai_table_row.title_pretty.clone() { - Some(title) if !title.is_empty() => title, - _ => { - log::warn!("Pretty title not available for hentai {}, falling back to English title", id); - hentai_table_row.title_pretty.clone().unwrap_or_default() + TitleType::Pretty => // non empty pretty title or fallback to english title + { + match hentai_table_row.title_pretty.clone() + { + Some(s) if !s.is_empty() => s, + _ => + { + log::warn!("Pretty title is not available. Falling back to English title for hentai filename."); + hentai_table_row.title_english.unwrap_or_default() // fallback to english title or further to empty string } } }, - None => { - log::debug!("No title type specified for hentai {}, using English title", id); - hentai_table_row.title_english.clone().unwrap_or_default() - } }; cbz_filename.retain(|c| !TITLE_CHARACTERS_FORBIDDEN.contains(c)); // remove forbidden characters @@ -422,4 +427,4 @@ pub struct HentaiTableRow pub title_japanese: Option<String>, pub title_pretty: Option<String>, pub upload_date: chrono::DateTime<chrono::Utc>, -} +} \ No newline at end of file diff --git a/src/main_inner.rs b/src/main_inner.rs index 2be2421..78ab646 100644 --- a/src/main_inner.rs +++ b/src/main_inner.rs @@ -104,7 +104,16 @@ pub async fn main_inner(config: Config) -> Result<(), Error> let hentai: Hentai; // hentai to download - match Hentai::new(*hentai_id, &db, &http_client, NHENTAI_HENTAI_SEARCH_URL, &config.LIBRARY_PATH, config.LIBRARY_SPLIT.unwrap_or_default(), &config.FILENAME_TITLE_TYPE ).await // create hentai, use u32 with 0 to disable library split and not Option<u32> with None, because that would make Some(0) an invalid state + match Hentai::new // create hentai + ( + *hentai_id, + &db, + &http_client, + NHENTAI_HENTAI_SEARCH_URL, + &config.FILENAME_TITLE_TYPE.clone().unwrap_or_default(), // if not set: default to english title + &config.LIBRARY_PATH, + config.LIBRARY_SPLIT.unwrap_or_default() // use u32 with 0 to disable library split and not Option<u32> with None, because that would make Some(0) an invalid state + ).await { Ok(o) => hentai = o, // hentai created successfully Err(e) => // hentai creation failed diff --git a/src/search_api.rs b/src/search_api.rs index 6e7eb45..a9d3ed5 100644 --- a/src/search_api.rs +++ b/src/search_api.rs @@ -37,6 +37,7 @@ pub async fn search_by_id(http_client: &reqwest::Client, nhentai_hentai_search_u page_types: r_serialised.images.pages.iter().map(|page| format!("{:?}", page.t)).collect::<Vec<String>>().join(""), scanlator: r_serialised.scanlator, title_english: r_serialised.title.english, + title_japanese: r_serialised.title.japanese, title_pretty: r_serialised.title.pretty, upload_date: r_serialised.upload_date, });