diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..4b764ea --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,2948 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "ahash" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" + +[[package]] +name = "anstyle-parse" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.61.2", +] + +[[package]] +name = "anyhow" +version = "1.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" + +[[package]] +name = "ascii-canvas" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6" +dependencies = [ + "term", +] + +[[package]] +name = "assert-json-diff" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e4f2b81832e72834d7518d8487a0396a28cc408186a2e8854c0f98011faf12" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "assert_cmd" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcbb6924530aa9e0432442af08bbcafdad182db80d2e560da42a6d442535bf85" +dependencies = [ + "anstyle", + "bstr", + "libc", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + +[[package]] +name = "async-attributes" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3203e79f4dd9bdda415ed03cf14dae5a2bf775c683a00f94e9cd1faf0f596e5" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "async-channel" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" +dependencies = [ + "concurrent-queue", + "event-listener 2.5.3", + "futures-core", +] + +[[package]] +name = "async-channel" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "924ed96dd52d1b75e9c1a3e6275715fd320f5f9439fb5a4a11fa51f4221158d2" +dependencies = [ + "concurrent-queue", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-executor" +version = "1.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497c00e0fd83a72a79a39fcbd8e3e2f055d6f6c7e025f3b3d91f4f8e76527fb8" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "pin-project-lite", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c" +dependencies = [ + "async-channel 2.5.0", + "async-executor", + "async-io", + "async-lock", + "blocking", + "futures-lite", + "once_cell", +] + +[[package]] +name = "async-io" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456b8a8feb6f42d237746d4b3e9a178494627745c3c56c6ea55d92ba50d026fc" +dependencies = [ + "autocfg", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite", + "parking", + "polling", + "rustix", + "slab", + "windows-sys 0.61.2", +] + +[[package]] +name = "async-lock" +version = "3.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f7f2596bd5b78a9fec8088ccd89180d7f9f55b94b0576823bbbdc72ee8311" +dependencies = [ + "event-listener 5.4.1", + "event-listener-strategy", + "pin-project-lite", +] + +[[package]] +name = "async-object-pool" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "333c456b97c3f2d50604e8b2624253b7f787208cb72eb75e64b0ad11b221652c" +dependencies = [ + "async-std", +] + +[[package]] +name = "async-process" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc50921ec0055cdd8a16de48773bfeec5c972598674347252c0399676be7da75" +dependencies = [ + "async-channel 2.5.0", + "async-io", + "async-lock", + "async-signal", + "async-task", + "blocking", + "cfg-if", + "event-listener 5.4.1", + "futures-lite", + "rustix", +] + +[[package]] +name = "async-signal" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43c070bbf59cd3570b6b2dd54cd772527c7c3620fce8be898406dd3ed6adc64c" +dependencies = [ + "async-io", + "async-lock", + "atomic-waker", + "cfg-if", + "futures-core", + "futures-io", + "rustix", + "signal-hook-registry", + "slab", + "windows-sys 0.61.2", +] + +[[package]] +name = "async-std" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8e079a4ab67ae52b7403632e4618815d6db36d2a010cfe41b02c1b1578f93b" +dependencies = [ + "async-attributes", + "async-channel 1.9.0", + "async-global-executor", + "async-io", + "async-lock", + "async-process", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + +[[package]] +name = "async-task" +version = "4.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" + +[[package]] +name = "async-trait" +version = "0.1.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "basic-cookies" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67bd8fd42c16bdb08688243dc5f0cc117a3ca9efeeaba3a345a18a6159ad96f7" +dependencies = [ + "lalrpop", + "lalrpop-util", + "regex", +] + +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" + +[[package]] +name = "blocking" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e83f8d02be6967315521be875afa792a316e28d57b5a2d401897e2a7921b7f21" +dependencies = [ + "async-channel 2.5.0", + "async-task", + "futures-io", + "futures-lite", + "piper", +] + +[[package]] +name = "bstr" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63044e1ae8e69f3b5a92c736ca6269b8d12fa7efe39bf34ddb06d102cf0e2cab" +dependencies = [ + "memchr", + "regex-automata", + "serde", +] + +[[package]] +name = "bumpalo" +version = "3.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" + +[[package]] +name = "bytes" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3" + +[[package]] +name = "cc" +version = "1.2.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a0aeaff4ff1a90589618835a598e545176939b97874f7abc7851caa0618f203" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "chrono" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "clap" +version = "4.5.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "clap_lex" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" + +[[package]] +name = "colorchoice" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + +[[package]] +name = "csv" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52cd9d68cf7efc6ddfaaee42e7288d3a99d613d4b50f76ce9827ae0c6e14f938" +dependencies = [ + "csv-core", + "itoa", + "ryu", + "serde_core", +] + +[[package]] +name = "csv-core" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "704a3c26996a80471189265814dbc2c257598b96b8a7feae2d31ace646bb9782" +dependencies = [ + "memchr", +] + +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + +[[package]] +name = "directories" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a49173b84e034382284f27f1af4dcbbd231ffa358c0fe316541a7337f376a35" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + +[[package]] +name = "ena" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d248bdd43ce613d87415282f69b9bb99d947d290b10962dd6c56233312c2ad5" +dependencies = [ + "log", +] + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "event-listener" +version = "5.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93" +dependencies = [ + "event-listener 5.4.1", + "pin-project-lite", +] + +[[package]] +name = "fallible-iterator" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" + +[[package]] +name = "fallible-streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" + +[[package]] +name = "fastrand" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" + +[[package]] +name = "find-msvc-tools" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645cbb3a84e60b7531617d5ae4e57f7e27308f6445f5abf653209ea76dec8dff" + +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + +[[package]] +name = "float-cmp" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b09cf3155332e944990140d967ff5eceb70df778b34f77d8075db46e4704e6d8" +dependencies = [ + "num-traits", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-lite" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "parking", + "pin-project-lite", +] + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-core", + "futures-io", + "futures-macro", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasip2", +] + +[[package]] +name = "gloo-timers" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb143cf96099802033e0d4f4963b19fd2e0b728bcf076cd9cf7f6634f092994" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "h2" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0beca50380b1fc32983fc1cb4587bfa4bb9e78fc259aad4a0032d2080309222d" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + +[[package]] +name = "hashlink" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" +dependencies = [ + "hashbrown 0.14.5", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" + +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "httpmock" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08ec9586ee0910472dec1a1f0f8acf52f0fdde93aea74d70d4a3107b4be0fd5b" +dependencies = [ + "assert-json-diff", + "async-object-pool", + "async-std", + "async-trait", + "base64", + "basic-cookies", + "crossbeam-utils", + "form_urlencoded", + "futures-util", + "hyper", + "lazy_static", + "levenshtein", + "log", + "regex", + "serde", + "serde_json", + "serde_regex", + "similar", + "tokio", + "url", +] + +[[package]] +name = "hyper" +version = "0.14.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41dfc780fdec9373c01bae43289ea34c972e40ee3c9f6b3c8801a35f35586ce7" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2 0.5.10", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" +dependencies = [ + "futures-util", + "http", + "hyper", + "rustls", + "tokio", + "tokio-rustls", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ad4bb2b565bca0645f4d68c5c9af97fba094e9791da685bf83cb5f3ce74acf2" +dependencies = [ + "equivalent", + "hashbrown 0.16.1", +] + +[[package]] +name = "ipnet" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" + +[[package]] +name = "is-terminal" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] +name = "itertools" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + +[[package]] +name = "js-sys" +version = "0.3.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + +[[package]] +name = "lalrpop" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cb077ad656299f160924eb2912aa147d7339ea7d69e1b5517326fdcec3c1ca" +dependencies = [ + "ascii-canvas", + "bit-set", + "ena", + "itertools", + "lalrpop-util", + "petgraph", + "pico-args", + "regex", + "regex-syntax", + "string_cache", + "term", + "tiny-keccak", + "unicode-xid", + "walkdir", +] + +[[package]] +name = "lalrpop-util" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "507460a910eb7b32ee961886ff48539633b788a36b65692b95f225b844c82553" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "levenshtein" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760" + +[[package]] +name = "libc" +version = "0.2.178" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091" + +[[package]] +name = "libredox" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616" +dependencies = [ + "bitflags 2.10.0", + "libc", +] + +[[package]] +name = "libsqlite3-sys" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c10584274047cb335c23d3e61bcef8e323adae7c5c8c760540f73610177fc3f" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "linux-raw-sys" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" + +[[package]] +name = "litemap" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +dependencies = [ + "value-bag", +] + +[[package]] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mio" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "mov-renamarr" +version = "0.1.0" +dependencies = [ + "anyhow", + "assert_cmd", + "chrono", + "clap", + "csv", + "directories", + "httpmock", + "is-terminal", + "libc", + "num_cpus", + "owo-colors", + "predicates", + "rayon", + "regex", + "reqwest", + "rusqlite", + "serde", + "serde_json", + "strsim", + "tempfile", + "thiserror", + "toml", + "walkdir", +] + +[[package]] +name = "native-tls" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "normalize-line-endings" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] +name = "openssl" +version = "0.10.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08838db121398ad17ab8531ce9de97b244589089e290a384c900cb9ff7434328" +dependencies = [ + "bitflags 2.10.0", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "openssl-probe" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" + +[[package]] +name = "openssl-sys" +version = "0.9.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82cab2d520aa75e3c58898289429321eb788c3106963d0dc886ec7a5f4adc321" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + +[[package]] +name = "owo-colors" +version = "4.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c6901729fa79e91a0913333229e9ca5dc725089d1c363b2f4b4760709dc4a52" + +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "petgraph" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" +dependencies = [ + "fixedbitset", + "indexmap", +] + +[[package]] +name = "phf_shared" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pico-args" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "piper" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c8c490f422ef9a4efd2cb5b42b76c8613d7e7dfc1caf667b8a3350a5acc066" +dependencies = [ + "atomic-waker", + "fastrand", + "futures-io", +] + +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + +[[package]] +name = "polling" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e4f59085d47d8241c88ead0f274e8a0cb551f3625263c05eb8dd897c34218" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi", + "pin-project-lite", + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "predicates" +version = "3.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5d19ee57562043d37e82899fade9a22ebab7be9cef5026b07fda9cdd4293573" +dependencies = [ + "anstyle", + "difflib", + "float-cmp", + "normalize-line-endings", + "predicates-core", + "regex", +] + +[[package]] +name = "predicates-core" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "727e462b119fe9c93fd0eb1429a5f7647394014cf3c04ab2c0350eeb09095ffa" + +[[package]] +name = "predicates-tree" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72dd2d6d381dfb73a193c7fca536518d7caee39fc8503f74e7dc0be0531b425c" +dependencies = [ + "predicates-core", + "termtree", +] + +[[package]] +name = "proc-macro2" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9695f8df41bb4f3d222c95a67532365f569318332d03d5f3f67f37b20e6ebdf0" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "rayon" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags 2.10.0", +] + +[[package]] +name = "redox_users" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +dependencies = [ + "getrandom 0.2.16", + "libredox", + "thiserror", +] + +[[package]] +name = "regex" +version = "1.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" + +[[package]] +name = "reqwest" +version = "0.11.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-rustls", + "hyper-tls", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tokio-rustls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", + "winreg", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.16", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rusqlite" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b838eba278d213a8beaf485bd313fd580ca4505a00d5871caeb1457c55322cae" +dependencies = [ + "bitflags 2.10.0", + "fallible-iterator", + "fallible-streaming-iterator", + "hashlink", + "libsqlite3-sys", + "smallvec", +] + +[[package]] +name = "rustix" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "146c9e247ccc180c1f61615433868c99f3de3ae256a30a43b49f67c2d9171f34" +dependencies = [ + "bitflags 2.10.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls" +version = "0.21.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" +dependencies = [ + "log", + "ring", + "rustls-webpki", + "sct", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +dependencies = [ + "base64", +] + +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schannel" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags 2.10.0", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc1f0cbffaac4852523ce30d8bd3c5cdc873501d96ff467ca09b6767bb8cd5c0" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "serde_json" +version = "1.0.148" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3084b546a1dd6289475996f182a22aba973866ea8e8b02c51d9f46b1336a22da" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_regex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8136f1a4ea815d7eac4101cfd0b16dc0cb5e1fe1b8609dfd728058656b7badf" +dependencies = [ + "regex", + "serde", +] + +[[package]] +name = "serde_spanned" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "similar" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa" + +[[package]] +name = "siphasher" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" + +[[package]] +name = "slab" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "socket2" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17129e116933cf371d018bb80ae557e889637989d8638274fb25622827b03881" +dependencies = [ + "libc", + "windows-sys 0.60.2", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "string_cache" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf776ba3fa74f83bf4b63c3dcbbf82173db2632ed8452cb2d891d33f459de70f" +dependencies = [ + "new_debug_unreachable", + "parking_lot", + "phf_shared", + "precomputed-hash", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "655da9c7eb6305c55742045d5a8d2037996d61d8de95806335c7c86ce0f82e9c" +dependencies = [ + "fastrand", + "getrandom 0.3.4", + "once_cell", + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "term" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" +dependencies = [ + "dirs-next", + "rustversion", + "winapi", +] + +[[package]] +name = "termtree" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683" + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "tinystr" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tokio" +version = "1.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "signal-hook-registry", + "socket2 0.6.1", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2efa149fe76073d6e8fd97ef4f4eca7b67f599660115591483572e406e165594" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "toml_write", + "winnow", +] + +[[package]] +name = "toml_write" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-ident" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08bc136a29a3d1758e07a9cca267be308aeebf5cfd5a10f3f67ab2097683ef5b" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "value-bag" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ba6f5989077681266825251a52748b8c1d8a4ad098cc37e440103d0ea717fc0" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wait-timeout" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11" +dependencies = [ + "libc", +] + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.1+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836d9622d604feee9e5de25ac10e3ea5f2d65b41eac0d9ce72eb5deae707ce7c" +dependencies = [ + "cfg-if", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 2.0.111", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-sys" +version = "0.3.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b32828d774c412041098d182a8b38b16ea816958e07cf40eec2bc080ae137ac" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "0.25.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "winnow" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829" +dependencies = [ + "memchr", +] + +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + +[[package]] +name = "wit-bindgen" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" + +[[package]] +name = "writeable" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" + +[[package]] +name = "yoke" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd74ec98b9250adb3ca554bdde269adf631549f51d8a8f8f0a10b50f1cb298c3" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8a8d209fdf45cf5138cbb5a506f6b52522a25afccc534d1475dad8e31105c6a" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", + "synstructure", +] + +[[package]] +name = "zerotrie" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + +[[package]] +name = "zmij" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9747e91771f56fd7893e1164abd78febd14a670ceec257caad15e051de35f06" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..20e9b29 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "mov-renamarr" +version = "0.1.0" +edition = "2024" +license = "MIT" + +[dependencies] +anyhow = "1.0" +chrono = "0.4" +clap = { version = "4.5", features = ["derive"] } +csv = "1.3" +directories = "5.0" +is-terminal = "0.4" +libc = "0.2" +num_cpus = "1.16" +owo-colors = "4.1" +rayon = "1.10" +regex = "1.10" +reqwest = { version = "0.11", features = ["blocking", "json", "rustls-tls"] } +rusqlite = { version = "0.31", features = ["bundled"] } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +strsim = "0.11" +thiserror = "1.0" +toml = "0.8" +walkdir = "2.5" + +[dev-dependencies] +assert_cmd = "2.0" +httpmock = "0.7" +predicates = "3.1" +tempfile = "3.10" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..58b2133 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 44r0n7 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/PLAN.md b/PLAN.md new file mode 100644 index 0000000..95de29c --- /dev/null +++ b/PLAN.md @@ -0,0 +1,96 @@ +# Mov Renamarr CLI - Project Plan + +## Goal +Build a Linux CLI that scans a directory of movie files, queries online metadata (OMDb/TMDb), and writes Radarr-compatible folder and file names to an output directory. Project name: Mov Renamarr. + +## Core Requirements +- Input: directory tree containing video files. +- Output: `Movie Title (Year)/Movie Title (Year) [Quality] [id].ext`. +- Uses `ffprobe` for media info and filename parsing for hints. +- Queries OMDb/TMDb, with caching to avoid repeat lookups. +- Non-interactive by default: skip ambiguous/unmatched files, report them at end. +- Optional `--interactive` to confirm matches. +- Linux support only (for now). + +## Non-Goals (for MVP) +- No Radarr API integration. +- No TV/series handling. +- No transcoding or media repair. + +## Decisions to Lock In +- Default action: copy (safe default). +- Optional flags: `--move` and `--rename-in-place`. +- Config file support (XDG by default) + CLI overrides. Config format: TOML. +- Provider selection: auto based on available API keys, with optional user preference. Default auto priority: TMDb. +- Match scoring and minimum confidence threshold. +- Cache storage format (SQLite vs JSON) + TTL + `--refresh-cache`. +- Quality tags default to resolution only; configurable via CLI/config. +- Optional local LLM integration (Ollama) for filename parsing and lookup assist, disabled by default. +- Default report format: text. +- Sidecar notes: off by default; opt-in only. +- Include top-3 candidates in unresolved items by default. +- Emphasize performance, broad Linux compatibility, and robust error handling. +- UX: per-file status line (file/provider/result/new name), progress counts, color when TTY, `--verbose` for debug details. +- Collision policy: default skip if destination exists; optional `--overwrite` or `--suffix` to avoid data loss. +- Sidecar files: optionally move/copy all sidecar files with `--sidecars` flag (off by default). +- Concurrency: default jobs = min(4, max(1, floor(cores/2))); default net-jobs = min(2, jobs); allow overrides. +- ffprobe required (no native parsing fallback). +- Reports: stdout by default; optional report file name pattern `mov-renamarr-report-YYYYMMDD-HHMMSS.txt` when `--report` is set without a path. +- Config precedence: defaults -> config TOML -> env -> CLI flags. +- Config path: `$XDG_CONFIG_HOME/mov-renamarr/config.toml` (fallback `~/.config/mov-renamarr/config.toml`). +- Cache path: `$XDG_CACHE_HOME/mov-renamarr/cache.db` (fallback `~/.cache/mov-renamarr/cache.db`). +- Report file default location: current working directory when `--report` is set without a path. +- Provider base URLs configurable in config/env to support testing/mocking. +- Create a commented default config file on first run and notify the user. + +## Proposed CLI (Draft) +- `mov-renamarr --input --output ` +- `--config ` (default: XDG config) +- `--provider auto|omdb|tmdb|both` +- `--api-key-omdb ` / `--api-key-tmdb ` (override config/env) +- `--cache ` (default: `~/.cache/mov-renamarr.db`) +- `--refresh-cache` (bypass cache) +- `--dry-run` +- `--move` / `--rename-in-place` +- `--interactive` +- `--report ` + `--report-format text|json|csv` +- `--sidecar-notes` (write per-file skip notes) +- `--min-score <0-100>` +- `--include-id` (tmdb/omdb/imdb if available) +- `--quality-tags resolution|resolution,codec,source` +- `--color auto|always|never` +- `--jobs ` +- `--net-jobs ` +- `--no-lookup` (skip external providers; use filename/LLM only) +- `--llm-mode off|parse|assist` (default: off) +- `--llm-endpoint ` (Ollama, default `http://localhost:11434`) +- `--llm-model ` (Ollama model name) +- `--llm-timeout ` / `--llm-max-tokens ` + +## Matching Heuristics (Draft) +- Parse filename for title/year hints; strip extra release metadata. +- Use `ffprobe` for duration and resolution. +- Prefer exact year match; allow +/- 1 year when missing. +- Use string similarity + runtime delta to choose best match. + +## Pipeline (Draft) +1. Load config (XDG) + merge CLI overrides. +2. Discover files and filter by extension; skip output subtree when output != input to avoid reprocessing. +3. Parse filename hints (title/year) and strip release metadata (optionally via LLM parse). +4. Run `ffprobe` for duration/resolution/codec. +5. Select provider(s) based on available API keys and user preference. +6. Query provider(s) with hints (LLM assist may propose candidates but must be verified). +7. Score and select match; if below threshold, mark as unresolved. +8. Build Radarr-compatible output path. +9. Copy/move/rename-in-place file to output directory. +10. Write summary report of successes and unresolved items. + +## Milestones +- M0: Project scaffold and plan (done). +- M1: CLI skeleton and config parsing. +- M2: `ffprobe` integration and media metadata model. +- M3: OMDb/TMDb client + caching. +- M4: Matching, naming, and file move/copy. +- M5: Reporting, tests, and polish. +- M6: Automated test harness and fixtures. +- M7: Performance pass and profiling. diff --git a/README.md b/README.md index 8610d3c..26d5d7e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,106 @@ -# mov-renamarr +# mov-renamarr :clapper: +Fast, safe CLI to rename movie files into Radarr-compatible folders and filenames on Linux. It uses `ffprobe` for media details, filename parsing for hints, and optional online metadata (TMDb/OMDb) with caching. Default action is copy; move/rename-in-place are opt-in. + +## Features :sparkles: +- Radarr-style output: `Title (Year)/Title (Year) [quality] [id].ext` +- Safe defaults: copy by default, skip on collision (opt-in overwrite/suffix) +- Metadata providers: TMDb, OMDb, or both (auto picks TMDb if available) +- Optional local LLM (Ollama) for filename parsing and lookup assist +- SQLite cache to reduce repeated lookups +- Reports in text/json/csv (stdout by default) +- Concurrency controls with sensible defaults + +## Requirements :clipboard: +- Linux +- `ffprobe` in `PATH` (install via ffmpeg) + +## Install :package: +From source: +```bash +cargo build --release +``` +Binary will be at `target/release/mov-renamarr`. + +Install with Cargo: +```bash +# From a git repo +cargo install --git --locked + +# From a local checkout +cargo install --path . --locked +``` + +## Quick start :rocket: +Create a default config (with comments) and see the config path: +```bash +mov-renamarr +``` + +Dry-run with TMDb: +```bash +mov-renamarr --input /path/to/in --output /path/to/out --dry-run --provider tmdb +``` + +Rename in place (no network lookups): +```bash +mov-renamarr --input /path/to/in --rename-in-place --no-lookup +``` + +## Configuration :gear: +Default config location: +`$XDG_CONFIG_HOME/mov-renamarr/config.toml` (fallback `~/.config/mov-renamarr/config.toml`) + +Cache location: +`$XDG_CACHE_HOME/mov-renamarr/cache.db` (fallback `~/.cache/mov-renamarr/cache.db`) + +The app creates a commented default config on first run and prints the path. + +Key options (TOML): +- `provider = "auto"|"tmdb"|"omdb"|"both"` +- `tmdb.api_key` or `tmdb.bearer_token` (TMDb read access token supported) +- `omdb.api_key` +- `quality_tags = ["resolution"]` (or add `codec`, `source`) +- `llm.mode = "off"|"parse"|"assist"` +- `llm.endpoint = "http://localhost:11434"` +- `llm.model = "Qwen2.5:latest"` (recommended for accuracy: `Qwen2.5:14b`) +- `jobs = "auto"|N`, `net_jobs = "auto"|N` +- `sidecars = false` (copy/move sidecars when true) + +CLI flags override config, and env vars override config as well. + +## Providers :globe_with_meridians: +- **TMDb**: preferred when available. Supports API key or read-access bearer token. +- **OMDb**: optional, API key required. +- **Auto**: uses TMDb if configured, else OMDb. +- **No-lookup**: `--no-lookup` (or `--offline`) uses filename/LLM only. + +## LLM (optional) :robot: +If enabled, Ollama is used for: +- filename parsing (`llm.mode = "parse"`) +- lookup assistance (`llm.mode = "assist"`) + +LLM output is treated as hints; provider results (when enabled) remain the source of truth. + +## Reports :memo: +By default, output is printed to stdout. +To write a report file: +```bash +mov-renamarr --input ... --output ... --report +``` +This creates `mov-renamarr-report-YYYYMMDD-HHMMSS.txt` in the current directory. + +Formats: `--report-format text|json|csv` + +## Safety and collisions :shield: +Default is **skip** if the destination exists. Options: +- `--overwrite` to overwrite +- `--suffix` to append ` (1)`, ` (2)`, ... + +## Testing :test_tube: +```bash +cargo test +``` + +## License :scroll: +MIT (see `LICENSE`). diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..b15f1ee --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,157 @@ +use std::path::PathBuf; +use std::str::FromStr; + +use clap::{Parser, ValueEnum}; +use serde::Deserialize; + +#[derive(Parser, Debug)] +#[command(name = "mov-renamarr", version, about = "Rename movie files into Radarr-compatible naming")] +pub struct Cli { + #[arg(long, value_name = "DIR")] + pub input: PathBuf, + + #[arg(long, value_name = "DIR")] + pub output: Option, + + #[arg(long, value_name = "PATH")] + pub config: Option, + + #[arg(long, value_enum)] + pub provider: Option, + + #[arg(long = "api-key-omdb")] + pub api_key_omdb: Option, + + #[arg(long = "api-key-tmdb")] + pub api_key_tmdb: Option, + + #[arg(long, value_name = "PATH")] + pub cache: Option, + + #[arg(long)] + pub refresh_cache: bool, + + #[arg(long)] + pub dry_run: bool, + + #[arg(long = "move", conflicts_with = "rename_in_place")] + pub move_files: bool, + + #[arg(long = "rename-in-place", conflicts_with = "move_files")] + pub rename_in_place: bool, + + #[arg(long)] + pub interactive: bool, + + #[arg( + long, + value_name = "PATH", + num_args = 0..=1, + default_missing_value = "__DEFAULT__" + )] + pub report: Option, + + #[arg(long, value_enum)] + pub report_format: Option, + + #[arg(long)] + pub sidecar_notes: bool, + + #[arg(long)] + pub sidecars: bool, + + #[arg(long)] + pub overwrite: bool, + + #[arg(long)] + pub suffix: bool, + + #[arg(long)] + pub min_score: Option, + + #[arg(long)] + pub include_id: bool, + + #[arg(long, value_name = "LIST")] + pub quality_tags: Option, + + #[arg(long, value_enum)] + pub color: Option, + + #[arg(long, value_enum)] + pub llm_mode: Option, + + #[arg(long, value_name = "URL")] + pub llm_endpoint: Option, + + #[arg(long, value_name = "NAME")] + pub llm_model: Option, + + #[arg(long, value_name = "SECONDS")] + pub llm_timeout: Option, + + #[arg(long, value_name = "N")] + pub llm_max_tokens: Option, + + #[arg(long, value_parser = parse_jobs_arg)] + pub jobs: Option, + + #[arg(long, value_parser = parse_jobs_arg)] + pub net_jobs: Option, + + #[arg(long, alias = "offline")] + pub no_lookup: bool, + + #[arg(long)] + pub verbose: bool, +} + +#[derive(Clone, Debug, ValueEnum, Eq, PartialEq, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum ProviderChoice { + Auto, + Omdb, + Tmdb, + Both, +} + +#[derive(Clone, Debug, ValueEnum, Eq, PartialEq, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum ReportFormat { + Text, + Json, + Csv, +} + +#[derive(Clone, Debug, ValueEnum, Eq, PartialEq, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum ColorMode { + Auto, + Always, + Never, +} + +#[derive(Clone, Debug, ValueEnum, Eq, PartialEq, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum LlmMode { + Off, + Parse, + Assist, +} + +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum JobsArg { + Auto, + Fixed(usize), +} + +fn parse_jobs_arg(value: &str) -> Result { + if value.eq_ignore_ascii_case("auto") { + return Ok(JobsArg::Auto); + } + let parsed = usize::from_str(value).map_err(|_| "jobs must be an integer or 'auto'".to_string())?; + if parsed == 0 { + return Err("jobs must be >= 1".to_string()); + } + Ok(JobsArg::Fixed(parsed)) +} diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..9cc9b99 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,774 @@ +use std::env; +use std::fs; +use std::path::{Path, PathBuf}; +use std::str::FromStr; + +use anyhow::{anyhow, Context, Result}; +use directories::BaseDirs; +use serde::Deserialize; + +use crate::cli::{Cli, ColorMode, JobsArg, LlmMode, ProviderChoice, ReportFormat}; + +#[derive(Clone, Debug)] +pub struct Settings { + pub input: PathBuf, + pub output: PathBuf, + pub provider: ProviderChoice, + pub api_key_omdb: Option, + pub api_key_tmdb: Option, + pub cache_path: PathBuf, + pub cache_ttl_days: u32, + pub refresh_cache: bool, + pub report_format: ReportFormat, + pub report_path: Option, + pub sidecar_notes: bool, + pub sidecars: bool, + pub overwrite: bool, + pub suffix: bool, + pub min_score: u8, + pub include_id: bool, + pub quality_tags: QualityTags, + pub color: ColorMode, + pub llm: LlmSettings, + pub jobs: usize, + pub net_jobs: usize, + pub no_lookup: bool, + pub dry_run: bool, + pub move_files: bool, + pub rename_in_place: bool, + pub interactive: bool, + pub verbose: bool, + pub omdb_base_url: String, + pub tmdb_base_url: String, +} + +#[derive(Clone, Debug)] +pub struct QualityTags { + pub resolution: bool, + pub codec: bool, + pub source: bool, +} + +impl Default for QualityTags { + fn default() -> Self { + Self { + resolution: true, + codec: false, + source: false, + } + } +} + +#[derive(Clone, Debug)] +pub struct LlmSettings { + pub mode: LlmMode, + pub endpoint: String, + pub model: Option, + pub timeout_seconds: u64, + pub max_tokens: Option, +} + +impl Default for LlmSettings { + fn default() -> Self { + Self { + mode: LlmMode::Off, + endpoint: "http://localhost:11434".to_string(), + model: None, + timeout_seconds: 30, + max_tokens: None, + } + } +} + +#[derive(Debug, Deserialize, Default)] +struct FileConfig { + provider: Option, + api_key_omdb: Option, + api_key_tmdb: Option, + cache_path: Option, + cache_ttl_days: Option, + refresh_cache: Option, + report_format: Option, + sidecar_notes: Option, + sidecars: Option, + overwrite: Option, + suffix: Option, + min_score: Option, + include_id: Option, + quality_tags: Option, + color: Option, + jobs: Option, + net_jobs: Option, + llm: Option, + omdb_base_url: Option, + tmdb_base_url: Option, + no_lookup: Option, +} + +#[derive(Debug, Deserialize, Default)] +struct FileLlmConfig { + mode: Option, + endpoint: Option, + model: Option, + timeout_seconds: Option, + max_tokens: Option, +} + +#[derive(Debug, Deserialize)] +#[serde(untagged)] +enum QualityTagsValue { + List(Vec), + Single(String), +} + +#[derive(Debug, Deserialize)] +#[serde(untagged)] +enum JobValue { + String(String), + Number(u64), +} + +pub fn build_settings(cli: &Cli) -> Result { + let config_path = resolve_config_path(cli.config.as_deref())?; + if let Err(err) = ensure_default_config(&config_path) { + eprintln!( + "Warning: failed to create default config at {}: {}", + config_path.display(), + err + ); + } + let file_config = load_config_file(&config_path)?; + + let input = cli.input.clone(); + let output = resolve_output(cli)?; + + let mut settings = Settings { + input, + output, + provider: ProviderChoice::Auto, + api_key_omdb: None, + api_key_tmdb: None, + cache_path: default_cache_path()?, + cache_ttl_days: 30, + refresh_cache: false, + report_format: ReportFormat::Text, + report_path: resolve_report_path(cli)?, + sidecar_notes: false, + sidecars: false, + overwrite: false, + suffix: false, + min_score: 80, + include_id: false, + quality_tags: QualityTags::default(), + color: ColorMode::Auto, + llm: LlmSettings::default(), + jobs: default_jobs(), + net_jobs: default_net_jobs(default_jobs()), + no_lookup: false, + dry_run: cli.dry_run, + move_files: cli.move_files, + rename_in_place: cli.rename_in_place, + interactive: cli.interactive, + verbose: cli.verbose, + omdb_base_url: "https://www.omdbapi.com".to_string(), + tmdb_base_url: "https://api.themoviedb.org/3".to_string(), + }; + + apply_file_config(&mut settings, &file_config)?; + apply_env_overrides(&mut settings)?; + apply_cli_overrides(&mut settings, cli)?; + + validate_settings(&mut settings)?; + + Ok(settings) +} + +pub fn init_default_config() -> Result { + let config_path = resolve_config_path(None)?; + ensure_default_config(&config_path)?; + Ok(config_path) +} + +fn resolve_output(cli: &Cli) -> Result { + match (cli.rename_in_place, cli.output.as_ref()) { + (true, None) => Ok(cli.input.clone()), + (true, Some(out)) => { + if out != &cli.input { + Err(anyhow!( + "--rename-in-place requires output to be omitted or the same as input" + )) + } else { + Ok(out.clone()) + } + } + (false, Some(out)) => { + if out == &cli.input { + Err(anyhow!( + "output directory must be different from input unless --rename-in-place is set" + )) + } else { + Ok(out.clone()) + } + } + (false, None) => Err(anyhow!("--output is required unless --rename-in-place is set")), + } +} + +fn resolve_config_path(cli_path: Option<&Path>) -> Result { + if let Some(path) = cli_path { + return Ok(path.to_path_buf()); + } + let dirs = BaseDirs::new().ok_or_else(|| anyhow!("unable to resolve XDG config directory"))?; + Ok(dirs.config_dir().join("mov-renamarr").join("config.toml")) +} + +fn default_cache_path() -> Result { + let dirs = BaseDirs::new().ok_or_else(|| anyhow!("unable to resolve XDG cache directory"))?; + Ok(dirs.cache_dir().join("mov-renamarr").join("cache.db")) +} + +fn load_config_file(path: &Path) -> Result { + if !path.exists() { + return Ok(FileConfig::default()); + } + let raw = fs::read_to_string(path) + .with_context(|| format!("failed to read config file: {}", path.display()))?; + let cfg: FileConfig = toml::from_str(&raw) + .with_context(|| format!("failed to parse config TOML: {}", path.display()))?; + Ok(cfg) +} + +fn ensure_default_config(path: &Path) -> Result { + if path.exists() { + return Ok(false); + } + if let Some(parent) = path.parent() { + fs::create_dir_all(parent) + .with_context(|| format!("failed to create config dir: {}", parent.display()))?; + } + fs::write(path, default_config_template()) + .with_context(|| format!("failed to write default config: {}", path.display()))?; + eprintln!( + "Created default config at {}. You can edit it to set API keys and preferences.", + path.display() + ); + Ok(true) +} + +fn default_config_template() -> String { + [ + "# Mov Renamarr configuration (TOML)", + "# Edit this file to set API keys and defaults.", + "# Values here override built-in defaults and can be overridden by env/CLI.", + "", + "# Provider selection:", + "# - auto: pick based on available API keys (prefers TMDb if both set).", + "# - tmdb / omdb: force a single provider.", + "# - both: query both and choose best match.", + "provider = \"auto\"", + "", + "# API keys (set at least one).", + "# TMDb accepts either v3 API key or v4 Read Access Token (Bearer).", + "# api_key_tmdb = \"YOUR_TMDB_KEY_OR_READ_ACCESS_TOKEN\"", + "# api_key_omdb = \"YOUR_OMDB_KEY\"", + "", + "# Cache settings", + "# cache_path lets you override the default XDG cache location.", + "# cache_path = \"/home/user/.cache/mov-renamarr/cache.db\"", + "# cache_ttl_days controls how long cached API results are reused.", + "cache_ttl_days = 30", + "# refresh_cache forces new lookups on next run.", + "refresh_cache = false", + "", + "# Output and reporting", + "# report_format: text (default), json, or csv.", + "report_format = \"text\"", + "# sidecar_notes writes a per-file note when a file is skipped/failed.", + "sidecar_notes = false", + "# sidecars copies/moves subtitle/nfo/etc files with the movie file.", + "sidecars = false", + "# overwrite replaces existing files; suffix adds \" (1)\", \" (2)\", etc.", + "overwrite = false", + "suffix = false", + "# Disable external lookups (use filename/LLM only).", + "# When true, provider selection is ignored.", + "no_lookup = false", + "# min_score is 0-100 (match confidence threshold).", + "min_score = 80", + "# include_id adds tmdb-XXXX or imdb-ttXXXX in the filename.", + "include_id = false", + "", + "# Quality tags: list or comma-separated string.", + "# Supported tags: resolution, codec, source, all, none.", + "quality_tags = [\"resolution\"]", + "", + "# Console colors: auto, always, never", + "color = \"auto\"", + "", + "# Concurrency: auto or a number", + "# jobs controls file processing threads.", + "# net_jobs controls concurrent API calls.", + "jobs = \"auto\"", + "net_jobs = \"auto\"", + "", + "# Optional: override provider base URLs (useful for testing).", + "# tmdb_base_url = \"https://api.themoviedb.org/3\"", + "# omdb_base_url = \"https://www.omdbapi.com\"", + "", + "[llm]", + "# LLM usage:", + "# - off: no LLM usage", + "# - parse: LLM can replace filename parsing hints", + "# - assist: LLM adds alternate hints but still verifies via providers", + "# Ollama expected at endpoint.", + "mode = \"off\"", + "endpoint = \"http://localhost:11434\"", + "model = \"Qwen2.5:latest\"", + "# For higher accuracy (more RAM/VRAM): \"Qwen2.5:14b\"", + "# timeout_seconds limits LLM request time.", + "timeout_seconds = 30", + "# max_tokens caps response length.", + "# max_tokens = 256", + "", + ] + .join("\n") +} + +fn apply_file_config(settings: &mut Settings, file: &FileConfig) -> Result<()> { + if let Some(provider) = &file.provider { + settings.provider = provider.clone(); + } + if let Some(key) = &file.api_key_omdb { + settings.api_key_omdb = Some(key.clone()); + } + if let Some(key) = &file.api_key_tmdb { + settings.api_key_tmdb = Some(key.clone()); + } + if let Some(path) = &file.cache_path { + settings.cache_path = path.clone(); + } + if let Some(ttl) = file.cache_ttl_days { + settings.cache_ttl_days = ttl; + } + if let Some(refresh) = file.refresh_cache { + settings.refresh_cache = refresh; + } + if let Some(format) = &file.report_format { + settings.report_format = format.clone(); + } + if let Some(sidecar_notes) = file.sidecar_notes { + settings.sidecar_notes = sidecar_notes; + } + if let Some(sidecars) = file.sidecars { + settings.sidecars = sidecars; + } + if let Some(overwrite) = file.overwrite { + settings.overwrite = overwrite; + } + if let Some(suffix) = file.suffix { + settings.suffix = suffix; + } + if let Some(min_score) = file.min_score { + settings.min_score = min_score; + } + if let Some(include_id) = file.include_id { + settings.include_id = include_id; + } + if let Some(tags) = &file.quality_tags { + let values = match tags { + QualityTagsValue::List(list) => list.clone(), + QualityTagsValue::Single(value) => split_list(value), + }; + settings.quality_tags = parse_quality_tags(&values)?; + } + if let Some(color) = &file.color { + settings.color = color.clone(); + } + if let Some(raw) = &file.jobs { + settings.jobs = parse_jobs_setting_value(raw, default_jobs())?; + } + if let Some(raw) = &file.net_jobs { + settings.net_jobs = parse_jobs_setting_value(raw, default_net_jobs(settings.jobs))?; + } + if let Some(no_lookup) = file.no_lookup { + settings.no_lookup = no_lookup; + } + if let Some(llm) = &file.llm { + apply_file_llm(settings, llm); + } + if let Some(url) = &file.omdb_base_url { + settings.omdb_base_url = url.clone(); + } + if let Some(url) = &file.tmdb_base_url { + settings.tmdb_base_url = url.clone(); + } + Ok(()) +} + +fn apply_file_llm(settings: &mut Settings, llm: &FileLlmConfig) { + if let Some(mode) = &llm.mode { + settings.llm.mode = mode.clone(); + } + if let Some(endpoint) = &llm.endpoint { + settings.llm.endpoint = endpoint.clone(); + } + if let Some(model) = &llm.model { + settings.llm.model = Some(model.clone()); + } + if let Some(timeout) = llm.timeout_seconds { + settings.llm.timeout_seconds = timeout; + } + if let Some(max_tokens) = llm.max_tokens { + settings.llm.max_tokens = Some(max_tokens); + } +} + +fn apply_env_overrides(settings: &mut Settings) -> Result<()> { + apply_env_string("MOV_RENAMARR_PROVIDER", |value| { + if let Ok(provider) = ProviderChoice::from_str(&value.to_ascii_lowercase()) { + settings.provider = provider; + } + }); + + apply_env_string("MOV_RENAMARR_OMDB_API_KEY", |value| { + settings.api_key_omdb = Some(value); + }); + + apply_env_string("MOV_RENAMARR_TMDB_API_KEY", |value| { + settings.api_key_tmdb = Some(value); + }); + + apply_env_string("MOV_RENAMARR_CACHE", |value| { + settings.cache_path = PathBuf::from(value); + }); + + apply_env_string("MOV_RENAMARR_REPORT_FORMAT", |value| { + if let Ok(format) = ReportFormat::from_str(&value.to_ascii_lowercase()) { + settings.report_format = format; + } + }); + + apply_env_string("MOV_RENAMARR_JOBS", |value| { + if let Ok(jobs) = parse_jobs_setting(&value, default_jobs()) { + settings.jobs = jobs; + } + }); + + apply_env_string("MOV_RENAMARR_NET_JOBS", |value| { + if let Ok(jobs) = parse_jobs_setting(&value, default_net_jobs(settings.jobs)) { + settings.net_jobs = jobs; + } + }); + + apply_env_string("MOV_RENAMARR_MIN_SCORE", |value| { + if let Ok(min_score) = value.parse::() { + settings.min_score = min_score; + } + }); + + apply_env_bool("MOV_RENAMARR_INCLUDE_ID", |value| settings.include_id = value); + apply_env_bool("MOV_RENAMARR_SIDECARS", |value| settings.sidecars = value); + apply_env_bool("MOV_RENAMARR_SIDECAR_NOTES", |value| settings.sidecar_notes = value); + apply_env_bool("MOV_RENAMARR_OVERWRITE", |value| settings.overwrite = value); + apply_env_bool("MOV_RENAMARR_SUFFIX", |value| settings.suffix = value); + apply_env_bool("MOV_RENAMARR_NO_LOOKUP", |value| settings.no_lookup = value); + + apply_env_string("MOV_RENAMARR_QUALITY_TAGS", |value| { + if let Ok(tags) = parse_quality_tags(&split_list(&value)) { + settings.quality_tags = tags; + } + }); + + apply_env_string("MOV_RENAMARR_COLOR", |value| { + if let Ok(mode) = ColorMode::from_str(&value.to_ascii_lowercase()) { + settings.color = mode; + } + }); + + apply_env_string("MOV_RENAMARR_LLM_MODE", |value| { + if let Ok(mode) = LlmMode::from_str(&value.to_ascii_lowercase()) { + settings.llm.mode = mode; + } + }); + + apply_env_string("MOV_RENAMARR_LLM_ENDPOINT", |value| settings.llm.endpoint = value); + apply_env_string("MOV_RENAMARR_LLM_MODEL", |value| settings.llm.model = Some(value)); + + apply_env_string("MOV_RENAMARR_LLM_TIMEOUT", |value| { + if let Ok(timeout) = value.parse::() { + settings.llm.timeout_seconds = timeout; + } + }); + + apply_env_string("MOV_RENAMARR_LLM_MAX_TOKENS", |value| { + if let Ok(max_tokens) = value.parse::() { + settings.llm.max_tokens = Some(max_tokens); + } + }); + + apply_env_string("MOV_RENAMARR_OMDB_BASE_URL", |value| settings.omdb_base_url = value); + apply_env_string("MOV_RENAMARR_TMDB_BASE_URL", |value| settings.tmdb_base_url = value); + + Ok(()) +} + +fn apply_env_string(key: &str, mut setter: F) { + if let Ok(value) = env::var(key) { + if !value.trim().is_empty() { + setter(value); + } + } +} + +fn apply_env_bool(key: &str, mut setter: F) { + if let Ok(value) = env::var(key) { + if let Ok(parsed) = parse_bool(&value) { + setter(parsed); + } + } +} + +fn parse_bool(value: &str) -> Result { + match value.trim().to_ascii_lowercase().as_str() { + "1" | "true" | "yes" | "on" => Ok(true), + "0" | "false" | "no" | "off" => Ok(false), + _ => Err(anyhow!("invalid boolean value: {value}")), + } +} + +fn apply_cli_overrides(settings: &mut Settings, cli: &Cli) -> Result<()> { + if let Some(provider) = &cli.provider { + settings.provider = provider.clone(); + } + if let Some(key) = &cli.api_key_omdb { + settings.api_key_omdb = Some(key.clone()); + } + if let Some(key) = &cli.api_key_tmdb { + settings.api_key_tmdb = Some(key.clone()); + } + if let Some(path) = &cli.cache { + settings.cache_path = path.clone(); + } + if cli.refresh_cache { + settings.refresh_cache = true; + } + if let Some(format) = &cli.report_format { + settings.report_format = format.clone(); + } + if cli.sidecar_notes { + settings.sidecar_notes = true; + } + if cli.sidecars { + settings.sidecars = true; + } + if cli.overwrite { + settings.overwrite = true; + } + if cli.suffix { + settings.suffix = true; + } + if let Some(min_score) = cli.min_score { + settings.min_score = min_score; + } + if cli.include_id { + settings.include_id = true; + } + if let Some(tags) = &cli.quality_tags { + settings.quality_tags = parse_quality_tags(&split_list(tags))?; + } + if let Some(color) = &cli.color { + settings.color = color.clone(); + } + if let Some(jobs) = &cli.jobs { + settings.jobs = resolve_jobs_arg(jobs, default_jobs()); + } + if let Some(net_jobs) = &cli.net_jobs { + settings.net_jobs = resolve_jobs_arg(net_jobs, default_net_jobs(settings.jobs)); + } + if cli.no_lookup { + settings.no_lookup = true; + } + if let Some(mode) = &cli.llm_mode { + settings.llm.mode = mode.clone(); + } + if let Some(endpoint) = &cli.llm_endpoint { + settings.llm.endpoint = endpoint.clone(); + } + if let Some(model) = &cli.llm_model { + settings.llm.model = Some(model.clone()); + } + if let Some(timeout) = cli.llm_timeout { + settings.llm.timeout_seconds = timeout; + } + if let Some(max_tokens) = cli.llm_max_tokens { + settings.llm.max_tokens = Some(max_tokens); + } + if cli.verbose { + settings.verbose = true; + } + Ok(()) +} + +fn validate_settings(settings: &mut Settings) -> Result<()> { + if settings.overwrite && settings.suffix { + return Err(anyhow!("--overwrite and --suffix cannot both be set")); + } + if settings.min_score > 100 { + return Err(anyhow!("min-score must be between 0 and 100")); + } + if settings.net_jobs == 0 { + settings.net_jobs = 1; + } + if settings.net_jobs > settings.jobs { + settings.net_jobs = settings.jobs; + } + Ok(()) +} + +pub fn default_jobs() -> usize { + let cores = num_cpus::get(); + let half = std::cmp::max(1, cores / 2); + let limit = std::cmp::min(4, half); + if limit == 0 { 1 } else { limit } +} + +pub fn default_net_jobs(jobs: usize) -> usize { + std::cmp::max(1, std::cmp::min(2, jobs)) +} + +fn parse_jobs_setting(raw: &str, fallback: usize) -> Result { + if raw.eq_ignore_ascii_case("auto") { + return Ok(fallback); + } + let parsed: usize = raw.parse().context("invalid jobs value")?; + if parsed == 0 { + return Err(anyhow!("jobs must be >= 1")); + } + Ok(parsed) +} + +fn parse_jobs_setting_value(raw: &JobValue, fallback: usize) -> Result { + match raw { + JobValue::String(value) => parse_jobs_setting(value, fallback), + JobValue::Number(value) => { + if *value == 0 { + return Err(anyhow!("jobs must be >= 1")); + } + Ok(*value as usize) + } + } +} + +fn resolve_jobs_arg(arg: &JobsArg, fallback: usize) -> usize { + match arg { + JobsArg::Auto => fallback, + JobsArg::Fixed(value) => *value, + } +} + +fn parse_quality_tags(values: &[String]) -> Result { + let mut tags = QualityTags::default(); + tags.resolution = false; + for value in values { + let token = value.trim().to_ascii_lowercase(); + match token.as_str() { + "resolution" => tags.resolution = true, + "codec" => tags.codec = true, + "source" => tags.source = true, + "all" => { + tags.resolution = true; + tags.codec = true; + tags.source = true; + } + "none" => { + tags.resolution = false; + tags.codec = false; + tags.source = false; + } + _ if token.is_empty() => {} + _ => return Err(anyhow!("unknown quality tag: {token}")), + } + } + Ok(tags) +} + +fn split_list(raw: &str) -> Vec { + raw.split([',', ';', ' ']) + .filter(|token| !token.trim().is_empty()) + .map(|token| token.trim().to_string()) + .collect() +} + +fn resolve_report_path(cli: &Cli) -> Result> { + match &cli.report { + None => Ok(None), + Some(path) => { + if path.as_os_str() == "__DEFAULT__" { + let filename = default_report_filename(); + Ok(Some(PathBuf::from(filename))) + } else { + Ok(Some(path.clone())) + } + } + } +} + +fn default_report_filename() -> String { + let now = chrono::Local::now(); + let timestamp = now.format("%Y%m%d-%H%M%S").to_string(); + format!("mov-renamarr-report-{timestamp}.txt") +} + +// Needed for ValueEnum parsing from env string +impl FromStr for ProviderChoice { + type Err = anyhow::Error; + + fn from_str(s: &str) -> Result { + match s { + "auto" => Ok(ProviderChoice::Auto), + "omdb" => Ok(ProviderChoice::Omdb), + "tmdb" => Ok(ProviderChoice::Tmdb), + "both" => Ok(ProviderChoice::Both), + _ => Err(anyhow!("invalid provider choice")), + } + } +} + +impl FromStr for ReportFormat { + type Err = anyhow::Error; + + fn from_str(s: &str) -> Result { + match s { + "text" => Ok(ReportFormat::Text), + "json" => Ok(ReportFormat::Json), + "csv" => Ok(ReportFormat::Csv), + _ => Err(anyhow!("invalid report format")), + } + } +} + +impl FromStr for ColorMode { + type Err = anyhow::Error; + + fn from_str(s: &str) -> Result { + match s { + "auto" => Ok(ColorMode::Auto), + "always" => Ok(ColorMode::Always), + "never" => Ok(ColorMode::Never), + _ => Err(anyhow!("invalid color mode")), + } + } +} + +impl FromStr for LlmMode { + type Err = anyhow::Error; + + fn from_str(s: &str) -> Result { + match s { + "off" => Ok(LlmMode::Off), + "parse" => Ok(LlmMode::Parse), + "assist" => Ok(LlmMode::Assist), + _ => Err(anyhow!("invalid LLM mode")), + } + } +} diff --git a/src/fsops.rs b/src/fsops.rs new file mode 100644 index 0000000..09faec7 --- /dev/null +++ b/src/fsops.rs @@ -0,0 +1,161 @@ +use std::fs; +use std::path::{Path, PathBuf}; + +use anyhow::{anyhow, Context, Result}; + +#[derive(Clone, Copy, Debug)] +pub enum OpMode { + Copy, + Move, + RenameInPlace, +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum CollisionPolicy { + Skip, + Overwrite, + Suffix, +} + +#[derive(Debug)] +pub struct OperationOutcome { + pub final_path: Option, + pub skipped_reason: Option, +} + +pub fn execute( + src: &Path, + dest: &Path, + mode: OpMode, + policy: CollisionPolicy, + sidecars: bool, +) -> Result { + let dest = resolve_collision(dest, policy)?; + if dest.is_none() { + return Ok(OperationOutcome { + final_path: None, + skipped_reason: Some("destination exists".to_string()), + }); + } + let dest = dest.unwrap(); + + if let Some(parent) = dest.parent() { + fs::create_dir_all(parent) + .with_context(|| format!("failed to create output dir: {}", parent.display()))?; + } + + match mode { + OpMode::Copy => copy_file(src, &dest)?, + OpMode::Move | OpMode::RenameInPlace => move_file(src, &dest)?, + } + + if sidecars { + process_sidecars(src, &dest, mode, policy)?; + } + + Ok(OperationOutcome { + final_path: Some(dest), + skipped_reason: None, + }) +} + +fn resolve_collision(dest: &Path, policy: CollisionPolicy) -> Result> { + if !dest.exists() { + return Ok(Some(dest.to_path_buf())); + } + + match policy { + CollisionPolicy::Skip => Ok(None), + CollisionPolicy::Overwrite => Ok(Some(dest.to_path_buf())), + CollisionPolicy::Suffix => Ok(Some(append_suffix(dest)?)), + } +} + +fn append_suffix(dest: &Path) -> Result { + let parent = dest.parent().ok_or_else(|| anyhow!("invalid destination path"))?; + let stem = dest + .file_stem() + .ok_or_else(|| anyhow!("invalid destination filename"))? + .to_string_lossy(); + let ext = dest.extension().map(|e| e.to_string_lossy()); + + for idx in 1..=999 { + let candidate_name = if let Some(ext) = ext.as_ref() { + format!("{} ({}).{}", stem, idx, ext) + } else { + format!("{} ({})", stem, idx) + }; + let candidate = parent.join(candidate_name); + if !candidate.exists() { + return Ok(candidate); + } + } + Err(anyhow!("unable to find available suffix for {}", dest.display())) +} + +fn copy_file(src: &Path, dest: &Path) -> Result<()> { + fs::copy(src, dest) + .with_context(|| format!("failed to copy {} -> {}", src.display(), dest.display()))?; + Ok(()) +} + +fn move_file(src: &Path, dest: &Path) -> Result<()> { + match fs::rename(src, dest) { + Ok(()) => Ok(()), + Err(err) if err.raw_os_error() == Some(libc::EXDEV) => { + copy_file(src, dest)?; + fs::remove_file(src) + .with_context(|| format!("failed to remove source after copy: {}", src.display()))?; + Ok(()) + } + Err(err) => Err(anyhow!("failed to move {} -> {}: {}", src.display(), dest.display(), err)), + } +} + +fn process_sidecars(src: &Path, dest: &Path, mode: OpMode, policy: CollisionPolicy) -> Result { + let src_dir = src.parent().ok_or_else(|| anyhow!("source has no parent"))?; + let src_stem = src.file_stem().ok_or_else(|| anyhow!("source has no stem"))?; + let dest_dir = dest.parent().ok_or_else(|| anyhow!("destination has no parent"))?; + let dest_stem = dest.file_stem().ok_or_else(|| anyhow!("destination has no stem"))?; + + let mut processed = 0; + for entry in fs::read_dir(src_dir)? { + let entry = entry?; + let path = entry.path(); + if path == src { + continue; + } + if path.is_dir() { + continue; + } + let stem = match path.file_stem() { + Some(stem) => stem, + None => continue, + }; + if stem != src_stem { + continue; + } + let ext = path.extension().map(|e| e.to_string_lossy().to_string()); + let mut dest_name = dest_stem.to_string_lossy().to_string(); + if let Some(ext) = ext { + dest_name.push('.'); + dest_name.push_str(&ext); + } + let dest_path = dest_dir.join(dest_name); + let dest_path = resolve_collision(&dest_path, policy)?; + if let Some(dest_path) = dest_path { + if let Some(parent) = dest_path.parent() { + fs::create_dir_all(parent).with_context(|| { + format!("failed to create sidecar output dir: {}", parent.display()) + })?; + } + match mode { + OpMode::Copy => copy_file(&path, &dest_path)?, + OpMode::Move | OpMode::RenameInPlace => move_file(&path, &dest_path)?, + } + processed += 1; + } + } + + Ok(processed) +} diff --git a/src/llm.rs b/src/llm.rs new file mode 100644 index 0000000..b6d9e0a --- /dev/null +++ b/src/llm.rs @@ -0,0 +1,118 @@ +use anyhow::{Context, Result}; +use reqwest::blocking::Client; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Default)] +pub struct LlmHints { + pub title: Option, + pub year: Option, + pub alt_titles: Vec, +} + +#[derive(Clone)] +pub struct LlmClient { + endpoint: String, + model: String, + max_tokens: Option, + client: Client, +} + +impl LlmClient { + pub fn new(endpoint: String, model: String, timeout_seconds: u64, max_tokens: Option) -> Result { + let client = Client::builder() + .timeout(std::time::Duration::from_secs(timeout_seconds)) + .build() + .context("failed to build HTTP client for LLM")?; + Ok(Self { + endpoint, + model, + max_tokens, + client, + }) + } + + pub fn parse_filename(&self, raw: &str) -> Result { + let prompt = build_prompt(raw); + let request = OllamaRequest { + model: self.model.clone(), + prompt, + stream: false, + format: Some("json".to_string()), + options: Some(OllamaOptions { + num_predict: self.max_tokens, + temperature: 0.0, + }), + }; + + let url = format!("{}/api/generate", self.endpoint.trim_end_matches('/')); + let response = self + .client + .post(url) + .json(&request) + .send() + .context("LLM request failed")?; + + let status = response.status(); + if !status.is_success() { + return Err(anyhow::anyhow!("LLM returned HTTP {status}")); + } + + let body: OllamaResponse = response.json().context("failed to parse LLM response")?; + let hints = parse_hints(&body.response).unwrap_or_default(); + Ok(hints) + } +} + +fn build_prompt(raw: &str) -> String { + format!( + "You are a strict parser. Extract the full movie title and year from the filename below.\n\nRules:\n- Output JSON only.\n- Title must include all words of the movie name in order (no partial tokens).\n- Strip release metadata (resolution, codec, source, group tags).\n- Year must be a 4-digit number if present.\n- If unsure, use null for fields and empty array for alt_titles.\n- Do NOT invent data.\n\nReturn JSON with keys: title, year, alt_titles.\n\nFilename: {raw}\n" + ) +} + +#[derive(Serialize)] +struct OllamaRequest { + model: String, + prompt: String, + stream: bool, + format: Option, + options: Option, +} + +#[derive(Serialize)] +struct OllamaOptions { + #[serde(skip_serializing_if = "Option::is_none")] + num_predict: Option, + temperature: f32, +} + +#[derive(Deserialize)] +struct OllamaResponse { + response: String, +} + +#[derive(Deserialize, Default)] +struct LlmHintsRaw { + title: Option, + year: Option, + alt_titles: Option>, +} + +#[derive(Deserialize)] +#[serde(untagged)] +enum YearValue { + Number(i32), + String(String), +} + +fn parse_hints(raw: &str) -> Option { + let parsed: LlmHintsRaw = serde_json::from_str(raw).ok()?; + let year = parsed.year.and_then(|value| match value { + YearValue::Number(num) => Some(num), + YearValue::String(s) => s.chars().filter(|c| c.is_ascii_digit()).collect::().parse().ok(), + }); + Some(LlmHints { + title: parsed.title, + year, + alt_titles: parsed.alt_titles.unwrap_or_default(), + }) +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..a322d3d --- /dev/null +++ b/src/main.rs @@ -0,0 +1,34 @@ +mod cli; +mod config; +mod fsops; +mod llm; +mod media; +mod metadata; +mod output; +mod parse; +mod pipeline; +mod report; +mod utils; + +use anyhow::Result; +use clap::Parser; + +use crate::cli::Cli; + +fn main() -> Result<()> { + if std::env::args_os().len() == 1 { + let path = config::init_default_config()?; + eprintln!("Config file: {} (edit to set API keys and defaults)", path.display()); + return Ok(()); + } + + let cli = Cli::parse(); + let settings = config::build_settings(&cli)?; + + let report_format = settings.report_format.clone(); + let report_path = settings.report_path.clone(); + + let report = pipeline::run(settings)?; + report.write(&report_format, report_path.as_deref())?; + Ok(()) +} diff --git a/src/media.rs b/src/media.rs new file mode 100644 index 0000000..3abfe94 --- /dev/null +++ b/src/media.rs @@ -0,0 +1,154 @@ +use std::path::Path; +use std::process::Command; + +use anyhow::{anyhow, Context, Result}; +use serde::Deserialize; + +use crate::config::QualityTags; + +#[derive(Debug, Clone)] +pub struct MediaInfo { + pub duration_seconds: Option, + pub height: Option, + pub codec: Option, +} + +#[derive(Debug, Deserialize)] +struct FfprobeOutput { + format: Option, + streams: Option>, +} + +#[derive(Debug, Deserialize)] +struct FfprobeFormat { + duration: Option, +} + +#[derive(Debug, Deserialize)] +struct FfprobeStream { + codec_type: Option, + codec_name: Option, + height: Option, +} + +pub fn probe(path: &Path) -> Result { + let output = Command::new("ffprobe") + .arg("-v") + .arg("error") + .arg("-print_format") + .arg("json") + .arg("-show_format") + .arg("-show_streams") + .arg(path) + .output() + .with_context(|| format!("failed to run ffprobe on {}", path.display()))?; + + if !output.status.success() { + return Err(anyhow!( + "ffprobe failed for {}: {}", + path.display(), + String::from_utf8_lossy(&output.stderr) + )); + } + + let parsed: FfprobeOutput = serde_json::from_slice(&output.stdout) + .with_context(|| "failed to parse ffprobe JSON")?; + + let duration_seconds = parsed + .format + .and_then(|fmt| fmt.duration) + .and_then(|dur| dur.parse::().ok()); + + let video_stream = parsed + .streams + .unwrap_or_default() + .into_iter() + .find(|stream| stream.codec_type.as_deref() == Some("video")); + + let (height, codec) = if let Some(stream) = video_stream { + (stream.height, stream.codec_name) + } else { + (None, None) + }; + + Ok(MediaInfo { + duration_seconds, + height, + codec, + }) +} + +pub fn quality_tag(info: &MediaInfo, tags: &QualityTags) -> Option { + let mut parts: Vec = Vec::new(); + if tags.resolution { + if let Some(res) = resolution_tag(info.height) { + parts.push(res); + } + } + if tags.codec { + if let Some(codec) = codec_tag(info.codec.as_deref()) { + parts.push(codec); + } + } + if tags.source { + // Source tagging not implemented yet; placeholder for future expansion. + } + + if parts.is_empty() { + None + } else { + Some(parts.join(" ")) + } +} + +pub fn resolution_tag(height: Option) -> Option { + let height = height?; + let tag = if height >= 2160 { + "2160p" + } else if height >= 1080 { + "1080p" + } else if height >= 720 { + "720p" + } else if height >= 480 { + "480p" + } else { + "360p" + }; + Some(tag.to_string()) +} + +pub fn codec_tag(codec: Option<&str>) -> Option { + let codec = codec?.to_ascii_lowercase(); + let tag = if codec.contains("hevc") || codec.contains("h265") || codec.contains("x265") { + "x265" + } else if codec.contains("h264") || codec.contains("x264") { + "x264" + } else if codec.contains("av1") { + "av1" + } else { + return None; + }; + Some(tag.to_string()) +} + +#[cfg(test)] +mod tests { + use super::{codec_tag, resolution_tag}; + + #[test] + fn resolution_tags() { + assert_eq!(resolution_tag(Some(2160)).as_deref(), Some("2160p")); + assert_eq!(resolution_tag(Some(1080)).as_deref(), Some("1080p")); + assert_eq!(resolution_tag(Some(720)).as_deref(), Some("720p")); + assert_eq!(resolution_tag(Some(480)).as_deref(), Some("480p")); + assert_eq!(resolution_tag(Some(360)).as_deref(), Some("360p")); + } + + #[test] + fn codec_tags() { + assert_eq!(codec_tag(Some("h264")).as_deref(), Some("x264")); + assert_eq!(codec_tag(Some("hevc")).as_deref(), Some("x265")); + assert_eq!(codec_tag(Some("av1")).as_deref(), Some("av1")); + assert_eq!(codec_tag(Some("vp9")), None); + } +} diff --git a/src/metadata/cache.rs b/src/metadata/cache.rs new file mode 100644 index 0000000..9275dad --- /dev/null +++ b/src/metadata/cache.rs @@ -0,0 +1,80 @@ +use std::path::PathBuf; + +use anyhow::{Context, Result}; +use rusqlite::{params, Connection}; + +pub struct Cache { + path: PathBuf, + ttl_days: u32, + refresh: bool, +} + +impl Cache { + pub fn new(path: PathBuf, ttl_days: u32, refresh: bool) -> Self { + Self { + path, + ttl_days, + refresh, + } + } + + pub fn get(&self, namespace: &str, key: &str) -> Result> { + if self.refresh { + return Ok(None); + } + let conn = self.open()?; + let mut stmt = conn.prepare( + "SELECT value, fetched_at FROM cache WHERE namespace = ?1 AND key = ?2 LIMIT 1", + )?; + let row = stmt.query_row(params![namespace, key], |row| { + let value: String = row.get(0)?; + let fetched_at: i64 = row.get(1)?; + Ok((value, fetched_at)) + }); + let (value, fetched_at) = match row { + Ok(row) => row, + Err(rusqlite::Error::QueryReturnedNoRows) => return Ok(None), + Err(err) => return Err(err.into()), + }; + let now = current_timestamp(); + let age_days = (now - fetched_at) as f64 / 86_400.0; + if age_days > self.ttl_days as f64 { + return Ok(None); + } + Ok(Some(value)) + } + + pub fn set(&self, namespace: &str, key: &str, value: &str) -> Result<()> { + let conn = self.open()?; + conn.execute( + "INSERT INTO cache (namespace, key, value, fetched_at) VALUES (?1, ?2, ?3, ?4) + ON CONFLICT(namespace, key) DO UPDATE SET value = excluded.value, fetched_at = excluded.fetched_at", + params![namespace, key, value, current_timestamp()], + )?; + Ok(()) + } + + fn open(&self) -> Result { + if let Some(parent) = self.path.parent() { + std::fs::create_dir_all(parent) + .with_context(|| format!("failed to create cache dir: {}", parent.display()))?; + } + let conn = Connection::open(&self.path) + .with_context(|| format!("failed to open cache db: {}", self.path.display()))?; + conn.execute( + "CREATE TABLE IF NOT EXISTS cache ( + namespace TEXT NOT NULL, + key TEXT NOT NULL, + value TEXT NOT NULL, + fetched_at INTEGER NOT NULL, + PRIMARY KEY(namespace, key) + )", + [], + )?; + Ok(conn) + } +} + +fn current_timestamp() -> i64 { + chrono::Utc::now().timestamp() +} diff --git a/src/metadata/mod.rs b/src/metadata/mod.rs new file mode 100644 index 0000000..d6d2ec6 --- /dev/null +++ b/src/metadata/mod.rs @@ -0,0 +1,336 @@ +use std::collections::HashMap; +use std::sync::Arc; + +use anyhow::{anyhow, Result}; +use reqwest::blocking::Client; + +use crate::config::Settings; +use crate::metadata::cache::Cache; +use crate::parse::FileHints; +use crate::utils::{normalize_title, Semaphore}; + +mod cache; +mod omdb; +mod tmdb; + +#[derive(Clone, Debug, Eq, PartialEq, Hash)] +pub enum Provider { + Omdb, + Tmdb, + Parsed, + Manual, +} + +impl Provider { + pub fn as_str(&self) -> &'static str { + match self { + Provider::Omdb => "omdb", + Provider::Tmdb => "tmdb", + Provider::Parsed => "parsed", + Provider::Manual => "manual", + } + } +} + +#[derive(Clone, Debug)] +pub struct Candidate { + pub provider: Provider, + pub id: String, + pub title: String, + pub year: Option, + pub runtime_minutes: Option, +} + +#[derive(Clone, Debug)] +pub struct ScoredCandidate { + pub candidate: Candidate, + pub score: f64, +} + +#[derive(Clone, Debug)] +pub struct MovieMetadata { + pub title: String, + pub year: i32, + pub tmdb_id: Option, + pub imdb_id: Option, + pub provider: Provider, + pub runtime_minutes: Option, +} + +#[derive(Clone, Debug)] +pub struct MatchOutcome { + pub best: Option, + pub candidates: Vec, +} + +pub struct MetadataClient { + settings: Arc, + cache: Arc, + client: Client, + net_sem: Arc, +} + +impl MetadataClient { + pub fn new(settings: Arc, net_sem: Arc) -> Result { + let client = Client::builder().build()?; + let cache = Arc::new(Cache::new( + settings.cache_path.clone(), + settings.cache_ttl_days, + settings.refresh_cache, + )); + Ok(Self { + settings, + cache, + client, + net_sem, + }) + } + + pub fn validate(&self) -> Result<()> { + self.selected_providers().map(|_| ()) + } + + pub fn match_movie(&self, hints: &FileHints, runtime_minutes: Option) -> Result { + let providers = self.selected_providers()?; + let queries = build_queries(hints); + let mut candidates = Vec::new(); + + for provider in providers { + for query in &queries { + let mut results = match provider { + Provider::Omdb => omdb::search( + &self.client, + &self.settings.omdb_base_url, + self.settings.api_key_omdb.as_deref().ok_or_else(|| anyhow!("OMDb API key missing"))?, + query, + &self.cache, + &self.net_sem, + )?, + Provider::Tmdb => tmdb::search( + &self.client, + &self.settings.tmdb_base_url, + self.settings.api_key_tmdb.as_deref().ok_or_else(|| anyhow!("TMDb API key missing"))?, + query, + &self.cache, + &self.net_sem, + )?, + Provider::Parsed | Provider::Manual => Vec::new(), + }; + candidates.append(&mut results); + } + } + + let candidates = dedupe_candidates(candidates); + let mut scored = score_candidates(hints, runtime_minutes, candidates); + scored.sort_by(|a, b| b.score.partial_cmp(&a.score).unwrap_or(std::cmp::Ordering::Equal)); + + if runtime_minutes.is_some() && !scored.is_empty() { + self.enrich_runtime(&mut scored)?; + for entry in &mut scored { + entry.score = score_candidate(hints, runtime_minutes, &entry.candidate); + } + scored.sort_by(|a, b| b.score.partial_cmp(&a.score).unwrap_or(std::cmp::Ordering::Equal)); + } + + let best = if let Some(best) = scored.first() { + if best.score * 100.0 >= self.settings.min_score as f64 { + Some(self.fetch_details(&best.candidate)?) + } else { + None + } + } else { + None + }; + + Ok(MatchOutcome { best, candidates: scored }) + } + + pub fn resolve_candidate(&self, candidate: &Candidate) -> Result { + self.fetch_details(candidate) + } + + fn fetch_details(&self, candidate: &Candidate) -> Result { + match candidate.provider { + Provider::Omdb => { + let key = self.settings.api_key_omdb.as_deref().ok_or_else(|| anyhow!("OMDb API key missing"))?; + omdb::details( + &self.client, + &self.settings.omdb_base_url, + key, + &candidate.id, + &self.cache, + &self.net_sem, + ) + } + Provider::Tmdb => { + let key = self.settings.api_key_tmdb.as_deref().ok_or_else(|| anyhow!("TMDb API key missing"))?; + tmdb::details( + &self.client, + &self.settings.tmdb_base_url, + key, + &candidate.id, + &self.cache, + &self.net_sem, + ) + } + Provider::Parsed | Provider::Manual => { + Err(anyhow!("parsed/manual provider has no metadata lookup")) + } + } + } + + fn enrich_runtime(&self, candidates: &mut [ScoredCandidate]) -> Result<()> { + let top_n = 3.min(candidates.len()); + for entry in candidates.iter_mut().take(top_n) { + if entry.candidate.runtime_minutes.is_some() { + continue; + } + if let Ok(details) = self.fetch_details(&entry.candidate) { + entry.candidate.runtime_minutes = details.runtime_minutes; + entry.candidate.year = Some(details.year); + } + } + Ok(()) + } + + fn selected_providers(&self) -> Result> { + use crate::cli::ProviderChoice; + match self.settings.provider { + ProviderChoice::Auto => { + if self.settings.api_key_tmdb.is_some() { + Ok(vec![Provider::Tmdb]) + } else if self.settings.api_key_omdb.is_some() { + Ok(vec![Provider::Omdb]) + } else { + Err(anyhow!("no API keys available for provider selection")) + } + } + ProviderChoice::Omdb => { + if self.settings.api_key_omdb.is_none() { + Err(anyhow!("OMDb provider selected but API key missing")) + } else { + Ok(vec![Provider::Omdb]) + } + } + ProviderChoice::Tmdb => { + if self.settings.api_key_tmdb.is_none() { + Err(anyhow!("TMDb provider selected but API key missing")) + } else { + Ok(vec![Provider::Tmdb]) + } + } + ProviderChoice::Both => { + if self.settings.api_key_tmdb.is_none() || self.settings.api_key_omdb.is_none() { + Err(anyhow!("both providers requested but one or more API keys missing")) + } else { + Ok(vec![Provider::Tmdb, Provider::Omdb]) + } + } + } + } +} + +#[derive(Clone, Debug)] +pub(crate) struct SearchQuery { + title: String, + year: Option, +} + +fn build_queries(hints: &FileHints) -> Vec { + let mut queries = Vec::new(); + if let Some(title) = &hints.title { + queries.push(SearchQuery { + title: title.clone(), + year: hints.year, + }); + } + for alt in &hints.alt_titles { + queries.push(SearchQuery { + title: alt.clone(), + year: hints.year, + }); + } + dedupe_queries(queries) +} + +fn dedupe_queries(queries: Vec) -> Vec { + let mut seen = HashMap::new(); + let mut out = Vec::new(); + for query in queries { + let key = format!("{}:{}", normalize_title(&query.title), query.year.unwrap_or(0)); + if seen.insert(key, true).is_none() { + out.push(query); + } + } + out +} + +fn score_candidates( + hints: &FileHints, + runtime_minutes: Option, + candidates: Vec, +) -> Vec { + let mut scored = Vec::new(); + for candidate in candidates { + let score = score_candidate(hints, runtime_minutes, &candidate); + scored.push(ScoredCandidate { candidate, score }); + } + scored +} + +fn dedupe_candidates(candidates: Vec) -> Vec { + let mut seen = HashMap::new(); + let mut out = Vec::new(); + for candidate in candidates { + let key = format!("{}:{}", candidate.provider.as_str(), candidate.id); + if seen.insert(key, true).is_none() { + out.push(candidate); + } + } + out +} + +fn score_candidate(hints: &FileHints, runtime_minutes: Option, candidate: &Candidate) -> f64 { + let title_score = best_title_score(hints, &candidate.title); + let mut score = title_score; + + if let (Some(target_year), Some(candidate_year)) = (hints.year, candidate.year) { + let diff = (target_year - candidate_year).abs(); + if diff == 0 { + score += 0.10; + } else if diff == 1 { + score += 0.05; + } else { + score -= 0.05; + } + } + + if let (Some(target_runtime), Some(candidate_runtime)) = (runtime_minutes, candidate.runtime_minutes) { + let diff = target_runtime.abs_diff(candidate_runtime); + if diff <= 2 { + score += 0.05; + } else if diff <= 5 { + score += 0.02; + } + } + + score.clamp(0.0, 1.0) +} + +fn best_title_score(hints: &FileHints, candidate_title: &str) -> f64 { + let candidate_norm = normalize_title(candidate_title); + let mut best = 0.0; + if let Some(title) = &hints.title { + let score = strsim::jaro_winkler(&normalize_title(title), &candidate_norm); + if score > best { + best = score; + } + } + for alt in &hints.alt_titles { + let score = strsim::jaro_winkler(&normalize_title(alt), &candidate_norm); + if score > best { + best = score; + } + } + best +} diff --git a/src/metadata/omdb.rs b/src/metadata/omdb.rs new file mode 100644 index 0000000..51f1e0f --- /dev/null +++ b/src/metadata/omdb.rs @@ -0,0 +1,161 @@ +use anyhow::{anyhow, Context, Result}; +use reqwest::blocking::Client; +use serde::Deserialize; + +use crate::metadata::{Candidate, MovieMetadata, Provider}; +use crate::metadata::cache::Cache; +use crate::metadata::SearchQuery; +use crate::utils::{normalize_title, Semaphore}; + +#[derive(Debug, Deserialize)] +struct OmdbSearchResponse { + #[serde(rename = "Search")] + search: Option>, + #[serde(rename = "Response")] + response: Option, +} + +#[derive(Debug, Deserialize)] +struct OmdbSearchItem { + #[serde(rename = "Title")] + title: String, + #[serde(rename = "Year")] + year: String, + #[serde(rename = "imdbID")] + imdb_id: String, +} + +#[derive(Debug, Deserialize)] +struct OmdbDetailResponse { + #[serde(rename = "Title")] + title: Option, + #[serde(rename = "Year")] + year: Option, + #[serde(rename = "imdbID")] + imdb_id: Option, + #[serde(rename = "Runtime")] + runtime: Option, + #[serde(rename = "Response")] + response: Option, + #[serde(rename = "Error")] + error: Option, +} + +pub fn search( + client: &Client, + base_url: &str, + api_key: &str, + query: &SearchQuery, + cache: &Cache, + net_sem: &Semaphore, +) -> Result> { + let key = format!("{}:{}", normalize_title(&query.title), query.year.unwrap_or(0)); + if let Some(cached) = cache.get("omdb_search", &key)? { + return parse_search(&cached); + } + + let _permit = net_sem.acquire(); + let mut req = client + .get(base_url) + .query(&[("apikey", api_key), ("s", &query.title), ("type", "movie")]); + if let Some(year) = query.year { + req = req.query(&[("y", year.to_string())]); + } + + let resp = req.send().context("OMDb search request failed")?; + let status = resp.status(); + if !status.is_success() { + return Err(anyhow!("OMDb search failed with HTTP {status}")); + } + let text = resp.text().context("failed to read OMDb response")?; + cache.set("omdb_search", &key, &text)?; + parse_search(&text) +} + +fn parse_search(raw: &str) -> Result> { + let parsed: OmdbSearchResponse = serde_json::from_str(raw) + .with_context(|| "failed to parse OMDb search JSON")?; + if parsed.response.as_deref() == Some("False") { + return Ok(Vec::new()); + } + let mut candidates = Vec::new(); + if let Some(items) = parsed.search { + for item in items { + let year = parse_year(&item.year); + candidates.push(Candidate { + provider: Provider::Omdb, + id: item.imdb_id, + title: item.title, + year, + runtime_minutes: None, + }); + } + } + Ok(candidates) +} + +pub fn details( + client: &Client, + base_url: &str, + api_key: &str, + imdb_id: &str, + cache: &Cache, + net_sem: &Semaphore, +) -> Result { + if let Some(cached) = cache.get("omdb_details", imdb_id)? { + return parse_details(&cached); + } + + let _permit = net_sem.acquire(); + let resp = client + .get(base_url) + .query(&[("apikey", api_key), ("i", imdb_id), ("plot", "short")]) + .send() + .context("OMDb details request failed")?; + + let status = resp.status(); + if !status.is_success() { + return Err(anyhow!("OMDb details failed with HTTP {status}")); + } + let text = resp.text().context("failed to read OMDb details")?; + cache.set("omdb_details", imdb_id, &text)?; + parse_details(&text) +} + +fn parse_details(raw: &str) -> Result { + let parsed: OmdbDetailResponse = serde_json::from_str(raw) + .with_context(|| "failed to parse OMDb details JSON")?; + if parsed.response.as_deref() == Some("False") { + let msg = parsed.error.unwrap_or_else(|| "OMDb details not found".to_string()); + return Err(anyhow!(msg)); + } + let title = parsed.title.unwrap_or_else(|| "Unknown Title".to_string()); + let year = parsed + .year + .and_then(|y| parse_year(&y)) + .unwrap_or(0); + let imdb_id = parsed.imdb_id; + let runtime_minutes = parsed.runtime.as_deref().and_then(parse_runtime); + + Ok(MovieMetadata { + title, + year, + tmdb_id: None, + imdb_id, + provider: Provider::Omdb, + runtime_minutes, + }) +} + +fn parse_year(raw: &str) -> Option { + raw.chars() + .filter(|c| c.is_ascii_digit()) + .collect::() + .get(0..4) + .and_then(|s| s.parse::().ok()) +} + +fn parse_runtime(raw: &str) -> Option { + let digits: String = raw.chars().take_while(|c| c.is_ascii_digit()).collect(); + digits.parse().ok() +} diff --git a/src/metadata/tmdb.rs b/src/metadata/tmdb.rs new file mode 100644 index 0000000..a49c86e --- /dev/null +++ b/src/metadata/tmdb.rs @@ -0,0 +1,142 @@ +use anyhow::{anyhow, Context, Result}; +use reqwest::blocking::{Client, RequestBuilder}; +use serde::Deserialize; + +use crate::metadata::{Candidate, MovieMetadata, Provider}; +use crate::metadata::cache::Cache; +use crate::metadata::SearchQuery; +use crate::utils::{normalize_title, Semaphore}; + +#[derive(Debug, Deserialize)] +struct TmdbSearchResponse { + results: Option>, +} + +#[derive(Debug, Deserialize)] +struct TmdbSearchItem { + id: u32, + title: String, + release_date: Option, +} + +#[derive(Debug, Deserialize)] +struct TmdbDetailResponse { + id: u32, + title: Option, + release_date: Option, + runtime: Option, + imdb_id: Option, +} + +pub fn search( + client: &Client, + base_url: &str, + api_key: &str, + query: &SearchQuery, + cache: &Cache, + net_sem: &Semaphore, +) -> Result> { + let key = format!("{}:{}", normalize_title(&query.title), query.year.unwrap_or(0)); + if let Some(cached) = cache.get("tmdb_search", &key)? { + return parse_search(&cached); + } + + let _permit = net_sem.acquire(); + let url = format!("{}/search/movie", base_url.trim_end_matches('/')); + let mut req = apply_auth(client.get(url), api_key) + .query(&[("query", &query.title)]); + if let Some(year) = query.year { + req = req.query(&[("year", year.to_string())]); + } + let resp = req.send().context("TMDb search request failed")?; + let status = resp.status(); + if !status.is_success() { + return Err(anyhow!("TMDb search failed with HTTP {status}")); + } + let text = resp.text().context("failed to read TMDb response")?; + cache.set("tmdb_search", &key, &text)?; + parse_search(&text) +} + +fn parse_search(raw: &str) -> Result> { + let parsed: TmdbSearchResponse = serde_json::from_str(raw) + .with_context(|| "failed to parse TMDb search JSON")?; + let mut candidates = Vec::new(); + if let Some(items) = parsed.results { + for item in items { + let year = item.release_date.as_deref().and_then(parse_year); + candidates.push(Candidate { + provider: Provider::Tmdb, + id: item.id.to_string(), + title: item.title, + year, + runtime_minutes: None, + }); + } + } + Ok(candidates) +} + +pub fn details( + client: &Client, + base_url: &str, + api_key: &str, + id: &str, + cache: &Cache, + net_sem: &Semaphore, +) -> Result { + if let Some(cached) = cache.get("tmdb_details", id)? { + return parse_details(&cached); + } + + let _permit = net_sem.acquire(); + let url = format!("{}/movie/{}", base_url.trim_end_matches('/'), id); + let resp = apply_auth(client.get(url), api_key).send() + .context("TMDb details request failed")?; + + let status = resp.status(); + if !status.is_success() { + return Err(anyhow!("TMDb details failed with HTTP {status}")); + } + let text = resp.text().context("failed to read TMDb details")?; + cache.set("tmdb_details", id, &text)?; + parse_details(&text) +} + +fn parse_details(raw: &str) -> Result { + let parsed: TmdbDetailResponse = serde_json::from_str(raw) + .with_context(|| "failed to parse TMDb details JSON")?; + let title = parsed.title.unwrap_or_else(|| "Unknown Title".to_string()); + let year = parsed + .release_date + .as_deref() + .and_then(parse_year) + .unwrap_or(0); + + let tmdb_id = Some(parsed.id); + + Ok(MovieMetadata { + title, + year, + tmdb_id, + imdb_id: parsed.imdb_id, + provider: Provider::Tmdb, + runtime_minutes: parsed.runtime, + }) +} + +fn apply_auth(req: RequestBuilder, api_key: &str) -> RequestBuilder { + if looks_like_bearer(api_key) { + req.bearer_auth(api_key) + } else { + req.query(&[("api_key", api_key)]) + } +} + +fn looks_like_bearer(value: &str) -> bool { + value.contains('.') && value.len() > 30 +} + +fn parse_year(raw: &str) -> Option { + raw.get(0..4).and_then(|s| s.parse::().ok()) +} diff --git a/src/output.rs b/src/output.rs new file mode 100644 index 0000000..23c8bdf --- /dev/null +++ b/src/output.rs @@ -0,0 +1,95 @@ +use std::io; +use std::sync::Mutex; + +use is_terminal::IsTerminal; +use owo_colors::OwoColorize; + +use crate::cli::ColorMode; + +#[derive(Clone, Copy, Debug)] +pub enum StatusKind { + Renamed, + Skipped, + Failed, +} + +pub struct Output { + use_color: bool, + verbose: bool, + lock: Mutex<()>, +} + +impl Output { + pub fn new(color_mode: &ColorMode, verbose: bool) -> Self { + let use_color = match color_mode { + ColorMode::Always => true, + ColorMode::Never => false, + ColorMode::Auto => io::stdout().is_terminal(), + }; + Self { + use_color, + verbose, + lock: Mutex::new(()), + } + } + + pub fn status_line( + &self, + index: usize, + total: usize, + status: StatusKind, + filename: &str, + provider: Option<&str>, + result: &str, + output_name: Option<&str>, + ) { + let _guard = self.lock.lock().unwrap(); + let prefix = format!("[{}/{}]", index, total); + let status_label = match status { + StatusKind::Renamed => "renamed", + StatusKind::Skipped => "skipped", + StatusKind::Failed => "failed", + }; + let status_label = self.colorize_status(status_label, status); + let provider_label = provider.map(|p| format!("{p}")); + + let mut line = format!("{prefix} {status_label} {filename}"); + if let Some(provider) = provider_label { + line.push_str(&format!(" | {provider}")); + } + line.push_str(&format!(" | {result}")); + if let Some(output_name) = output_name { + line.push_str(&format!(" -> {output_name}")); + } + println!("{line}"); + } + + pub fn warn(&self, message: &str) { + let _guard = self.lock.lock().unwrap(); + let msg = if self.use_color { + message.yellow().to_string() + } else { + message.to_string() + }; + eprintln!("{msg}"); + } + + + pub fn info(&self, message: &str) { + if self.verbose { + let _guard = self.lock.lock().unwrap(); + println!("{message}"); + } + } + + fn colorize_status(&self, text: &str, status: StatusKind) -> String { + if !self.use_color { + return text.to_string(); + } + match status { + StatusKind::Renamed => text.green().to_string(), + StatusKind::Skipped => text.yellow().to_string(), + StatusKind::Failed => text.red().to_string(), + } + } +} diff --git a/src/parse.rs b/src/parse.rs new file mode 100644 index 0000000..2b9ea1a --- /dev/null +++ b/src/parse.rs @@ -0,0 +1,150 @@ +use std::path::Path; + +use regex::Regex; + +use crate::utils::{collapse_whitespace, normalize_title}; + +#[derive(Debug, Clone)] +pub struct FileHints { + pub title: Option, + pub normalized_title: Option, + pub year: Option, + pub alt_titles: Vec, +} + +pub fn parse_filename(path: &Path) -> FileHints { + let stem = path + .file_stem() + .map(|s| s.to_string_lossy().to_string()) + .unwrap_or_default(); + + let year = extract_year(&stem); + let cleaned = strip_bracketed(&stem); + let alt_titles = extract_alt_titles(&cleaned, year); + let tokens = tokenize(&cleaned, year); + + let title = if tokens.is_empty() { + let mut fallback = cleaned.clone(); + if let Some(year) = year { + fallback = fallback.replace(&year.to_string(), ""); + } + let fallback = collapse_whitespace(&fallback); + if fallback.is_empty() { None } else { Some(fallback) } + } else { + Some(collapse_whitespace(&tokens.join(" "))) + }; + let normalized_title = title.as_deref().map(normalize_title); + + FileHints { + title, + normalized_title, + year, + alt_titles, + } +} + +fn extract_year(raw: &str) -> Option { + let re = Regex::new(r"(19|20)\d{2}").ok()?; + let mut year: Option = None; + for mat in re.find_iter(raw) { + if let Ok(parsed) = mat.as_str().parse::() { + year = Some(parsed); + } + } + year +} + +fn strip_bracketed(raw: &str) -> String { + let re_square = Regex::new(r"\[[^\]]*\]").unwrap(); + let re_round = Regex::new(r"\([^\)]*\)").unwrap(); + let without_square = re_square.replace_all(raw, " "); + let without_round = re_round.replace_all(&without_square, " "); + without_round.to_string() +} + +fn extract_alt_titles(raw: &str, year: Option) -> Vec { + let mut alt_titles = Vec::new(); + if let Some((left, right)) = raw.split_once(" - ") { + let left = clean_title_fragment(left, year); + let right = collapse_whitespace(right); + if !left.is_empty() && !right.is_empty() { + alt_titles.push(left); + } + } + alt_titles +} + +fn clean_title_fragment(fragment: &str, year: Option) -> String { + let mut cleaned = fragment.to_string(); + if let Some(year) = year { + cleaned = cleaned.replace(&year.to_string(), " "); + } + collapse_whitespace(&cleaned) +} + +fn tokenize(raw: &str, year: Option) -> Vec { + let stopwords = stopwords(); + let mut tokens = Vec::new(); + for token in raw.split(|c: char| !c.is_alphanumeric()) { + if token.is_empty() { + continue; + } + let lower = token.to_ascii_lowercase(); + if let Some(year) = year { + if lower == year.to_string() { + continue; + } + } + if stopwords.contains(lower.as_str()) { + continue; + } + if token.chars().all(|c| c.is_ascii_uppercase()) && token.len() <= 8 { + continue; + } + tokens.push(token.to_string()); + } + tokens +} + +fn stopwords() -> std::collections::HashSet<&'static str> { + [ + "1080p", "720p", "2160p", "480p", "360p", "4k", "uhd", "hdr", "dvdrip", + "bdrip", "brrip", "bluray", "blu", "webdl", "web-dl", "webrip", "hdrip", + "remux", "x264", "x265", "h264", "h265", "hevc", "aac", "dts", "ac3", + "proper", "repack", "limited", "extended", "uncut", "remastered", "subbed", + "subs", "multi", "dubbed", "dub", "yts", "yify", "rarbg", "web", "hd", + "hq", "cam", "ts", "dvdscr", "r5", "r6", + ] + .into_iter() + .collect() +} + +#[cfg(test)] +mod tests { + use super::parse_filename; + use std::path::Path; + + #[test] + fn parses_basic_title_and_year() { + let path = Path::new("Some.Movie.2020.1080p.BluRay.x264-GROUP.mkv"); + let hints = parse_filename(path); + assert_eq!(hints.title.as_deref(), Some("Some Movie")); + assert_eq!(hints.year, Some(2020)); + } + + #[test] + fn handles_brackets_and_stopwords() { + let path = Path::new("[YTS] The.Matrix.(1999).1080p.BluRay.mkv"); + let hints = parse_filename(path); + assert_eq!(hints.title.as_deref(), Some("The Matrix")); + assert_eq!(hints.year, Some(1999)); + } + + #[test] + fn adds_alt_title_for_dash_suffix() { + let path = Path::new("Zootopia - Vlix.mp4"); + let hints = parse_filename(path); + assert_eq!(hints.title.as_deref(), Some("Zootopia Vlix")); + assert!(hints.alt_titles.iter().any(|t| t == "Zootopia")); + } +} diff --git a/src/pipeline.rs b/src/pipeline.rs new file mode 100644 index 0000000..deb689f --- /dev/null +++ b/src/pipeline.rs @@ -0,0 +1,563 @@ +use std::path::{Path, PathBuf}; +use std::sync::Arc; +use std::io; + +use anyhow::{anyhow, Context, Result}; +use rayon::prelude::*; +use walkdir::WalkDir; + +use crate::config::Settings; +use crate::fsops::{self, CollisionPolicy, OpMode}; +use crate::llm::{LlmClient, LlmHints}; +use crate::media; +use crate::metadata::{MatchOutcome, MetadataClient, MovieMetadata, Provider, ScoredCandidate}; +use crate::output::{Output, StatusKind}; +use crate::parse::{parse_filename, FileHints}; +use crate::report::{summarize_candidates, Report, ReportEntry}; +use crate::utils::{sanitize_filename, Semaphore}; + +pub fn run(mut settings: Settings) -> Result { + ensure_ffprobe()?; + + let output = Arc::new(Output::new(&settings.color, settings.verbose)); + if settings.no_lookup { + output.warn("No-lookup mode enabled: using filename/LLM only (no external providers)."); + } + if settings.verbose { + output.info(&format!( + "jobs: {} | net-jobs: {} | report format: {:?}", + settings.jobs, settings.net_jobs, settings.report_format + )); + } + + if settings.interactive { + settings.jobs = 1; + settings.net_jobs = settings.net_jobs.max(1); + } + + let files = discover_files(&settings.input, &settings.output)?; + let total = files.len(); + if total == 0 { + output.warn("no video files found"); + return Ok(Report::default()); + } + + let settings = Arc::new(settings); + let net_sem = Arc::new(Semaphore::new(settings.net_jobs)); + let metadata = if settings.no_lookup { + None + } else { + let client = Arc::new(MetadataClient::new(settings.clone(), net_sem)?); + client.validate()?; + Some(client) + }; + + let llm = build_llm_client(&settings, &output)?; + + let pool = rayon::ThreadPoolBuilder::new() + .num_threads(settings.jobs) + .build() + .context("failed to build thread pool")?; + + let results: Vec = pool.install(|| { + files + .par_iter() + .enumerate() + .map(|(idx, path)| { + process_file( + idx + 1, + total, + path, + settings.clone(), + metadata.clone(), + llm.clone(), + output.clone(), + ) + .unwrap_or_else(|err| ReportEntry { + input: path.display().to_string(), + status: "failed".to_string(), + provider: None, + result: None, + output: None, + reason: Some(err.to_string()), + candidates: Vec::new(), + }) + }) + .collect() + }); + + let mut report = Report::default(); + for entry in results { + report.record(entry); + } + + Ok(report) +} + +fn ensure_ffprobe() -> Result<()> { + let output = std::process::Command::new("ffprobe") + .arg("-version") + .output(); + match output { + Ok(output) if output.status.success() => Ok(()), + _ => Err(anyhow!( + "ffprobe not found. Please install ffmpeg/ffprobe and ensure it is in PATH." + )), + } +} + +fn discover_files(input: &Path, output: &Path) -> Result> { + let mut files = Vec::new(); + for entry in WalkDir::new(input).follow_links(true) { + let entry = entry?; + if !entry.file_type().is_file() { + continue; + } + let path = entry.path(); + if output != input && path.starts_with(output) { + continue; + } + if is_video_file(path) { + files.push(path.to_path_buf()); + } + } + Ok(files) +} + +fn is_video_file(path: &Path) -> bool { + let ext = match path.extension().and_then(|e| e.to_str()) { + Some(ext) => ext.to_ascii_lowercase(), + None => return false, + }; + matches!( + ext.as_str(), + "mkv" | "mp4" | "avi" | "mov" | "m4v" | "mpg" | "mpeg" | "wmv" | "webm" | "ts" | "m2ts" + ) +} + +fn process_file( + index: usize, + total: usize, + path: &Path, + settings: Arc, + metadata: Option>, + llm: Option>, + output: Arc, +) -> Result { + let filename = path.file_name().unwrap_or_default().to_string_lossy().to_string(); + let mut hints = parse_filename(path); + + if let Some(llm) = &llm { + if settings.llm.mode != crate::cli::LlmMode::Off { + if let Ok(llm_hints) = llm.parse_filename(&filename) { + merge_llm_hints(&mut hints, llm_hints, settings.llm.mode.clone()); + } else { + output.warn(&format!("LLM parse failed for {filename}, using heuristic parse")); + } + } + } + + let media = match media::probe(path) { + Ok(info) => info, + Err(err) => { + output.status_line( + index, + total, + StatusKind::Failed, + &filename, + None, + "ffprobe failed", + None, + ); + return Ok(ReportEntry { + input: path.display().to_string(), + status: "failed".to_string(), + provider: None, + result: None, + output: None, + reason: Some(err.to_string()), + candidates: Vec::new(), + }); + } + }; + + let runtime_minutes = media + .duration_seconds + .map(|seconds| (seconds / 60.0).round() as u32); + + let outcome = if settings.no_lookup { + MatchOutcome { + best: match_offline(&hints, settings.interactive)?, + candidates: Vec::new(), + } + } else { + match metadata + .as_ref() + .ok_or_else(|| anyhow!("metadata client unavailable"))? + .match_movie(&hints, runtime_minutes) + { + Ok(outcome) => outcome, + Err(err) => { + output.status_line( + index, + total, + StatusKind::Failed, + &filename, + None, + "metadata lookup failed", + None, + ); + return Ok(ReportEntry { + input: path.display().to_string(), + status: "failed".to_string(), + provider: None, + result: None, + output: None, + reason: Some(err.to_string()), + candidates: Vec::new(), + }); + } + } + }; + + let mut chosen = outcome.best.clone(); + if settings.interactive && !settings.no_lookup { + let client = metadata.as_ref().ok_or_else(|| anyhow!("metadata client unavailable"))?; + chosen = interactive_choice(&outcome, path, client)?; + } + + if chosen.is_none() { + let reason = if settings.no_lookup { + if hints.title.is_none() || hints.year.is_none() { + "no-lookup missing title/year".to_string() + } else { + "no-lookup skipped".to_string() + } + } else { + "no match above threshold".to_string() + }; + output.status_line( + index, + total, + StatusKind::Skipped, + &filename, + None, + "no match", + None, + ); + let entry = ReportEntry { + input: path.display().to_string(), + status: "skipped".to_string(), + provider: None, + result: None, + output: None, + reason: Some(reason), + candidates: summarize_candidates(&outcome.candidates, 3), + }; + if settings.sidecar_notes { + write_sidecar_note(path, &entry)?; + } + return Ok(entry); + } + + let metadata = chosen.unwrap(); + let quality = media::quality_tag(&media, &settings.quality_tags); + let output_path = build_output_path(&metadata, &settings, path, quality.as_deref()); + + if settings.dry_run { + output.status_line( + index, + total, + StatusKind::Renamed, + &filename, + Some(metadata.provider.as_str()), + "dry-run", + Some(&output_path.display().to_string()), + ); + return Ok(ReportEntry { + input: path.display().to_string(), + status: "renamed".to_string(), + provider: Some(metadata.provider.as_str().to_string()), + result: Some(format!("{} ({})", metadata.title, metadata.year)), + output: Some(output_path.display().to_string()), + reason: Some("dry-run".to_string()), + candidates: Vec::new(), + }); + } + + let op_mode = if settings.move_files { + OpMode::Move + } else if settings.rename_in_place { + OpMode::RenameInPlace + } else { + OpMode::Copy + }; + let policy = if settings.overwrite { + CollisionPolicy::Overwrite + } else if settings.suffix { + CollisionPolicy::Suffix + } else { + CollisionPolicy::Skip + }; + + let outcome = fsops::execute(path, &output_path, op_mode, policy, settings.sidecars)?; + if outcome.final_path.is_none() { + output.status_line( + index, + total, + StatusKind::Skipped, + &filename, + Some(metadata.provider.as_str()), + "destination exists", + None, + ); + let entry = ReportEntry { + input: path.display().to_string(), + status: "skipped".to_string(), + provider: Some(metadata.provider.as_str().to_string()), + result: Some(format!("{} ({})", metadata.title, metadata.year)), + output: None, + reason: outcome.skipped_reason, + candidates: Vec::new(), + }; + if settings.sidecar_notes { + write_sidecar_note(path, &entry)?; + } + return Ok(entry); + } + + let final_path = outcome.final_path.unwrap(); + output.status_line( + index, + total, + StatusKind::Renamed, + &filename, + Some(metadata.provider.as_str()), + "renamed", + Some(&final_path.display().to_string()), + ); + + Ok(ReportEntry { + input: path.display().to_string(), + status: "renamed".to_string(), + provider: Some(metadata.provider.as_str().to_string()), + result: Some(format!("{} ({})", metadata.title, metadata.year)), + output: Some(final_path.display().to_string()), + reason: None, + candidates: Vec::new(), + }) +} + +fn merge_llm_hints(hints: &mut FileHints, llm_hints: LlmHints, mode: crate::cli::LlmMode) { + if let Some(title) = llm_hints.title { + if hints.title.is_none() || mode == crate::cli::LlmMode::Parse { + hints.title = Some(title.clone()); + hints.normalized_title = Some(crate::utils::normalize_title(&title)); + } else if hints.title.as_deref() != Some(title.as_str()) { + hints.alt_titles.push(title); + } + } + if let Some(year) = llm_hints.year { + if hints.year.is_none() || mode == crate::cli::LlmMode::Parse { + hints.year = Some(year); + } + } + if !llm_hints.alt_titles.is_empty() { + hints.alt_titles.extend(llm_hints.alt_titles); + } +} + +fn match_offline(hints: &FileHints, interactive: bool) -> Result> { + if let (Some(title), Some(year)) = (&hints.title, hints.year) { + return Ok(Some(MovieMetadata { + title: title.clone(), + year, + tmdb_id: None, + imdb_id: None, + provider: Provider::Parsed, + runtime_minutes: None, + })); + } + + if interactive { + let title = prompt("Title")?; + let year = prompt("Year")?; + if let Ok(year) = year.parse::() { + return Ok(Some(MovieMetadata { + title, + year, + tmdb_id: None, + imdb_id: None, + provider: Provider::Manual, + runtime_minutes: None, + })); + } + } + Ok(None) +} + +fn build_output_path( + metadata: &MovieMetadata, + settings: &Settings, + source: &Path, + quality: Option<&str>, +) -> PathBuf { + let mut folder = format!("{} ({})", metadata.title, metadata.year); + folder = sanitize_filename(&folder); + + let mut filename = folder.clone(); + if let Some(quality) = quality { + filename.push_str(&format!(" [{}]", quality)); + } + if settings.include_id { + if let Some(id) = id_tag(metadata) { + filename.push_str(&format!(" [{}]", id)); + } + } + + let ext = source.extension().and_then(|e| e.to_str()).unwrap_or(""); + if !ext.is_empty() { + filename.push('.'); + filename.push_str(ext); + } + + settings.output.join(folder).join(filename) +} + +fn id_tag(metadata: &MovieMetadata) -> Option { + match metadata.provider { + Provider::Tmdb => metadata.tmdb_id.map(|id| format!("tmdb-{id}")), + Provider::Omdb => metadata.imdb_id.as_ref().map(|id| format!("imdb-{id}")), + Provider::Parsed | Provider::Manual => None, + } +} + +fn interactive_choice( + outcome: &MatchOutcome, + path: &Path, + metadata: &MetadataClient, +) -> Result> { + if outcome.candidates.is_empty() { + return Ok(outcome.best.clone()); + } + + let ambiguous = is_ambiguous(&outcome.candidates); + if !ambiguous && outcome.best.is_some() { + return Ok(outcome.best.clone()); + } + + let filename = path.file_name().unwrap_or_default().to_string_lossy(); + println!("Ambiguous match for {filename}"); + for (idx, candidate) in outcome.candidates.iter().take(3).enumerate() { + let label = format!( + " {}) {} ({}) [{}] score {:.1}", + idx + 1, + candidate.candidate.title, + candidate.candidate.year.unwrap_or(0), + candidate.candidate.provider.as_str(), + candidate.score * 100.0 + ); + println!("{label}"); + } + println!(" s) skip"); + println!(" m) manual title/year"); + print!("Choose: "); + io::Write::flush(&mut std::io::stdout())?; + + let mut choice = String::new(); + std::io::stdin().read_line(&mut choice)?; + let choice = choice.trim(); + if choice.eq_ignore_ascii_case("s") { + return Ok(None); + } + if choice.eq_ignore_ascii_case("m") { + let title = prompt("Title")?; + let year = prompt("Year")?; + if let Ok(year) = year.parse::() { + return Ok(Some(MovieMetadata { + title, + year, + tmdb_id: None, + imdb_id: None, + provider: Provider::Manual, + runtime_minutes: None, + })); + } + return Ok(None); + } + if let Ok(index) = choice.parse::() { + if let Some(candidate) = outcome.candidates.get(index - 1) { + if let Ok(details) = metadata.resolve_candidate(&candidate.candidate) { + return Ok(Some(details)); + } + return Ok(Some(MovieMetadata { + title: candidate.candidate.title.clone(), + year: candidate.candidate.year.unwrap_or(0), + tmdb_id: None, + imdb_id: None, + provider: candidate.candidate.provider.clone(), + runtime_minutes: None, + })); + } + } + Ok(outcome.best.clone()) +} + +fn is_ambiguous(candidates: &[ScoredCandidate]) -> bool { + if candidates.len() < 2 { + return false; + } + (candidates[0].score - candidates[1].score).abs() < 0.02 +} + +fn prompt(label: &str) -> Result { + print!("{label}: "); + io::Write::flush(&mut std::io::stdout())?; + let mut input = String::new(); + std::io::stdin().read_line(&mut input)?; + Ok(input.trim().to_string()) +} + +fn build_llm_client(settings: &Settings, output: &Output) -> Result>> { + if settings.llm.mode == crate::cli::LlmMode::Off { + return Ok(None); + } + let model = match &settings.llm.model { + Some(model) => model.clone(), + None => { + output.warn("LLM mode enabled but no model provided; disabling LLM"); + return Ok(None); + } + }; + let client = LlmClient::new( + settings.llm.endpoint.clone(), + model, + settings.llm.timeout_seconds, + settings.llm.max_tokens, + )?; + Ok(Some(Arc::new(client))) +} + +fn write_sidecar_note(path: &Path, entry: &ReportEntry) -> Result<()> { + let note_path = path.with_extension("mov-renamarr.txt"); + let mut note = String::new(); + note.push_str(&format!("Status: {}\n", entry.status)); + if let Some(reason) = &entry.reason { + note.push_str(&format!("Reason: {}\n", reason)); + } + if !entry.candidates.is_empty() { + note.push_str("Candidates:\n"); + for candidate in &entry.candidates { + note.push_str(&format!( + " - {} ({}) [{}] {:.1}\n", + candidate.title, + candidate.year.unwrap_or(0), + candidate.provider, + candidate.score * 100.0 + )); + } + } + std::fs::write(¬e_path, note) + .with_context(|| format!("failed to write sidecar note: {}", note_path.display()))?; + Ok(()) +} diff --git a/src/report.rs b/src/report.rs new file mode 100644 index 0000000..646c6a3 --- /dev/null +++ b/src/report.rs @@ -0,0 +1,165 @@ +use std::fs::File; +use std::io::{self, Write}; +use std::path::Path; + +use anyhow::{Context, Result}; +use serde::Serialize; + +use crate::cli::ReportFormat; +use crate::metadata::ScoredCandidate; + +#[derive(Debug, Default, Serialize)] +pub struct Report { + pub processed: usize, + pub renamed: usize, + pub skipped: usize, + pub failed: usize, + pub entries: Vec, +} + +#[derive(Debug, Serialize)] +pub struct ReportEntry { + pub input: String, + pub status: String, + pub provider: Option, + pub result: Option, + pub output: Option, + pub reason: Option, + pub candidates: Vec, +} + +#[derive(Debug, Serialize)] +pub struct CandidateSummary { + pub title: String, + pub year: Option, + pub provider: String, + pub score: f64, +} + +impl Report { + pub fn record(&mut self, entry: ReportEntry) { + self.processed += 1; + match entry.status.as_str() { + "renamed" => self.renamed += 1, + "skipped" => self.skipped += 1, + "failed" => self.failed += 1, + _ => {} + } + self.entries.push(entry); + } + + pub fn write(&self, format: &ReportFormat, path: Option<&Path>) -> Result<()> { + match format { + ReportFormat::Text => self.write_text(path), + ReportFormat::Json => self.write_json(path), + ReportFormat::Csv => self.write_csv(path), + } + } + + fn write_text(&self, path: Option<&Path>) -> Result<()> { + let mut writer = open_writer(path)?; + writeln!( + writer, + "Processed: {} | Renamed: {} | Skipped: {} | Failed: {}", + self.processed, self.renamed, self.skipped, self.failed + )?; + + for entry in &self.entries { + writeln!(writer, "\n[{}] {}", entry.status, entry.input)?; + if let Some(provider) = &entry.provider { + writeln!(writer, " Provider: {}", provider)?; + } + if let Some(result) = &entry.result { + writeln!(writer, " Result: {}", result)?; + } + if let Some(output) = &entry.output { + writeln!(writer, " Output: {}", output)?; + } + if let Some(reason) = &entry.reason { + writeln!(writer, " Reason: {}", reason)?; + } + if !entry.candidates.is_empty() { + writeln!(writer, " Candidates:")?; + for candidate in &entry.candidates { + writeln!( + writer, + " - {} ({}) [{}] score {:.1}", + candidate.title, + candidate.year.map(|y| y.to_string()).unwrap_or_else(|| "?".into()), + candidate.provider, + candidate.score * 100.0 + )?; + } + } + } + Ok(()) + } + + fn write_json(&self, path: Option<&Path>) -> Result<()> { + let writer = open_writer(path)?; + serde_json::to_writer_pretty(writer, self).context("failed to write JSON report")?; + Ok(()) + } + + fn write_csv(&self, path: Option<&Path>) -> Result<()> { + let mut writer = csv::Writer::from_writer(open_writer(path)?); + writer.write_record([ + "input", + "status", + "provider", + "result", + "output", + "reason", + "candidates", + ])?; + for entry in &self.entries { + let candidates = entry + .candidates + .iter() + .map(|c| { + format!( + "{} ({}) [{}] {:.1}", + c.title, + c.year.map(|y| y.to_string()).unwrap_or_else(|| "?".into()), + c.provider, + c.score * 100.0 + ) + }) + .collect::>() + .join(" | "); + writer.write_record([ + &entry.input, + &entry.status, + entry.provider.as_deref().unwrap_or(""), + entry.result.as_deref().unwrap_or(""), + entry.output.as_deref().unwrap_or(""), + entry.reason.as_deref().unwrap_or(""), + &candidates, + ])?; + } + writer.flush()?; + Ok(()) + } +} + +fn open_writer(path: Option<&Path>) -> Result> { + if let Some(path) = path { + let file = File::create(path).with_context(|| format!("failed to create report: {}", path.display()))?; + Ok(Box::new(file)) + } else { + Ok(Box::new(io::stdout())) + } +} + +pub fn summarize_candidates(candidates: &[ScoredCandidate], limit: usize) -> Vec { + candidates + .iter() + .take(limit) + .map(|entry| CandidateSummary { + title: entry.candidate.title.clone(), + year: entry.candidate.year, + provider: entry.candidate.provider.as_str().to_string(), + score: entry.score, + }) + .collect() +} diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..3ddc143 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,99 @@ +use std::sync::{Condvar, Mutex}; + +pub fn normalize_title(input: &str) -> String { + let mut out = String::with_capacity(input.len()); + for ch in input.chars() { + if ch.is_ascii_alphanumeric() { + out.push(ch.to_ascii_lowercase()); + } else if ch.is_whitespace() { + out.push(' '); + } else { + out.push(' '); + } + } + collapse_whitespace(&out) +} + +pub fn sanitize_filename(input: &str) -> String { + let mut out = String::with_capacity(input.len()); + for ch in input.chars() { + if matches!(ch, '<' | '>' | ':' | '"' | '/' | '\\' | '|' | '?' | '*') { + out.push(' '); + } else { + out.push(ch); + } + } + collapse_whitespace(&out) +} + +pub fn collapse_whitespace(input: &str) -> String { + let mut out = String::with_capacity(input.len()); + let mut last_space = false; + for ch in input.chars() { + if ch.is_whitespace() { + if !last_space { + out.push(' '); + last_space = true; + } + } else { + last_space = false; + out.push(ch); + } + } + out.trim().to_string() +} + +pub struct Semaphore { + state: Mutex, + cvar: Condvar, +} + +impl Semaphore { + pub fn new(count: usize) -> Self { + Self { + state: Mutex::new(count), + cvar: Condvar::new(), + } + } + + pub fn acquire(&self) -> SemaphoreGuard<'_> { + let mut count = self.state.lock().unwrap(); + while *count == 0 { + count = self.cvar.wait(count).unwrap(); + } + *count -= 1; + SemaphoreGuard { sem: self } + } +} + +pub struct SemaphoreGuard<'a> { + sem: &'a Semaphore, +} + +impl Drop for SemaphoreGuard<'_> { + fn drop(&mut self) { + let mut count = self.sem.state.lock().unwrap(); + *count += 1; + self.sem.cvar.notify_one(); + } +} + +#[cfg(test)] +mod tests { + use super::{collapse_whitespace, normalize_title, sanitize_filename}; + + #[test] + fn normalizes_title() { + assert_eq!(normalize_title("The.Matrix!!"), "the matrix"); + } + + #[test] + fn sanitizes_filename() { + assert_eq!(sanitize_filename("Bad:Name/Here"), "Bad Name Here"); + } + + #[test] + fn collapses_whitespace() { + assert_eq!(collapse_whitespace("a b c"), "a b c"); + } +} diff --git a/tests/integration.rs b/tests/integration.rs new file mode 100644 index 0000000..272e86e --- /dev/null +++ b/tests/integration.rs @@ -0,0 +1,298 @@ +use std::fs; +use std::path::Path; + +use assert_cmd::Command; +use httpmock::Method::{GET, POST}; +use httpmock::MockServer; +use predicates::str::contains; +use tempfile::TempDir; + +fn make_ffprobe_stub(dir: &Path) -> std::path::PathBuf { + let bin_dir = dir.join("bin"); + fs::create_dir_all(&bin_dir).unwrap(); + let script_path = bin_dir.join("ffprobe"); + let script = r#"#!/usr/bin/env sh +echo '{"format":{"duration":"7200"},"streams":[{"codec_type":"video","codec_name":"h264","height":1080}]}' +"#; + fs::write(&script_path, script).unwrap(); + let mut perms = fs::metadata(&script_path).unwrap().permissions(); + #[cfg(unix)] + { + use std::os::unix::fs::PermissionsExt; + perms.set_mode(0o755); + fs::set_permissions(&script_path, perms).unwrap(); + } + script_path +} + +fn prepend_path(path: &Path) -> String { + let current = std::env::var("PATH").unwrap_or_default(); + format!("{}:{}", path.display(), current) +} + +#[test] +fn tmdb_flow_dry_run_with_mock_server() { + let server = MockServer::start(); + + let search_mock = server.mock(|when, then| { + when.method(GET) + .path("/search/movie") + .query_param("api_key", "test") + .query_param("query", "Some Movie") + .query_param("year", "2020"); + then.status(200) + .header("content-type", "application/json") + .body(r#"{"results":[{"id":123,"title":"Some Movie","release_date":"2020-01-02"}]}"#); + }); + + let details_mock = server.mock(|when, then| { + when.method(GET) + .path("/movie/123") + .query_param("api_key", "test"); + then.status(200) + .header("content-type", "application/json") + .body(r#"{"id":123,"title":"Some Movie","release_date":"2020-01-02","runtime":120,"imdb_id":"tt123"}"#); + }); + + let temp = TempDir::new().unwrap(); + let input = temp.path().join("input"); + let output = temp.path().join("output"); + fs::create_dir_all(&input).unwrap(); + fs::create_dir_all(&output).unwrap(); + fs::write(input.join("Some.Movie.2020.mkv"), b"stub").unwrap(); + + let ffprobe = make_ffprobe_stub(temp.path()); + + let mut cmd = Command::new(assert_cmd::cargo_bin!("mov-renamarr")); + cmd.arg("--input").arg(&input) + .arg("--output").arg(&output) + .arg("--dry-run") + .env("MOV_RENAMARR_PROVIDER", "tmdb") + .env("MOV_RENAMARR_TMDB_API_KEY", "test") + .env("MOV_RENAMARR_TMDB_BASE_URL", server.url("")) + .env("XDG_CONFIG_HOME", temp.path().join("config")) + .env("XDG_CACHE_HOME", temp.path().join("cache")) + .env("PATH", prepend_path(ffprobe.parent().unwrap())); + + cmd.assert().success().stdout(contains("renamed")); + + search_mock.assert_hits(1); + details_mock.assert_hits(1); +} + +#[test] +fn omdb_flow_dry_run_with_mock_server() { + let server = MockServer::start(); + + let search_mock = server.mock(|when, then| { + when.method(GET) + .path("/") + .query_param("apikey", "test") + .query_param("s", "Another Movie") + .query_param("type", "movie") + .query_param("y", "2019"); + then.status(200) + .header("content-type", "application/json") + .body(r#"{"Search":[{"Title":"Another Movie","Year":"2019","imdbID":"tt999"}],"Response":"True"}"#); + }); + + let details_mock = server.mock(|when, then| { + when.method(GET) + .path("/") + .query_param("apikey", "test") + .query_param("i", "tt999") + .query_param("plot", "short"); + then.status(200) + .header("content-type", "application/json") + .body(r#"{"Title":"Another Movie","Year":"2019","imdbID":"tt999","Runtime":"95 min","Response":"True"}"#); + }); + + let temp = TempDir::new().unwrap(); + let input = temp.path().join("input"); + let output = temp.path().join("output"); + fs::create_dir_all(&input).unwrap(); + fs::create_dir_all(&output).unwrap(); + fs::write(input.join("Another.Movie.2019.mkv"), b"stub").unwrap(); + + let ffprobe = make_ffprobe_stub(temp.path()); + + let mut cmd = Command::new(assert_cmd::cargo_bin!("mov-renamarr")); + cmd.arg("--input").arg(&input) + .arg("--output").arg(&output) + .arg("--dry-run") + .env("MOV_RENAMARR_PROVIDER", "omdb") + .env("MOV_RENAMARR_OMDB_API_KEY", "test") + .env("MOV_RENAMARR_OMDB_BASE_URL", server.url("")) + .env("XDG_CONFIG_HOME", temp.path().join("config")) + .env("XDG_CACHE_HOME", temp.path().join("cache")) + .env("PATH", prepend_path(ffprobe.parent().unwrap())); + + cmd.assert().success().stdout(contains("renamed")); + + search_mock.assert_hits(1); + details_mock.assert_hits(1); +} + +#[test] +fn creates_default_config_on_no_args() { + let temp = TempDir::new().unwrap(); + let config_home = temp.path().join("config"); + + let mut cmd = Command::new(assert_cmd::cargo_bin!("mov-renamarr")); + cmd.env("XDG_CONFIG_HOME", &config_home); + + cmd.assert().success().stderr(contains("Config file:")); + + let config_path = config_home.join("mov-renamarr").join("config.toml"); + assert!(config_path.exists()); + let contents = fs::read_to_string(config_path).unwrap(); + assert!(contents.contains("provider = \"auto\"")); +} + +#[test] +fn no_lookup_uses_parsed_title_and_year() { + let temp = TempDir::new().unwrap(); + let input = temp.path().join("input"); + let output = temp.path().join("output"); + fs::create_dir_all(&input).unwrap(); + fs::create_dir_all(&output).unwrap(); + fs::write(input.join("Test.Movie.2021.mkv"), b"stub").unwrap(); + + let ffprobe = make_ffprobe_stub(temp.path()); + + let mut cmd = Command::new(assert_cmd::cargo_bin!("mov-renamarr")); + cmd.arg("--input").arg(&input) + .arg("--output").arg(&output) + .arg("--dry-run") + .arg("--no-lookup") + .env("XDG_CONFIG_HOME", temp.path().join("config")) + .env("XDG_CACHE_HOME", temp.path().join("cache")) + .env("PATH", prepend_path(ffprobe.parent().unwrap())); + + cmd.assert().success().stdout(contains("parsed")); +} + +#[test] +fn no_lookup_with_llm_parse_renames_missing_year() { + let server = MockServer::start(); + let llm_mock = server.mock(|when, then| { + when.method(POST) + .path("/api/generate"); + then.status(200) + .header("content-type", "application/json") + .body(r#"{"response":"{\"title\":\"Mystery Movie\",\"year\":\"2011\",\"alt_titles\":[]}"}"#); + }); + + let temp = TempDir::new().unwrap(); + let input = temp.path().join("input"); + let output = temp.path().join("output"); + fs::create_dir_all(&input).unwrap(); + fs::create_dir_all(&output).unwrap(); + fs::write(input.join("Mystery.Movie.mkv"), b"stub").unwrap(); + + let ffprobe = make_ffprobe_stub(temp.path()); + + let mut cmd = Command::new(assert_cmd::cargo_bin!("mov-renamarr")); + cmd.arg("--input").arg(&input) + .arg("--output").arg(&output) + .arg("--dry-run") + .arg("--no-lookup") + .arg("--llm-mode").arg("parse") + .arg("--llm-endpoint").arg(server.url("")) + .arg("--llm-model").arg("qwen") + .env("XDG_CONFIG_HOME", temp.path().join("config")) + .env("XDG_CACHE_HOME", temp.path().join("cache")) + .env("PATH", prepend_path(ffprobe.parent().unwrap())); + + cmd.assert() + .success() + .stdout(contains("Mystery Movie (2011)")) + .stdout(contains("parsed")); + + llm_mock.assert_hits(1); +} + +#[test] +fn collision_policy_skips_existing_destination() { + let temp = TempDir::new().unwrap(); + let input = temp.path().join("input"); + let output = temp.path().join("output"); + fs::create_dir_all(&input).unwrap(); + fs::create_dir_all(&output).unwrap(); + fs::write(input.join("Some.Movie.2020.mkv"), b"stub").unwrap(); + + let ffprobe = make_ffprobe_stub(temp.path()); + + // Pre-create destination to trigger collision skip. + let dest_dir = output.join("Some Movie (2020)"); + fs::create_dir_all(&dest_dir).unwrap(); + let dest_path = dest_dir.join("Some Movie (2020) [1080p].mkv"); + fs::write(&dest_path, b"existing").unwrap(); + + let mut cmd = Command::new(assert_cmd::cargo_bin!("mov-renamarr")); + cmd.arg("--input").arg(&input) + .arg("--output").arg(&output) + .arg("--no-lookup") + .env("XDG_CONFIG_HOME", temp.path().join("config")) + .env("XDG_CACHE_HOME", temp.path().join("cache")) + .env("PATH", prepend_path(ffprobe.parent().unwrap())); + + cmd.assert().success().stdout(contains("destination exists")); + + assert!(dest_path.exists()); + assert!(input.join("Some.Movie.2020.mkv").exists()); +} + +#[test] +fn sidecars_are_copied_when_enabled() { + let temp = TempDir::new().unwrap(); + let input = temp.path().join("input"); + let output = temp.path().join("output"); + fs::create_dir_all(&input).unwrap(); + fs::create_dir_all(&output).unwrap(); + fs::write(input.join("Film.2020.mkv"), b"stub").unwrap(); + fs::write(input.join("Film.2020.srt"), b"sub").unwrap(); + fs::write(input.join("Film.2020.nfo"), b"nfo").unwrap(); + + let ffprobe = make_ffprobe_stub(temp.path()); + + let mut cmd = Command::new(assert_cmd::cargo_bin!("mov-renamarr")); + cmd.arg("--input").arg(&input) + .arg("--output").arg(&output) + .arg("--no-lookup") + .arg("--sidecars") + .env("XDG_CONFIG_HOME", temp.path().join("config")) + .env("XDG_CACHE_HOME", temp.path().join("cache")) + .env("PATH", prepend_path(ffprobe.parent().unwrap())); + + cmd.assert().success(); + + let out_dir = output.join("Film (2020)"); + assert!(out_dir.join("Film (2020) [1080p].mkv").exists()); + assert!(out_dir.join("Film (2020) [1080p].srt").exists()); + assert!(out_dir.join("Film (2020) [1080p].nfo").exists()); +} + +#[test] +fn rename_in_place_uses_input_as_output() { + let temp = TempDir::new().unwrap(); + let input = temp.path().join("input"); + fs::create_dir_all(&input).unwrap(); + fs::write(input.join("Alien.1979.1080p.mkv"), b"stub").unwrap(); + + let ffprobe = make_ffprobe_stub(temp.path()); + + let mut cmd = Command::new(assert_cmd::cargo_bin!("mov-renamarr")); + cmd.arg("--input").arg(&input) + .arg("--rename-in-place") + .arg("--no-lookup") + .env("XDG_CONFIG_HOME", temp.path().join("config")) + .env("XDG_CACHE_HOME", temp.path().join("cache")) + .env("PATH", prepend_path(ffprobe.parent().unwrap())); + + cmd.assert().success().stdout(contains("renamed")); + + let renamed = input.join("Alien (1979)").join("Alien (1979) [1080p].mkv"); + assert!(renamed.exists()); + assert!(!input.join("Alien.1979.1080p.mkv").exists()); +}