Fix interactive season choosing false-positive triggering

This commit is contained in:
ByteDream 2023-01-09 16:55:10 +01:00
parent 4b33ef02c6
commit 12be16417f
8 changed files with 157 additions and 197 deletions

85
Cargo.lock generated
View file

@ -222,7 +222,7 @@ dependencies = [
"lazy_static", "lazy_static",
"libc", "libc",
"unicode-width", "unicode-width",
"windows-sys 0.42.0", "windows-sys",
] ]
[[package]] [[package]]
@ -302,6 +302,7 @@ dependencies = [
"ctrlc", "ctrlc",
"dirs", "dirs",
"indicatif", "indicatif",
"lazy_static",
"log", "log",
"num_cpus", "num_cpus",
"regex", "regex",
@ -390,7 +391,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1631ca6e3c59112501a9d87fd86f21591ff77acd31331e8a73f8d80a65bbdd71" checksum = "1631ca6e3c59112501a9d87fd86f21591ff77acd31331e8a73f8d80a65bbdd71"
dependencies = [ dependencies = [
"nix", "nix",
"windows-sys 0.42.0", "windows-sys",
] ]
[[package]] [[package]]
@ -859,14 +860,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c"
dependencies = [ dependencies = [
"libc", "libc",
"windows-sys 0.42.0", "windows-sys",
] ]
[[package]] [[package]]
name = "ipnet" name = "ipnet"
version = "2.7.0" version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11b0d96e660696543b251e58030cf9787df56da39dab19ad60eae7353040917e" checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146"
[[package]] [[package]]
name = "is-terminal" name = "is-terminal"
@ -877,7 +878,7 @@ dependencies = [
"hermit-abi", "hermit-abi",
"io-lifetimes", "io-lifetimes",
"rustix", "rustix",
"windows-sys 0.42.0", "windows-sys",
] ]
[[package]] [[package]]
@ -980,7 +981,7 @@ dependencies = [
"libc", "libc",
"log", "log",
"wasi 0.11.0+wasi-snapshot-preview1", "wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys 0.42.0", "windows-sys",
] ]
[[package]] [[package]]
@ -1231,9 +1232,9 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.7.0" version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@ -1338,7 +1339,7 @@ dependencies = [
"io-lifetimes", "io-lifetimes",
"libc", "libc",
"linux-raw-sys", "linux-raw-sys",
"windows-sys 0.42.0", "windows-sys",
] ]
[[package]] [[package]]
@ -1380,12 +1381,11 @@ dependencies = [
[[package]] [[package]]
name = "schannel" name = "schannel"
version = "0.1.20" version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3"
dependencies = [ dependencies = [
"lazy_static", "windows-sys",
"windows-sys 0.36.1",
] ]
[[package]] [[package]]
@ -1591,7 +1591,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb20089a8ba2b69debd491f8d2d023761cbf196e999218c591fa1e7e15a21907" checksum = "cb20089a8ba2b69debd491f8d2d023761cbf196e999218c591fa1e7e15a21907"
dependencies = [ dependencies = [
"rustix", "rustix",
"windows-sys 0.42.0", "windows-sys",
] ]
[[package]] [[package]]
@ -1682,7 +1682,7 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
"socket2", "socket2",
"tokio-macros", "tokio-macros",
"windows-sys 0.42.0", "windows-sys",
] ]
[[package]] [[package]]
@ -1973,19 +1973,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2"
dependencies = [
"windows_aarch64_msvc 0.36.1",
"windows_i686_gnu 0.36.1",
"windows_i686_msvc 0.36.1",
"windows_x86_64_gnu 0.36.1",
"windows_x86_64_msvc 0.36.1",
]
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.42.0" version = "0.42.0"
@ -1993,12 +1980,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
dependencies = [ dependencies = [
"windows_aarch64_gnullvm", "windows_aarch64_gnullvm",
"windows_aarch64_msvc 0.42.0", "windows_aarch64_msvc",
"windows_i686_gnu 0.42.0", "windows_i686_gnu",
"windows_i686_msvc 0.42.0", "windows_i686_msvc",
"windows_x86_64_gnu 0.42.0", "windows_x86_64_gnu",
"windows_x86_64_gnullvm", "windows_x86_64_gnullvm",
"windows_x86_64_msvc 0.42.0", "windows_x86_64_msvc",
] ]
[[package]] [[package]]
@ -2007,48 +1994,24 @@ version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e"
[[package]]
name = "windows_aarch64_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
[[package]] [[package]]
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
version = "0.42.0" version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4"
[[package]]
name = "windows_i686_gnu"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
[[package]] [[package]]
name = "windows_i686_gnu" name = "windows_i686_gnu"
version = "0.42.0" version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7"
[[package]]
name = "windows_i686_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
[[package]] [[package]]
name = "windows_i686_msvc" name = "windows_i686_msvc"
version = "0.42.0" version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246"
[[package]]
name = "windows_x86_64_gnu"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
[[package]] [[package]]
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
version = "0.42.0" version = "0.42.0"
@ -2061,12 +2024,6 @@ version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028"
[[package]]
name = "windows_x86_64_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
[[package]] [[package]]
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
version = "0.42.0" version = "0.42.0"

View file

@ -203,7 +203,7 @@ dependencies = [
"lazy_static", "lazy_static",
"libc", "libc",
"unicode-width", "unicode-width",
"windows-sys 0.42.0", "windows-sys",
] ]
[[package]] [[package]]
@ -271,6 +271,7 @@ dependencies = [
"ctrlc", "ctrlc",
"dirs", "dirs",
"indicatif", "indicatif",
"lazy_static",
"log", "log",
"num_cpus", "num_cpus",
"regex", "regex",
@ -359,7 +360,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1631ca6e3c59112501a9d87fd86f21591ff77acd31331e8a73f8d80a65bbdd71" checksum = "1631ca6e3c59112501a9d87fd86f21591ff77acd31331e8a73f8d80a65bbdd71"
dependencies = [ dependencies = [
"nix", "nix",
"windows-sys 0.42.0", "windows-sys",
] ]
[[package]] [[package]]
@ -828,14 +829,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c"
dependencies = [ dependencies = [
"libc", "libc",
"windows-sys 0.42.0", "windows-sys",
] ]
[[package]] [[package]]
name = "ipnet" name = "ipnet"
version = "2.7.0" version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11b0d96e660696543b251e58030cf9787df56da39dab19ad60eae7353040917e" checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146"
[[package]] [[package]]
name = "is-terminal" name = "is-terminal"
@ -846,7 +847,7 @@ dependencies = [
"hermit-abi", "hermit-abi",
"io-lifetimes", "io-lifetimes",
"rustix", "rustix",
"windows-sys 0.42.0", "windows-sys",
] ]
[[package]] [[package]]
@ -949,7 +950,7 @@ dependencies = [
"libc", "libc",
"log", "log",
"wasi 0.11.0+wasi-snapshot-preview1", "wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys 0.42.0", "windows-sys",
] ]
[[package]] [[package]]
@ -1200,9 +1201,9 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.7.0" version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@ -1301,7 +1302,7 @@ dependencies = [
"io-lifetimes", "io-lifetimes",
"libc", "libc",
"linux-raw-sys", "linux-raw-sys",
"windows-sys 0.42.0", "windows-sys",
] ]
[[package]] [[package]]
@ -1343,12 +1344,11 @@ dependencies = [
[[package]] [[package]]
name = "schannel" name = "schannel"
version = "0.1.20" version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3"
dependencies = [ dependencies = [
"lazy_static", "windows-sys",
"windows-sys 0.36.1",
] ]
[[package]] [[package]]
@ -1554,7 +1554,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb20089a8ba2b69debd491f8d2d023761cbf196e999218c591fa1e7e15a21907" checksum = "cb20089a8ba2b69debd491f8d2d023761cbf196e999218c591fa1e7e15a21907"
dependencies = [ dependencies = [
"rustix", "rustix",
"windows-sys 0.42.0", "windows-sys",
] ]
[[package]] [[package]]
@ -1645,7 +1645,7 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
"socket2", "socket2",
"tokio-macros", "tokio-macros",
"windows-sys 0.42.0", "windows-sys",
] ]
[[package]] [[package]]
@ -1936,19 +1936,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2"
dependencies = [
"windows_aarch64_msvc 0.36.1",
"windows_i686_gnu 0.36.1",
"windows_i686_msvc 0.36.1",
"windows_x86_64_gnu 0.36.1",
"windows_x86_64_msvc 0.36.1",
]
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.42.0" version = "0.42.0"
@ -1956,12 +1943,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
dependencies = [ dependencies = [
"windows_aarch64_gnullvm", "windows_aarch64_gnullvm",
"windows_aarch64_msvc 0.42.0", "windows_aarch64_msvc",
"windows_i686_gnu 0.42.0", "windows_i686_gnu",
"windows_i686_msvc 0.42.0", "windows_i686_msvc",
"windows_x86_64_gnu 0.42.0", "windows_x86_64_gnu",
"windows_x86_64_gnullvm", "windows_x86_64_gnullvm",
"windows_x86_64_msvc 0.42.0", "windows_x86_64_msvc",
] ]
[[package]] [[package]]
@ -1970,48 +1957,24 @@ version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e"
[[package]]
name = "windows_aarch64_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
[[package]] [[package]]
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
version = "0.42.0" version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4"
[[package]]
name = "windows_i686_gnu"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
[[package]] [[package]]
name = "windows_i686_gnu" name = "windows_i686_gnu"
version = "0.42.0" version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7"
[[package]]
name = "windows_i686_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
[[package]] [[package]]
name = "windows_i686_msvc" name = "windows_i686_msvc"
version = "0.42.0" version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246"
[[package]]
name = "windows_x86_64_gnu"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
[[package]] [[package]]
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
version = "0.42.0" version = "0.42.0"
@ -2024,12 +1987,6 @@ version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028"
[[package]]
name = "windows_x86_64_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
[[package]] [[package]]
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
version = "0.42.0" version = "0.42.0"

View file

@ -14,6 +14,7 @@ csv = "1.1"
ctrlc = "3.2" ctrlc = "3.2"
dirs = "4.0" dirs = "4.0"
indicatif = "0.17" indicatif = "0.17"
lazy_static = "1.4"
log = { version = "0.4", features = ["std"] } log = { version = "0.4", features = ["std"] }
num_cpus = "1.15" num_cpus = "1.15"
regex = "1.7" regex = "1.7"

View file

@ -1,7 +1,10 @@
use crate::cli::log::tab_info; use crate::cli::log::tab_info;
use crate::cli::utils::{download_segments, find_resolution, FFmpegPreset, find_multiple_seasons_with_same_number, interactive_season_choosing}; use crate::cli::utils::{
download_segments, find_multiple_seasons_with_same_number, find_resolution,
interactive_season_choosing, FFmpegPreset,
};
use crate::utils::context::Context; use crate::utils::context::Context;
use crate::utils::format::{Format, format_path}; use crate::utils::format::{format_path, Format};
use crate::utils::log::progress; use crate::utils::log::progress;
use crate::utils::os::{free_file, has_ffmpeg, is_special_file, tempfile}; use crate::utils::os::{free_file, has_ffmpeg, is_special_file, tempfile};
use crate::utils::parse::{parse_url, UrlFilter}; use crate::utils::parse::{parse_url, UrlFilter};
@ -240,11 +243,16 @@ impl Execute for Archive {
for (formats, mut subtitles) in archive_formats { for (formats, mut subtitles) in archive_formats {
let (primary, additionally) = formats.split_first().unwrap(); let (primary, additionally) = formats.split_first().unwrap();
let path = free_file(format_path(if self.output.is_empty() { let path = free_file(format_path(
"{title}.mkv" if self.output.is_empty() {
} else { "{title}.mkv"
&self.output } else {
}.into(), &primary, true)); &self.output
}
.into(),
&primary,
true,
));
info!( info!(
"Downloading {} to '{}'", "Downloading {} to '{}'",
@ -387,15 +395,6 @@ async fn formats_from_series(
let mut result: BTreeMap<u32, BTreeMap<u32, (Vec<Format>, Vec<Subtitle>)>> = BTreeMap::new(); let mut result: BTreeMap<u32, BTreeMap<u32, (Vec<Format>, Vec<Subtitle>)>> = BTreeMap::new();
let mut primary_season = true; let mut primary_season = true;
for season in seasons { for season in seasons {
if !url_filter.is_season_valid(season.metadata.season_number)
|| !archive
.locale
.iter()
.any(|l| season.metadata.audio_locales.contains(l))
{
continue;
}
for episode in season.episodes().await? { for episode in season.episodes().await? {
if !url_filter.is_episode_valid( if !url_filter.is_episode_valid(
episode.metadata.episode_number, episode.metadata.episode_number,

View file

@ -1,7 +1,10 @@
use crate::cli::log::tab_info; use crate::cli::log::tab_info;
use crate::cli::utils::{download_segments, find_resolution, FFmpegPreset, interactive_season_choosing, find_multiple_seasons_with_same_number}; use crate::cli::utils::{
download_segments, find_multiple_seasons_with_same_number, find_resolution,
interactive_season_choosing, FFmpegPreset,
};
use crate::utils::context::Context; use crate::utils::context::Context;
use crate::utils::format::{Format, format_path}; use crate::utils::format::{format_path, Format};
use crate::utils::log::progress; use crate::utils::log::progress;
use crate::utils::os::{free_file, has_ffmpeg, is_special_file}; use crate::utils::os::{free_file, has_ffmpeg, is_special_file};
use crate::utils::parse::{parse_url, UrlFilter}; use crate::utils::parse::{parse_url, UrlFilter};
@ -206,11 +209,16 @@ impl Execute for Download {
} }
for format in formats { for format in formats {
let path = free_file(format_path(if self.output.is_empty() { let path = free_file(format_path(
"{title}.mkv" if self.output.is_empty() {
} else { "{title}.mkv"
&self.output } else {
}.into(), &format, true)); &self.output
}
.into(),
&format,
true,
));
info!( info!(
"Downloading {} to '{}'", "Downloading {} to '{}'",

View file

@ -1,15 +1,16 @@
use crate::utils::context::Context; use crate::utils::context::Context;
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use crunchyroll_rs::media::{Resolution, VariantData, VariantSegment}; use crunchyroll_rs::media::{Resolution, VariantData, VariantSegment};
use crunchyroll_rs::{Media, Season};
use indicatif::{ProgressBar, ProgressFinish, ProgressStyle}; use indicatif::{ProgressBar, ProgressFinish, ProgressStyle};
use lazy_static::lazy_static;
use log::{debug, LevelFilter}; use log::{debug, LevelFilter};
use regex::Regex;
use std::borrow::{Borrow, BorrowMut}; use std::borrow::{Borrow, BorrowMut};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::io::{BufRead, Write}; use std::io::{BufRead, Write};
use std::sync::{mpsc, Arc, Mutex}; use std::sync::{mpsc, Arc, Mutex};
use std::time::Duration; use std::time::Duration;
use crunchyroll_rs::{Media, Season};
use regex::Regex;
use tokio::task::JoinSet; use tokio::task::JoinSet;
pub fn find_resolution( pub fn find_resolution(
@ -111,7 +112,7 @@ pub async fn download_segments(
}; };
buf = VariantSegment::decrypt(buf.borrow_mut(), segment.key)?.to_vec(); buf = VariantSegment::decrypt(buf.borrow_mut(), segment.key)?.to_vec();
let mut c = thread_count.lock().unwrap(); let mut c = thread_count.lock().unwrap();
debug!( debug!(
"Downloaded and decrypted segment [{}/{} {:.2}%] {}", "Downloaded and decrypted segment [{}/{} {:.2}%] {}",
@ -120,14 +121,14 @@ pub async fn download_segments(
((*c + 1) as f64 / total_segments as f64) * 100f64, ((*c + 1) as f64 / total_segments as f64) * 100f64,
segment.url segment.url
); );
thread_sender.send((num as i32 + (i * cpus) as i32, buf))?; thread_sender.send((num as i32 + (i * cpus) as i32, buf))?;
*c += 1; *c += 1;
} }
Ok(()) Ok(())
}; };
let result = download().await; let result = download().await;
if result.is_err() { if result.is_err() {
@ -149,7 +150,7 @@ pub async fn download_segments(
for (pos, bytes) in receiver.iter() { for (pos, bytes) in receiver.iter() {
// if the position is lower than 0, an error occured in the sending download thread // if the position is lower than 0, an error occured in the sending download thread
if pos < 0 { if pos < 0 {
break break;
} }
if let Some(p) = &progress { if let Some(p) = &progress {
@ -330,6 +331,10 @@ impl FFmpegPreset {
} }
} }
lazy_static! {
static ref DUPLICATED_SEASONS_MULTILANG_REGEX: Regex = Regex::new(r"(-castilian|-english|-english-in|-french|-german|-hindi|-italian|-portuguese|-russian|-spanish)$").unwrap();
}
pub(crate) fn find_multiple_seasons_with_same_number(seasons: &Vec<Media<Season>>) -> Vec<u32> { pub(crate) fn find_multiple_seasons_with_same_number(seasons: &Vec<Media<Season>>) -> Vec<u32> {
let mut seasons_map: BTreeMap<u32, u32> = BTreeMap::new(); let mut seasons_map: BTreeMap<u32, u32> = BTreeMap::new();
for season in seasons { for season in seasons {
@ -342,7 +347,25 @@ pub(crate) fn find_multiple_seasons_with_same_number(seasons: &Vec<Media<Season>
seasons_map seasons_map
.into_iter() .into_iter()
.filter_map(|(k, v)| if v > 1 { Some(k) } else { None }) .filter_map(|(k, v)| {
if v > 1 {
// check if the different seasons are actual the same but with different dub languages
let mut multilang_season_vec: Vec<String> = seasons
.iter()
.map(|s| {
DUPLICATED_SEASONS_MULTILANG_REGEX
.replace(s.slug_title.trim_end_matches("-dub"), "")
.to_string()
})
.collect();
multilang_season_vec.dedup();
if multilang_season_vec.len() > 1 {
return Some(k);
}
}
None
})
.collect() .collect()
} }
@ -363,6 +386,22 @@ pub(crate) fn interactive_season_choosing(seasons: Vec<Media<Season>>) -> Vec<Me
if season_vec.len() == 1 { if season_vec.len() == 1 {
continue; continue;
} }
// check if the different seasons are actual the same but with different dub languages
let mut multilang_season_vec: Vec<String> = season_vec
.iter()
.map(|s| {
DUPLICATED_SEASONS_MULTILANG_REGEX
.replace(s.slug_title.trim_end_matches("-dub"), "")
.to_string()
})
.collect();
multilang_season_vec.dedup();
if multilang_season_vec.len() == 1 {
continue;
}
println!(":: Found multiple seasons for season number {}", num); println!(":: Found multiple seasons for season number {}", num);
println!(":: Select the number of the seasons you want to download (eg \"1 2 4\", \"1-3\", \"1-3 5\"):"); println!(":: Select the number of the seasons you want to download (eg \"1 2 4\", \"1-3\", \"1-3 5\"):");
for (i, season) in season_vec.iter().enumerate() { for (i, season) in season_vec.iter().enumerate() {
@ -372,7 +411,8 @@ pub(crate) fn interactive_season_choosing(seasons: Vec<Media<Season>>) -> Vec<Me
let _ = write!(stdout, ":: => "); let _ = write!(stdout, ":: => ");
let _ = stdout.flush(); let _ = stdout.flush();
let mut user_input = String::new(); let mut user_input = String::new();
std::io::stdin().lock() std::io::stdin()
.lock()
.read_line(&mut user_input) .read_line(&mut user_input)
.expect("cannot open stdin"); .expect("cannot open stdin");
@ -400,13 +440,7 @@ pub(crate) fn interactive_season_choosing(seasons: Vec<Media<Season>>) -> Vec<Me
season_vec season_vec
.iter() .iter()
.enumerate() .enumerate()
.filter_map(|(i, _)| { .filter_map(|(i, _)| if i >= from && i <= to { Some(i) } else { None })
if i >= from && i <= to {
Some(i)
} else {
None
}
})
.collect::<Vec<usize>>(), .collect::<Vec<usize>>(),
) )
} }
@ -430,4 +464,3 @@ pub(crate) fn interactive_season_choosing(seasons: Vec<Media<Season>>) -> Vec<Me
.flatten() .flatten()
.collect::<Vec<Media<Season>>>() .collect::<Vec<Media<Season>>>()
} }

View file

@ -1,6 +1,6 @@
use std::path::PathBuf;
use crunchyroll_rs::media::VariantData; use crunchyroll_rs::media::VariantData;
use crunchyroll_rs::{Episode, Locale, Media, Movie}; use crunchyroll_rs::{Episode, Locale, Media, Movie};
use std::path::PathBuf;
use std::time::Duration; use std::time::Duration;
#[derive(Clone)] #[derive(Clone)]
@ -76,31 +76,34 @@ pub fn format_path(path: PathBuf, format: &Format, sanitize: bool) -> PathBuf {
let as_string = path.to_string_lossy().to_string(); let as_string = path.to_string_lossy().to_string();
PathBuf::from(as_string.replace("{title}", &sanitize_func(&format.title)) PathBuf::from(
.replace("{series_name}", &sanitize_func(&format.series_name)) as_string
.replace("{season_name}", &sanitize_func(&format.season_title)) .replace("{title}", &sanitize_func(&format.title))
.replace("{audio}", &sanitize_func(&format.audio.to_string())) .replace("{series_name}", &sanitize_func(&format.series_name))
.replace( .replace("{season_name}", &sanitize_func(&format.season_title))
"{resolution}", .replace("{audio}", &sanitize_func(&format.audio.to_string()))
&sanitize_func(&format.stream.resolution.to_string()), .replace(
) "{resolution}",
.replace( &sanitize_func(&format.stream.resolution.to_string()),
"{padded_season_number}", )
&sanitize_func(&format!("{:0>2}", format.season_number.to_string())), .replace(
) "{padded_season_number}",
.replace( &sanitize_func(&format!("{:0>2}", format.season_number.to_string())),
"{season_number}", )
&sanitize_func(&format.season_number.to_string()), .replace(
) "{season_number}",
.replace( &sanitize_func(&format.season_number.to_string()),
"{padded_episode_number}", )
&sanitize_func(&format!("{:0>2}", format.number.to_string())), .replace(
) "{padded_episode_number}",
.replace( &sanitize_func(&format!("{:0>2}", format.number.to_string())),
"{episode_number}", )
&sanitize_func(&format.number.to_string()), .replace(
) "{episode_number}",
.replace("{series_id}", &sanitize_func(&format.series_id)) &sanitize_func(&format.number.to_string()),
.replace("{season_id}", &sanitize_func(&format.season_id)) )
.replace("{episode_id}", &sanitize_func(&format.id))) .replace("{series_id}", &sanitize_func(&format.series_id))
.replace("{season_id}", &sanitize_func(&format.season_id))
.replace("{episode_id}", &sanitize_func(&format.id)),
)
} }

View file

@ -33,7 +33,9 @@ pub fn sort_formats_after_seasons(formats: Vec<Format>) -> Vec<Vec<Format>> {
// the season title is used as key instead of season number to distinguish duplicated season // the season title is used as key instead of season number to distinguish duplicated season
// numbers which are actually two different seasons; season id is not used as this somehow // numbers which are actually two different seasons; season id is not used as this somehow
// messes up ordering when duplicated seasons exist // messes up ordering when duplicated seasons exist
as_map.entry(format.season_title.clone()).or_insert_with(Vec::new); as_map
.entry(format.season_title.clone())
.or_insert_with(Vec::new);
as_map.get_mut(&format.season_title).unwrap().push(format); as_map.get_mut(&format.season_title).unwrap().push(format);
} }