mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Compare commits
No commits in common. "master" and "v3.5.1" have entirely different histories.
27 changed files with 1519 additions and 1500 deletions
|
|
@ -15,23 +15,13 @@ sha256sums=('$CI_SHA_SUM')
|
||||||
# lto causes linking errors when executed by this buildscript. besides, lto is already done by cargo itself (which doesn't cause linking errors)
|
# lto causes linking errors when executed by this buildscript. besides, lto is already done by cargo itself (which doesn't cause linking errors)
|
||||||
options=(!lto)
|
options=(!lto)
|
||||||
|
|
||||||
prepare() {
|
|
||||||
cd "$srcdir/${pkgname}-$pkgver"
|
|
||||||
|
|
||||||
export RUSTUP_TOOLCHAIN=stable
|
|
||||||
export CARGO_HOME="$srcdir/cargo-home"
|
|
||||||
|
|
||||||
cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
|
|
||||||
}
|
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
cd "$srcdir/${pkgname}-$pkgver"
|
cd "$srcdir/${pkgname}-$pkgver"
|
||||||
|
|
||||||
export RUSTUP_TOOLCHAIN=stable
|
|
||||||
export CARGO_HOME="$srcdir/cargo-home"
|
export CARGO_HOME="$srcdir/cargo-home"
|
||||||
|
export RUSTUP_TOOLCHAIN=stable
|
||||||
|
|
||||||
export CRUNCHY_CLI_GIT_HASH=$CI_GIT_HASH
|
cargo build --release
|
||||||
cargo build --frozen --release
|
|
||||||
}
|
}
|
||||||
|
|
||||||
package() {
|
package() {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
name: build
|
name: ci
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
|
@ -41,7 +41,7 @@ jobs:
|
||||||
run: cargo install --force cross
|
run: cargo install --force cross
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cross build --locked --release --no-default-features --features openssl-tls-static --target ${{ matrix.toolchain }}
|
run: cross build --release --no-default-features --features openssl-tls-static --target ${{ matrix.toolchain }}
|
||||||
|
|
||||||
- name: Upload binary artifact
|
- name: Upload binary artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
|
|
@ -101,7 +101,7 @@ jobs:
|
||||||
toolchain: stable
|
toolchain: stable
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cargo build --locked --release --target ${{ matrix.toolchain }}
|
run: cargo build --release --target ${{ matrix.toolchain }}
|
||||||
|
|
||||||
- name: Upload binary artifact
|
- name: Upload binary artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
|
|
@ -135,7 +135,7 @@ jobs:
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
shell: msys2 {0}
|
shell: msys2 {0}
|
||||||
run: cargo build --locked --release --target x86_64-pc-windows-gnu
|
run: cargo build --release --target x86_64-pc-windows-gnu
|
||||||
|
|
||||||
- name: Upload binary artifact
|
- name: Upload binary artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
58
.github/workflows/lint.yml
vendored
58
.github/workflows/lint.yml
vendored
|
|
@ -1,58 +0,0 @@
|
||||||
name: lint
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- '*'
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
fmt:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Cargo cache
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.cargo/bin/
|
|
||||||
~/.cargo/registry/index/
|
|
||||||
~/.cargo/registry/cache/
|
|
||||||
~/.cargo/git/db/
|
|
||||||
target/
|
|
||||||
key: x86_64-unknown-linux-gnu-cargo-${{ hashFiles('**/Cargo.lock') }}
|
|
||||||
|
|
||||||
- name: Setup Rust
|
|
||||||
uses: dtolnay/rust-toolchain@stable
|
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
|
|
||||||
- name: Check fmt
|
|
||||||
run: cargo fmt --check
|
|
||||||
|
|
||||||
lint:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Cargo cache
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.cargo/bin/
|
|
||||||
~/.cargo/registry/index/
|
|
||||||
~/.cargo/registry/cache/
|
|
||||||
~/.cargo/git/db/
|
|
||||||
target/
|
|
||||||
key: x86_64-unknown-linux-gnu-cargo-${{ hashFiles('**/Cargo.lock') }}
|
|
||||||
|
|
||||||
- name: Setup Rust
|
|
||||||
uses: dtolnay/rust-toolchain@stable
|
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
|
|
||||||
- name: Lint
|
|
||||||
run: cargo clippy -- -D warnings
|
|
||||||
8
.github/workflows/publish.yml
vendored
8
.github/workflows/publish.yml
vendored
|
|
@ -20,15 +20,11 @@ jobs:
|
||||||
curl -LO https://github.com/crunchy-labs/crunchy-cli/archive/refs/tags/${{ github.ref_name }}.tar.gz
|
curl -LO https://github.com/crunchy-labs/crunchy-cli/archive/refs/tags/${{ github.ref_name }}.tar.gz
|
||||||
echo "CRUNCHY_CLI_SHA256=$(sha256sum ${{ github.ref_name }}.tar.gz | cut -f 1 -d ' ')" >> $GITHUB_ENV
|
echo "CRUNCHY_CLI_SHA256=$(sha256sum ${{ github.ref_name }}.tar.gz | cut -f 1 -d ' ')" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Get release commit hash
|
|
||||||
run: echo "CRUNCHY_CLI_GIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Generate crunchy-cli PKGBUILD
|
- name: Generate crunchy-cli PKGBUILD
|
||||||
env:
|
env:
|
||||||
CI_PKG_VERSION: ${{ env.RELEASE_VERSION }}
|
CI_PKG_VERSION: ${{ env.RELEASE_VERSION }}
|
||||||
CI_SHA_SUM: ${{ env.CRUNCHY_CLI_SHA256 }}
|
CI_SHA_SUM: ${{ env.CRUNCHY_CLI_SHA256 }}
|
||||||
CI_GIT_HASH: ${{ env.CRUNCHY_CLI_GIT_HASH }}
|
run: envsubst '$CI_PKG_VERSION,$CI_SHA_SUM' < .github/scripts/PKGBUILD.source > PKGBUILD
|
||||||
run: envsubst '$CI_PKG_VERSION,$CI_SHA_SUM,$CI_GIT_HASH' < .github/workflow-resources/PKGBUILD.source > PKGBUILD
|
|
||||||
|
|
||||||
- name: Publish crunchy-cli to AUR
|
- name: Publish crunchy-cli to AUR
|
||||||
uses: KSXGitHub/github-actions-deploy-aur@v2.7.0
|
uses: KSXGitHub/github-actions-deploy-aur@v2.7.0
|
||||||
|
|
@ -61,7 +57,7 @@ jobs:
|
||||||
CI_MANPAGES_SHA_SUM: ${{ env.CRUNCHY_CLI_BIN_MANPAGES_SHA256 }}
|
CI_MANPAGES_SHA_SUM: ${{ env.CRUNCHY_CLI_BIN_MANPAGES_SHA256 }}
|
||||||
CI_COMPLETIONS_SHA_SUM: ${{ env.CRUNCHY_CLI_BIN_COMPLETIONS_SHA256 }}
|
CI_COMPLETIONS_SHA_SUM: ${{ env.CRUNCHY_CLI_BIN_COMPLETIONS_SHA256 }}
|
||||||
CI_LICENSE_SHA_SUM: ${{ env.CRUNCHY_CLI_BIN_LICENSE_SHA256 }}
|
CI_LICENSE_SHA_SUM: ${{ env.CRUNCHY_CLI_BIN_LICENSE_SHA256 }}
|
||||||
run: envsubst '$CI_PKG_VERSION,$CI_AMD_BINARY_SHA_SUM,$CI_ARM_BINARY_SHA_SUM,$CI_COMPLETIONS_SHA_SUM,$CI_MANPAGES_SHA_SUM,$CI_LICENSE_SHA_SUM' < .github/workflow-resources/PKGBUILD.binary > PKGBUILD
|
run: envsubst '$CI_PKG_VERSION,$CI_AMD_BINARY_SHA_SUM,$CI_ARM_BINARY_SHA_SUM,$CI_COMPLETIONS_SHA_SUM,$CI_MANPAGES_SHA_SUM,$CI_LICENSE_SHA_SUM' < .github/scripts/PKGBUILD.binary > PKGBUILD
|
||||||
|
|
||||||
- name: Publish crunchy-cli-bin to AUR
|
- name: Publish crunchy-cli-bin to AUR
|
||||||
uses: KSXGitHub/github-actions-deploy-aur@v2.7.0
|
uses: KSXGitHub/github-actions-deploy-aur@v2.7.0
|
||||||
|
|
|
||||||
352
Cargo.lock
generated
352
Cargo.lock
generated
|
|
@ -43,48 +43,47 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstream"
|
name = "anstream"
|
||||||
version = "0.6.14"
|
version = "0.6.13"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b"
|
checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstyle",
|
"anstyle",
|
||||||
"anstyle-parse",
|
"anstyle-parse",
|
||||||
"anstyle-query",
|
"anstyle-query",
|
||||||
"anstyle-wincon",
|
"anstyle-wincon",
|
||||||
"colorchoice",
|
"colorchoice",
|
||||||
"is_terminal_polyfill",
|
|
||||||
"utf8parse",
|
"utf8parse",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstyle"
|
name = "anstyle"
|
||||||
version = "1.0.7"
|
version = "1.0.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b"
|
checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstyle-parse"
|
name = "anstyle-parse"
|
||||||
version = "0.2.4"
|
version = "0.2.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4"
|
checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"utf8parse",
|
"utf8parse",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstyle-query"
|
name = "anstyle-query"
|
||||||
version = "1.0.3"
|
version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5"
|
checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstyle-wincon"
|
name = "anstyle-wincon"
|
||||||
version = "3.0.3"
|
version = "3.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19"
|
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstyle",
|
"anstyle",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
|
|
@ -92,9 +91,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.86"
|
version = "1.0.82"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
|
checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-speed-limit"
|
name = "async-speed-limit"
|
||||||
|
|
@ -119,17 +118,11 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "atomic-waker"
|
|
||||||
version = "1.1.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.3.0"
|
version = "1.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
|
checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "backtrace"
|
name = "backtrace"
|
||||||
|
|
@ -154,9 +147,9 @@ checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "base64"
|
name = "base64"
|
||||||
version = "0.22.1"
|
version = "0.22.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "base64-serde"
|
name = "base64-serde"
|
||||||
|
|
@ -186,6 +179,18 @@ version = "3.16.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
|
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bytemuck"
|
||||||
|
version = "1.15.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byteorder"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytes"
|
name = "bytes"
|
||||||
version = "1.6.0"
|
version = "1.6.0"
|
||||||
|
|
@ -194,9 +199,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.98"
|
version = "1.0.95"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f"
|
checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
|
|
@ -244,7 +249,7 @@ dependencies = [
|
||||||
"anstream",
|
"anstream",
|
||||||
"anstyle",
|
"anstyle",
|
||||||
"clap_lex",
|
"clap_lex",
|
||||||
"strsim",
|
"strsim 0.11.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -286,9 +291,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "colorchoice"
|
name = "colorchoice"
|
||||||
version = "1.0.1"
|
version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422"
|
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "console"
|
name = "console"
|
||||||
|
|
@ -349,7 +354,7 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crunchy-cli"
|
name = "crunchy-cli"
|
||||||
version = "3.6.7"
|
version = "3.5.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
|
|
@ -362,7 +367,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crunchy-cli-core"
|
name = "crunchy-cli-core"
|
||||||
version = "3.6.7"
|
version = "3.5.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-speed-limit",
|
"async-speed-limit",
|
||||||
|
|
@ -376,6 +381,8 @@ dependencies = [
|
||||||
"fs2",
|
"fs2",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"http",
|
"http",
|
||||||
|
"image",
|
||||||
|
"image_hasher",
|
||||||
"indicatif",
|
"indicatif",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"log",
|
"log",
|
||||||
|
|
@ -383,16 +390,13 @@ dependencies = [
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"regex",
|
"regex",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rsubs-lib",
|
|
||||||
"rustls-native-certs",
|
"rustls-native-certs",
|
||||||
"rusty-chromaprint",
|
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_plain",
|
"serde_plain",
|
||||||
"shlex",
|
"shlex",
|
||||||
"sys-locale",
|
"sys-locale",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"time",
|
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
|
|
@ -400,9 +404,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crunchyroll-rs"
|
name = "crunchyroll-rs"
|
||||||
version = "0.11.4"
|
version = "0.10.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d6e38c223aecf65c9c9bec50764beea5dc70b6c97cd7f767bf6860f2fc8e0a07"
|
checksum = "ccd0a624f3f8ec3fb7af8d83b907142aaee1858579ab697f24f05d00736e5bb2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
|
@ -426,9 +430,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crunchyroll-rs-internal"
|
name = "crunchyroll-rs-internal"
|
||||||
version = "0.11.4"
|
version = "0.10.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "144a38040a21aaa456741a9f6749354527bb68ad3bb14210e0bbc40fbd95186c"
|
checksum = "85c3614a871ec25ab17425405b08aea3c5869597e2348302b922c2a077aa9c3a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"darling",
|
"darling",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
@ -447,9 +451,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "darling"
|
name = "darling"
|
||||||
version = "0.20.9"
|
version = "0.20.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "83b2eb4d90d12bdda5ed17de686c2acb4c57914f8f921b8da7e112b5a36f3fe1"
|
checksum = "54e36fcd13ed84ffdfda6f5be89b31287cbb80c439841fe69e04841435464391"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"darling_core",
|
"darling_core",
|
||||||
"darling_macro",
|
"darling_macro",
|
||||||
|
|
@ -457,23 +461,23 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "darling_core"
|
name = "darling_core"
|
||||||
version = "0.20.9"
|
version = "0.20.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "622687fe0bac72a04e5599029151f5796111b90f1baaa9b544d807a5e31cd120"
|
checksum = "9c2cf1c23a687a1feeb728783b993c4e1ad83d99f351801977dd809b48d0a70f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fnv",
|
"fnv",
|
||||||
"ident_case",
|
"ident_case",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"strsim",
|
"strsim 0.10.0",
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "darling_macro"
|
name = "darling_macro"
|
||||||
version = "0.20.9"
|
version = "0.20.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178"
|
checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"darling_core",
|
"darling_core",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
@ -482,13 +486,12 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dash-mpd"
|
name = "dash-mpd"
|
||||||
version = "0.16.3"
|
version = "0.16.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4618a5e165bf47b084963611bcf1d568c681f52d8a237e8862a0cd8c546ba255"
|
checksum = "79b4bdd5f1c0c7493d780c645f0bff5b9361e6408210fa88910adb181efca64c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.22.1",
|
"base64 0.22.0",
|
||||||
"base64-serde",
|
"base64-serde",
|
||||||
"bytes",
|
|
||||||
"chrono",
|
"chrono",
|
||||||
"fs-err",
|
"fs-err",
|
||||||
"iso8601",
|
"iso8601",
|
||||||
|
|
@ -561,9 +564,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "either"
|
name = "either"
|
||||||
version = "1.12.0"
|
version = "1.11.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b"
|
checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "encode_unicode"
|
name = "encode_unicode"
|
||||||
|
|
@ -588,9 +591,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "errno"
|
name = "errno"
|
||||||
version = "0.3.9"
|
version = "0.3.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba"
|
checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
|
|
@ -598,9 +601,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fastrand"
|
name = "fastrand"
|
||||||
version = "2.1.0"
|
version = "2.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a"
|
checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fnv"
|
name = "fnv"
|
||||||
|
|
@ -720,9 +723,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.15"
|
version = "0.2.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
|
checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
|
|
@ -739,15 +742,15 @@ checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "h2"
|
name = "h2"
|
||||||
version = "0.4.5"
|
version = "0.4.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fa82e28a107a8cc405f0839610bdc9b15f1e25ec7d696aa5cf173edbcb1486ab"
|
checksum = "816ec7294445779408f36fe57bc5b7fc1cf59664059096c65f905c1c61f58069"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atomic-waker",
|
|
||||||
"bytes",
|
"bytes",
|
||||||
"fnv",
|
"fnv",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-sink",
|
"futures-sink",
|
||||||
|
"futures-util",
|
||||||
"http",
|
"http",
|
||||||
"indexmap 2.2.6",
|
"indexmap 2.2.6",
|
||||||
"slab",
|
"slab",
|
||||||
|
|
@ -764,9 +767,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.14.5"
|
version = "0.14.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
|
|
@ -948,6 +951,32 @@ dependencies = [
|
||||||
"unicode-normalization",
|
"unicode-normalization",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "image"
|
||||||
|
version = "0.25.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fd54d660e773627692c524beaad361aca785a4f9f5730ce91f42aabe5bce3d11"
|
||||||
|
dependencies = [
|
||||||
|
"bytemuck",
|
||||||
|
"byteorder",
|
||||||
|
"num-traits",
|
||||||
|
"zune-core",
|
||||||
|
"zune-jpeg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "image_hasher"
|
||||||
|
version = "2.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9481465fe767d92494987319b0b447a5829edf57f09c52bf8639396abaaeaf78"
|
||||||
|
dependencies = [
|
||||||
|
"base64 0.22.0",
|
||||||
|
"image",
|
||||||
|
"rustdct",
|
||||||
|
"serde",
|
||||||
|
"transpose",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "1.9.3"
|
version = "1.9.3"
|
||||||
|
|
@ -966,7 +995,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
|
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"equivalent",
|
"equivalent",
|
||||||
"hashbrown 0.14.5",
|
"hashbrown 0.14.3",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -985,9 +1014,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "instant"
|
name = "instant"
|
||||||
version = "0.1.13"
|
version = "0.1.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222"
|
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
@ -998,12 +1027,6 @@ version = "2.9.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3"
|
checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "is_terminal_polyfill"
|
|
||||||
version = "1.70.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iso8601"
|
name = "iso8601"
|
||||||
version = "0.6.1"
|
version = "0.6.1"
|
||||||
|
|
@ -1049,9 +1072,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.155"
|
version = "0.2.153"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
|
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libredox"
|
name = "libredox"
|
||||||
|
|
@ -1065,9 +1088,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linux-raw-sys"
|
name = "linux-raw-sys"
|
||||||
version = "0.4.14"
|
version = "0.4.13"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
|
checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
|
|
@ -1105,9 +1128,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "miniz_oxide"
|
name = "miniz_oxide"
|
||||||
version = "0.7.3"
|
version = "0.7.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae"
|
checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"adler",
|
"adler",
|
||||||
]
|
]
|
||||||
|
|
@ -1125,8 +1148,8 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "native-tls"
|
name = "native-tls"
|
||||||
version = "0.2.12"
|
version = "0.2.11"
|
||||||
source = "git+https://github.com/crunchy-labs/rust-not-so-native-tls.git?rev=c7ac566#c7ac566559d441bbc3e5e5bd04fb7162c38d88b0"
|
source = "git+https://github.com/crunchy-labs/rust-not-so-native-tls.git?rev=fdba246#fdba246a79986607cbdf573733445498bb6da2a9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
|
|
@ -1163,9 +1186,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-complex"
|
name = "num-complex"
|
||||||
version = "0.4.6"
|
version = "0.4.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
|
checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"num-traits",
|
"num-traits",
|
||||||
]
|
]
|
||||||
|
|
@ -1187,9 +1210,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-traits"
|
name = "num-traits"
|
||||||
version = "0.2.19"
|
version = "0.2.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
@ -1259,9 +1282,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "openssl-src"
|
name = "openssl-src"
|
||||||
version = "300.3.0+3.3.0"
|
version = "300.2.3+3.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "eba8804a1c5765b18c4b3f907e6897ebabeedebc9830e1a0046c4a4cf44663e1"
|
checksum = "5cff92b6f71555b61bb9315f7c64da3ca43d87531622120fea0195fc761b4843"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
@ -1352,9 +1375,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.83"
|
version = "1.0.81"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0b33eb56c327dec362a9e55b3ad14f9d2f0904fb5a5b03b513ab5465399e9f43"
|
checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
@ -1394,15 +1417,6 @@ dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "realfft"
|
|
||||||
version = "3.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "953d9f7e5cdd80963547b456251296efc2626ed4e3cbf36c869d9564e0220571"
|
|
||||||
dependencies = [
|
|
||||||
"rustfft",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_users"
|
name = "redox_users"
|
||||||
version = "0.4.5"
|
version = "0.4.5"
|
||||||
|
|
@ -1449,7 +1463,7 @@ version = "0.12.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10"
|
checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.22.1",
|
"base64 0.22.0",
|
||||||
"bytes",
|
"bytes",
|
||||||
"cookie",
|
"cookie",
|
||||||
"cookie_store",
|
"cookie_store",
|
||||||
|
|
@ -1517,34 +1531,20 @@ version = "0.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316"
|
checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rsubs-lib"
|
|
||||||
version = "0.3.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8c9f50e3fbcbf1f0bd109954e2dd813d1715c7b4a92a7bf159a85dea49e9d863"
|
|
||||||
dependencies = [
|
|
||||||
"regex",
|
|
||||||
"serde",
|
|
||||||
"time",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rubato"
|
|
||||||
version = "0.14.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e6dd52e80cfc21894deadf554a5673002938ae4625f7a283e536f9cf7c17b0d5"
|
|
||||||
dependencies = [
|
|
||||||
"num-complex",
|
|
||||||
"num-integer",
|
|
||||||
"num-traits",
|
|
||||||
"realfft",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-demangle"
|
name = "rustc-demangle"
|
||||||
version = "0.1.24"
|
version = "0.1.23"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
|
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustdct"
|
||||||
|
version = "0.7.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8b61555105d6a9bf98797c063c362a1d24ed8ab0431655e38f1cf51e52089551"
|
||||||
|
dependencies = [
|
||||||
|
"rustfft",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustfft"
|
name = "rustfft"
|
||||||
|
|
@ -1607,42 +1607,32 @@ version = "2.1.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d"
|
checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.22.1",
|
"base64 0.22.0",
|
||||||
"rustls-pki-types",
|
"rustls-pki-types",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustls-pki-types"
|
name = "rustls-pki-types"
|
||||||
version = "1.7.0"
|
version = "1.4.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d"
|
checksum = "ecd36cc4259e3e4514335c4a138c6b43171a8d61d8f5c9348f9fc7529416f247"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustls-webpki"
|
name = "rustls-webpki"
|
||||||
version = "0.102.4"
|
version = "0.102.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e"
|
checksum = "f3bce581c0dd41bce533ce695a1437fa16a7ab5ac3ccfa99fe1a620a7885eabf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ring",
|
"ring",
|
||||||
"rustls-pki-types",
|
"rustls-pki-types",
|
||||||
"untrusted",
|
"untrusted",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rusty-chromaprint"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1755646867c36ecb391776deaa0b557a76d3badf20c142de7282630c34b20440"
|
|
||||||
dependencies = [
|
|
||||||
"rubato",
|
|
||||||
"rustfft",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
version = "1.0.18"
|
version = "1.0.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
|
checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "schannel"
|
name = "schannel"
|
||||||
|
|
@ -1655,11 +1645,11 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "security-framework"
|
name = "security-framework"
|
||||||
version = "2.11.0"
|
version = "2.10.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0"
|
checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.5.0",
|
"bitflags 1.3.2",
|
||||||
"core-foundation",
|
"core-foundation",
|
||||||
"core-foundation-sys",
|
"core-foundation-sys",
|
||||||
"libc",
|
"libc",
|
||||||
|
|
@ -1668,9 +1658,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "security-framework-sys"
|
name = "security-framework-sys"
|
||||||
version = "2.11.0"
|
version = "2.10.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7"
|
checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"core-foundation-sys",
|
"core-foundation-sys",
|
||||||
"libc",
|
"libc",
|
||||||
|
|
@ -1678,18 +1668,18 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.202"
|
version = "1.0.198"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395"
|
checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.202"
|
version = "1.0.198"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838"
|
checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
@ -1698,9 +1688,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.117"
|
version = "1.0.116"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3"
|
checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"ryu",
|
"ryu",
|
||||||
|
|
@ -1740,11 +1730,11 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_with"
|
name = "serde_with"
|
||||||
version = "3.8.1"
|
version = "3.7.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0ad483d2ab0149d5a5ebcd9972a3852711e0153d863bf5a5d0391d28883c4a20"
|
checksum = "ee80b0e361bbf88fd2f6e242ccd19cfda072cb0faa6ae694ecee08199938569a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.22.1",
|
"base64 0.21.7",
|
||||||
"chrono",
|
"chrono",
|
||||||
"hex",
|
"hex",
|
||||||
"indexmap 1.9.3",
|
"indexmap 1.9.3",
|
||||||
|
|
@ -1758,9 +1748,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_with_macros"
|
name = "serde_with_macros"
|
||||||
version = "3.8.1"
|
version = "3.7.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "65569b702f41443e8bc8bbb1c5779bd0450bbe723b56198980e80ec45780bce2"
|
checksum = "6561dc161a9224638a31d876ccdfefbc1df91d3f3a8342eddb35f055d48c7655"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"darling",
|
"darling",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
|
|
@ -1808,9 +1798,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "socket2"
|
name = "socket2"
|
||||||
version = "0.5.7"
|
version = "0.5.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c"
|
checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
|
|
@ -1828,6 +1818,12 @@ version = "0.2.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fe895eb47f22e2ddd4dabc02bce419d2e643c8e3b585c78158b349195bc24d82"
|
checksum = "fe895eb47f22e2ddd4dabc02bce419d2e643c8e3b585c78158b349195bc24d82"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "strsim"
|
name = "strsim"
|
||||||
version = "0.11.1"
|
version = "0.11.1"
|
||||||
|
|
@ -1842,9 +1838,9 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.65"
|
version = "2.0.60"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d2863d96a84c6439701d7a38f9de935ec562c8832cc55d1dde0f513b52fad106"
|
checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
@ -1901,18 +1897,18 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "1.0.61"
|
version = "1.0.59"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709"
|
checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"thiserror-impl",
|
"thiserror-impl",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror-impl"
|
name = "thiserror-impl"
|
||||||
version = "1.0.61"
|
version = "1.0.59"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533"
|
checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
@ -1967,9 +1963,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "1.38.0"
|
version = "1.37.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a"
|
checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace",
|
"backtrace",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
|
@ -1984,9 +1980,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-macros"
|
name = "tokio-macros"
|
||||||
version = "2.3.0"
|
version = "2.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a"
|
checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
@ -2028,15 +2024,16 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-util"
|
name = "tokio-util"
|
||||||
version = "0.7.11"
|
version = "0.7.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1"
|
checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-sink",
|
"futures-sink",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -2147,9 +2144,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-width"
|
name = "unicode-width"
|
||||||
version = "0.1.12"
|
version = "0.1.11"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6"
|
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "untrusted"
|
name = "untrusted"
|
||||||
|
|
@ -2504,3 +2501,18 @@ name = "zeroize"
|
||||||
version = "1.7.0"
|
version = "1.7.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d"
|
checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zune-core"
|
||||||
|
version = "0.4.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3f423a2c17029964870cfaabb1f13dfab7d092a62a29a89264f4d36990ca414a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zune-jpeg"
|
||||||
|
version = "0.4.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ec866b44a2a1fd6133d363f073ca1b179f438f99e7e5bfb1e33f7181facfe448"
|
||||||
|
dependencies = [
|
||||||
|
"zune-core",
|
||||||
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "crunchy-cli"
|
name = "crunchy-cli"
|
||||||
authors = ["Crunchy Labs Maintainers"]
|
authors = ["Crunchy Labs Maintainers"]
|
||||||
version = "3.6.7"
|
version = "3.5.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
|
|
@ -14,9 +14,9 @@ openssl-tls = ["dep:native-tls-crate", "native-tls-crate/openssl", "crunchy-cli-
|
||||||
openssl-tls-static = ["dep:native-tls-crate", "native-tls-crate/openssl", "crunchy-cli-core/openssl-tls-static"]
|
openssl-tls-static = ["dep:native-tls-crate", "native-tls-crate/openssl", "crunchy-cli-core/openssl-tls-static"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = { version = "1.38", features = ["macros", "rt-multi-thread", "time"], default-features = false }
|
tokio = { version = "1.37", features = ["macros", "rt-multi-thread", "time"], default-features = false }
|
||||||
|
|
||||||
native-tls-crate = { package = "native-tls", version = "0.2.12", optional = true }
|
native-tls-crate = { package = "native-tls", version = "0.2.11", optional = true }
|
||||||
|
|
||||||
crunchy-cli-core = { path = "./crunchy-cli-core" }
|
crunchy-cli-core = { path = "./crunchy-cli-core" }
|
||||||
|
|
||||||
|
|
@ -34,7 +34,7 @@ members = ["crunchy-cli-core"]
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
# fork of the `native-tls` crate which can use openssl as backend on every platform. this is done as `reqwest` only
|
# fork of the `native-tls` crate which can use openssl as backend on every platform. this is done as `reqwest` only
|
||||||
# supports `rustls` and `native-tls` as tls backend
|
# supports `rustls` and `native-tls` as tls backend
|
||||||
native-tls = { git = "https://github.com/crunchy-labs/rust-not-so-native-tls.git", rev = "c7ac566" }
|
native-tls = { git = "https://github.com/crunchy-labs/rust-not-so-native-tls.git", rev = "fdba246" }
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
strip = true
|
strip = true
|
||||||
|
|
|
||||||
41
README.md
41
README.md
|
|
@ -1,4 +1,6 @@
|
||||||
# This project has been sunset as Crunchyroll moved to a DRM-only system. See [#362](https://github.com/crunchy-labs/crunchy-cli/issues/362).
|
> ~~This project has been sunset as Crunchyroll moved to a DRM-only system. See [#362](https://github.com/crunchy-labs/crunchy-cli/issues/362).~~
|
||||||
|
>
|
||||||
|
> Well there is one endpoint which still has DRM-free streams, I guess I still have a bit time until (finally) everything is DRM-only.
|
||||||
|
|
||||||
# crunchy-cli
|
# crunchy-cli
|
||||||
|
|
||||||
|
|
@ -20,8 +22,8 @@
|
||||||
<a href="https://discord.gg/PXGPGpQxgk">
|
<a href="https://discord.gg/PXGPGpQxgk">
|
||||||
<img src="https://img.shields.io/discord/994882878125121596?label=discord&style=flat-square" alt="Discord">
|
<img src="https://img.shields.io/discord/994882878125121596?label=discord&style=flat-square" alt="Discord">
|
||||||
</a>
|
</a>
|
||||||
<a href="https://github.com/crunchy-labs/crunchy-cli/actions/workflows/build.yml">
|
<a href="https://github.com/crunchy-labs/crunchy-cli/actions/workflows/ci.yml">
|
||||||
<img src="https://img.shields.io/github/actions/workflow/status/crunchy-labs/crunchy-cli/build.yml?branch=master&style=flat-square" alt="Build">
|
<img src="https://img.shields.io/github/actions/workflow/status/crunchy-labs/crunchy-cli/ci.yml?branch=master&style=flat-square" alt="CI">
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
@ -460,7 +462,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
|
||||||
In the best case, when multiple audio & subtitle tracks are used, there is only one *video* track and all other languages can be stored as audio-only.
|
In the best case, when multiple audio & subtitle tracks are used, there is only one *video* track and all other languages can be stored as audio-only.
|
||||||
But, as said, this is not always the case.
|
But, as said, this is not always the case.
|
||||||
With the `-m` / `--merge` flag you can define the behaviour when an episodes' video tracks differ in length.
|
With the `-m` / `--merge` flag you can define the behaviour when an episodes' video tracks differ in length.
|
||||||
Valid options are `audio` - store one video and all other languages as audio only; `video` - store the video + audio for every language; `auto` - detect if videos differ in length: if so, behave like `video` - otherwise like `audio`; `sync` - detect if videos differ in length: if so, it tries to find the offset of matching audio parts and removes the offset from the beginning, otherwise it behaves like `audio`.
|
Valid options are `audio` - store one video and all other languages as audio only; `video` - store the video + audio for every language; `auto` - detect if videos differ in length: if so, behave like `video` - otherwise like `audio`.
|
||||||
Subtitles will always match the primary audio and video.
|
Subtitles will always match the primary audio and video.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
|
@ -469,37 +471,26 @@ The `archive` command lets you download episodes with multiple audios and subtit
|
||||||
|
|
||||||
Default is `auto`.
|
Default is `auto`.
|
||||||
|
|
||||||
- <span id="archive-merge-time-tolerance">Merge time tolerance</span>
|
- <span id="archive-merge-auto-tolerance">Merge auto tolerance</span>
|
||||||
|
|
||||||
Sometimes two video tracks are downloaded with `--merge` set to `auto` even if they only differ some milliseconds in length which shouldn't be noticeable to the viewer.
|
Sometimes two video tracks are downloaded with `--merge` set to `auto` even if they only differ some milliseconds in length which shouldn't be noticeable to the viewer.
|
||||||
To prevent this, you can specify a range in milliseconds with the `--merge-time-tolerance` flag that only downloads one video if the length difference is in the given range.
|
To prevent this, you can specify a range in milliseconds with the `--merge-auto-tolerance` flag that only downloads one video if the length difference is in the given range.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ crunchy-cli archive -m auto --merge-time-tolerance 100 https://www.crunchyroll.com/series/GY8VEQ95Y/darling-in-the-franxx
|
$ crunchy-cli archive -m auto --merge-auto-tolerance 100 https://www.crunchyroll.com/series/GY8VEQ95Y/darling-in-the-franxx
|
||||||
```
|
```
|
||||||
|
|
||||||
Default are `200` milliseconds.
|
Default are `200` milliseconds.
|
||||||
|
|
||||||
- <span id="archive-merge-sync-tolerance">Merge sync tolerance</span>
|
- <span id="archive-sync-start">Sync start</span>
|
||||||
|
|
||||||
Sometimes two video tracks are downloaded with `--merge` set to `sync` because the audio fingerprinting fails to identify matching audio parts (e.g. opening).
|
If you want that all videos of the same episode should start at the same time and `--merge` doesn't fit your needs (e.g. one video has an intro, all other doesn't), you might consider using the `--sync-start`.
|
||||||
To prevent this, you can use the `--merge-sync-tolerance` flag to specify the difference by which two fingerprints are considered equal.
|
It tries to sync the timing of all downloaded audios to match one video.
|
||||||
|
This is done by downloading the first few segments/frames of all video tracks that differ in length and comparing them frame by frame.
|
||||||
|
The flag takes an optional value determines how accurate the syncing is, generally speaking everything over 15 begins to be more inaccurate and everything below 6 is too accurate (and won't succeed).
|
||||||
|
When the syncing fails, the command is continued as if `--sync-start` wasn't provided for this episode.
|
||||||
|
|
||||||
```shell
|
Default is `7.5`.
|
||||||
$ crunchy-cli archive -m sync --merge-sync-tolerance 3 https://www.crunchyroll.com/watch/GRDQPM1ZY/alone-and-lonesome
|
|
||||||
```
|
|
||||||
|
|
||||||
Default is `6`.
|
|
||||||
|
|
||||||
- <span id="archive-merge-sync-precision">Merge sync precision</span>
|
|
||||||
|
|
||||||
If you use `--merge` set to `sync` and the syncing seems to be not accurate enough or takes to long, you can use the `--sync-precision` flag to specify the amount of offset determination runs from which the final offset is calculated.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
$ crunchy-cli archive -m sync --merge-sync-precision 3 https://www.crunchyroll.com/watch/GRDQPM1ZY/alone-and-lonesome
|
|
||||||
```
|
|
||||||
|
|
||||||
Default is `4`.
|
|
||||||
|
|
||||||
- <span id="archive-language-tagging">Language tagging</span>
|
- <span id="archive-language-tagging">Language tagging</span>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "crunchy-cli-core"
|
name = "crunchy-cli-core"
|
||||||
authors = ["Crunchy Labs Maintainers"]
|
authors = ["Crunchy Labs Maintainers"]
|
||||||
version = "3.6.7"
|
version = "3.5.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
|
|
@ -16,7 +16,7 @@ anyhow = "1.0"
|
||||||
async-speed-limit = "0.4"
|
async-speed-limit = "0.4"
|
||||||
clap = { version = "4.5", features = ["derive", "string"] }
|
clap = { version = "4.5", features = ["derive", "string"] }
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
crunchyroll-rs = { version = "0.11.4", features = ["experimental-stabilizations", "tower"] }
|
crunchyroll-rs = { version = "0.10.8", features = ["experimental-stabilizations", "tower"] }
|
||||||
ctrlc = "3.4"
|
ctrlc = "3.4"
|
||||||
dialoguer = { version = "0.11", default-features = false }
|
dialoguer = { version = "0.11", default-features = false }
|
||||||
dirs = "5.0"
|
dirs = "5.0"
|
||||||
|
|
@ -24,22 +24,21 @@ derive_setters = "0.1"
|
||||||
futures-util = { version = "0.3", features = ["io"] }
|
futures-util = { version = "0.3", features = ["io"] }
|
||||||
fs2 = "0.4"
|
fs2 = "0.4"
|
||||||
http = "1.1"
|
http = "1.1"
|
||||||
|
image = { version = "0.25", features = ["jpeg"], default-features = false }
|
||||||
|
image_hasher = "2.0"
|
||||||
indicatif = "0.17"
|
indicatif = "0.17"
|
||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
log = { version = "0.4", features = ["std"] }
|
log = { version = "0.4", features = ["std"] }
|
||||||
num_cpus = "1.16"
|
num_cpus = "1.16"
|
||||||
regex = "1.10"
|
regex = "1.10"
|
||||||
reqwest = { version = "0.12", features = ["socks", "stream"] }
|
reqwest = { version = "0.12", features = ["socks", "stream"] }
|
||||||
rsubs-lib = "~0.3.2"
|
|
||||||
rusty-chromaprint = "0.2"
|
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde_plain = "1.0"
|
serde_plain = "1.0"
|
||||||
shlex = "1.3"
|
shlex = "1.3"
|
||||||
sys-locale = "0.3"
|
sys-locale = "0.3"
|
||||||
tempfile = "3.10"
|
tempfile = "3.10"
|
||||||
time = "0.3"
|
tokio = { version = "1.37", features = ["io-util", "macros", "net", "rt-multi-thread", "time"] }
|
||||||
tokio = { version = "1.38", features = ["io-util", "macros", "net", "rt-multi-thread", "time"] }
|
|
||||||
tokio-util = "0.7"
|
tokio-util = "0.7"
|
||||||
tower-service = "0.3"
|
tower-service = "0.3"
|
||||||
rustls-native-certs = { version = "0.7", optional = true }
|
rustls-native-certs = { version = "0.7", optional = true }
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
println!(
|
println!(
|
||||||
"cargo:rustc-env=GIT_HASH={}",
|
"cargo:rustc-env=GIT_HASH={}",
|
||||||
std::env::var("CRUNCHY_CLI_GIT_HASH")
|
get_short_commit_hash()?.unwrap_or_default()
|
||||||
.or::<std::io::Error>(Ok(get_short_commit_hash()?.unwrap_or_default()))?
|
|
||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
"cargo:rustc-env=BUILD_DATE={}",
|
"cargo:rustc-env=BUILD_DATE={}",
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
|
use crate::archive::filter::ArchiveFilter;
|
||||||
use crate::utils::context::Context;
|
use crate::utils::context::Context;
|
||||||
use crate::utils::download::{
|
use crate::utils::download::{
|
||||||
DownloadBuilder, DownloadFormat, DownloadFormatMetadata, MergeBehavior,
|
DownloadBuilder, DownloadFormat, DownloadFormatMetadata, MergeBehavior,
|
||||||
};
|
};
|
||||||
use crate::utils::ffmpeg::FFmpegPreset;
|
use crate::utils::ffmpeg::FFmpegPreset;
|
||||||
use crate::utils::filter::{Filter, FilterMediaScope};
|
use crate::utils::filter::Filter;
|
||||||
use crate::utils::format::{Format, SingleFormat};
|
use crate::utils::format::{Format, SingleFormat};
|
||||||
use crate::utils::locale::{all_locale_in_locales, resolve_locales, LanguageTagging};
|
use crate::utils::locale::{all_locale_in_locales, resolve_locales, LanguageTagging};
|
||||||
use crate::utils::log::progress;
|
use crate::utils::log::progress;
|
||||||
|
|
@ -89,31 +90,32 @@ pub struct Archive {
|
||||||
pub(crate) resolution: Resolution,
|
pub(crate) resolution: Resolution,
|
||||||
|
|
||||||
#[arg(
|
#[arg(
|
||||||
help = "Sets the behavior of the stream merging. Valid behaviors are 'auto', 'sync', 'audio' and 'video'"
|
help = "Sets the behavior of the stream merging. Valid behaviors are 'auto', 'audio' and 'video'"
|
||||||
)]
|
)]
|
||||||
#[arg(
|
#[arg(
|
||||||
long_help = "Because of local restrictions (or other reasons) some episodes with different languages does not have the same length (e.g. when some scenes were cut out). \
|
long_help = "Because of local restrictions (or other reasons) some episodes with different languages does not have the same length (e.g. when some scenes were cut out). \
|
||||||
With this flag you can set the behavior when handling multiple language.
|
With this flag you can set the behavior when handling multiple language.
|
||||||
Valid options are 'audio' (stores one video and all other languages as audio only), 'video' (stores the video + audio for every language), 'auto' (detects if videos differ in length: if so, behave like 'video' else like 'audio') and 'sync' (detects if videos differ in length: if so, tries to find the offset of matching audio parts and removes it from the beginning, otherwise it behaves like 'audio')"
|
Valid options are 'audio' (stores one video and all other languages as audio only), 'video' (stores the video + audio for every language) and 'auto' (detects if videos differ in length: if so, behave like 'video' else like 'audio')"
|
||||||
)]
|
)]
|
||||||
#[arg(short, long, default_value = "auto")]
|
#[arg(short, long, default_value = "auto")]
|
||||||
#[arg(value_parser = MergeBehavior::parse)]
|
#[arg(value_parser = MergeBehavior::parse)]
|
||||||
pub(crate) merge: MergeBehavior,
|
pub(crate) merge: MergeBehavior,
|
||||||
#[arg(
|
#[arg(
|
||||||
help = "If the merge behavior is 'auto' or 'sync', consider videos to be of equal lengths if the difference in length is smaller than the specified milliseconds"
|
help = "If the merge behavior is 'auto', only download multiple video tracks if their length difference is higher than the given milliseconds"
|
||||||
)]
|
)]
|
||||||
#[arg(long, default_value_t = 200)]
|
#[arg(long, default_value_t = 200)]
|
||||||
pub(crate) merge_time_tolerance: u32,
|
pub(crate) merge_auto_tolerance: u32,
|
||||||
|
#[arg(help = "Tries to sync the timing of all downloaded audios to match one video")]
|
||||||
#[arg(
|
#[arg(
|
||||||
help = "If the merge behavior is 'sync', specify the difference by which two fingerprints are considered equal, higher values can help when the algorithm fails"
|
long_help = "Tries to sync the timing of all downloaded audios to match one video. \
|
||||||
|
This is done by downloading the first few segments/frames of all video tracks that differ in length and comparing them frame by frame. \
|
||||||
|
The value of this flag determines how accurate the syncing is, generally speaking everything over 15 begins to be more inaccurate and everything below 6 is too accurate (and won't succeed). \
|
||||||
|
If you want to provide a custom value to this flag, you have to set it with an equals (e.g. `--sync-start=10` instead of `--sync-start 10`). \
|
||||||
|
When the syncing fails, the command is continued as if `--sync-start` wasn't provided for this episode
|
||||||
|
"
|
||||||
)]
|
)]
|
||||||
#[arg(long, default_value_t = 6)]
|
#[arg(long, require_equals = true, num_args = 0..=1, default_missing_value = "7.5")]
|
||||||
pub(crate) merge_sync_tolerance: u32,
|
pub(crate) sync_start: Option<f64>,
|
||||||
#[arg(
|
|
||||||
help = "If the merge behavior is 'sync', specify the amount of offset determination runs from which the final offset is calculated, higher values will increase the time required but lead to more precise offsets"
|
|
||||||
)]
|
|
||||||
#[arg(long, default_value_t = 4)]
|
|
||||||
pub(crate) merge_sync_precision: u32,
|
|
||||||
|
|
||||||
#[arg(
|
#[arg(
|
||||||
help = "Specified which language tagging the audio and subtitle tracks and language specific format options should have. \
|
help = "Specified which language tagging the audio and subtitle tracks and language specific format options should have. \
|
||||||
|
|
@ -227,14 +229,18 @@ impl Execute for Archive {
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.include_chapters
|
if self.include_chapters
|
||||||
&& !matches!(self.merge, MergeBehavior::Sync)
|
|
||||||
&& !matches!(self.merge, MergeBehavior::Audio)
|
&& !matches!(self.merge, MergeBehavior::Audio)
|
||||||
|
&& self.sync_start.is_none()
|
||||||
{
|
{
|
||||||
bail!("`--include-chapters` can only be used if `--merge` is set to 'audio' or 'sync'")
|
bail!("`--include-chapters` can only be used if `--merge` is set to 'audio' or `--sync-start` is set")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.skip_existing_method.is_empty() && !self.skip_existing {
|
if !matches!(self.merge, MergeBehavior::Auto) && self.sync_start.is_some() {
|
||||||
warn!("`--skip-existing-method` has no effect if `--skip-existing` is not set")
|
bail!("`--sync-start` can only be used if `--merge` is set to `auto`")
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.sync_start.is_some() && self.ffmpeg_preset.is_none() {
|
||||||
|
warn!("Using `--sync-start` without `--ffmpeg-preset` might produce worse sync results than with `--ffmpeg-preset` set")
|
||||||
}
|
}
|
||||||
|
|
||||||
self.audio = all_locale_in_locales(self.audio.clone());
|
self.audio = all_locale_in_locales(self.audio.clone());
|
||||||
|
|
@ -283,49 +289,9 @@ impl Execute for Archive {
|
||||||
|
|
||||||
for (i, (media_collection, url_filter)) in parsed_urls.into_iter().enumerate() {
|
for (i, (media_collection, url_filter)) in parsed_urls.into_iter().enumerate() {
|
||||||
let progress_handler = progress!("Fetching series details");
|
let progress_handler = progress!("Fetching series details");
|
||||||
let single_format_collection = Filter::new(
|
let single_format_collection = ArchiveFilter::new(
|
||||||
url_filter,
|
url_filter,
|
||||||
self.audio.clone(),
|
self.clone(),
|
||||||
self.subtitle.clone(),
|
|
||||||
|scope, locales| {
|
|
||||||
let audios = locales.into_iter().map(|l| l.to_string()).collect::<Vec<String>>().join(", ");
|
|
||||||
match scope {
|
|
||||||
FilterMediaScope::Series(series) => warn!("Series {} is not available with {} audio", series.title, audios),
|
|
||||||
FilterMediaScope::Season(season) => warn!("Season {} is not available with {} audio", season.season_number, audios),
|
|
||||||
FilterMediaScope::Episode(episodes) => {
|
|
||||||
if episodes.len() == 1 {
|
|
||||||
warn!("Episode {} is not available with {} audio", episodes[0].sequence_number, audios)
|
|
||||||
} else if episodes.len() == 2 {
|
|
||||||
warn!("Season {} is only available with {} audio from episode {} to {}", episodes[0].season_number, audios, episodes[0].sequence_number, episodes[1].sequence_number)
|
|
||||||
} else {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(true)
|
|
||||||
},
|
|
||||||
|scope, locales| {
|
|
||||||
let subtitles = locales.into_iter().map(|l| l.to_string()).collect::<Vec<String>>().join(", ");
|
|
||||||
match scope {
|
|
||||||
FilterMediaScope::Series(series) => warn!("Series {} is not available with {} subtitles", series.title, subtitles),
|
|
||||||
FilterMediaScope::Season(season) => warn!("Season {} is not available with {} subtitles", season.season_number, subtitles),
|
|
||||||
FilterMediaScope::Episode(episodes) => {
|
|
||||||
if episodes.len() == 1 {
|
|
||||||
warn!("Episode {} of season {} is not available with {} subtitles", episodes[0].sequence_number, episodes[0].season_title, subtitles)
|
|
||||||
} else if episodes.len() == 2 {
|
|
||||||
warn!("Season {} of season {} is only available with {} subtitles from episode {} to {}", episodes[0].season_number, episodes[0].season_title, subtitles, episodes[0].sequence_number, episodes[1].sequence_number)
|
|
||||||
} else {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(true)
|
|
||||||
},
|
|
||||||
|season| {
|
|
||||||
warn!("Skipping premium episodes in season {season}");
|
|
||||||
Ok(())
|
|
||||||
},
|
|
||||||
Format::has_relative_fmt(&self.output),
|
|
||||||
!self.yes,
|
!self.yes,
|
||||||
self.skip_specials,
|
self.skip_specials,
|
||||||
ctx.crunchy.premium().await,
|
ctx.crunchy.premium().await,
|
||||||
|
|
@ -351,14 +317,7 @@ impl Execute for Archive {
|
||||||
.audio_sort(Some(self.audio.clone()))
|
.audio_sort(Some(self.audio.clone()))
|
||||||
.subtitle_sort(Some(self.subtitle.clone()))
|
.subtitle_sort(Some(self.subtitle.clone()))
|
||||||
.no_closed_caption(self.no_closed_caption)
|
.no_closed_caption(self.no_closed_caption)
|
||||||
.merge_sync_tolerance(match self.merge {
|
.sync_start_value(self.sync_start)
|
||||||
MergeBehavior::Sync => Some(self.merge_sync_tolerance),
|
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
.merge_sync_precision(match self.merge {
|
|
||||||
MergeBehavior::Sync => Some(self.merge_sync_precision),
|
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
.threads(self.threads)
|
.threads(self.threads)
|
||||||
.audio_locale_output_map(
|
.audio_locale_output_map(
|
||||||
zip(self.audio.clone(), self.output_audio_locales.clone()).collect(),
|
zip(self.audio.clone(), self.output_audio_locales.clone()).collect(),
|
||||||
|
|
@ -436,7 +395,7 @@ impl Execute for Archive {
|
||||||
|| (method_subtitle && subtitle_differ)
|
|| (method_subtitle && subtitle_differ)
|
||||||
{
|
{
|
||||||
skip = false;
|
skip = false;
|
||||||
path.clone_from(&formatted_path)
|
path = formatted_path.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -540,28 +499,29 @@ async fn get_format(
|
||||||
.subtitle
|
.subtitle
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|s| {
|
.flat_map(|s| {
|
||||||
let mut subtitles = vec![];
|
let subtitles = stream
|
||||||
if let Some(caption) = stream.captions.get(s) {
|
.subtitles
|
||||||
subtitles.push((caption.clone(), true))
|
.get(s)
|
||||||
}
|
.cloned()
|
||||||
if let Some(subtitle) = stream.subtitles.get(s) {
|
// the subtitle is probably not cc if the audio is japanese or more than one
|
||||||
// the subtitle is probably cc if the audio is not japanese or only one subtitle
|
// subtitle exists for this stream
|
||||||
// exists for this stream
|
.map(|l| {
|
||||||
let cc = single_format.audio != Locale::ja_JP && stream.subtitles.len() == 1;
|
(
|
||||||
// only include the subtitles if no cc subtitle is already present or if it's
|
l,
|
||||||
// not cc
|
single_format.audio == Locale::ja_JP || stream.subtitles.len() > 1,
|
||||||
if subtitles.is_empty() || !cc {
|
)
|
||||||
subtitles.push((subtitle.clone(), cc))
|
});
|
||||||
}
|
let cc = stream.captions.get(s).cloned().map(|l| (l, false));
|
||||||
}
|
|
||||||
subtitles
|
subtitles
|
||||||
|
.into_iter()
|
||||||
|
.chain(cc.into_iter())
|
||||||
|
.collect::<Vec<(Subtitle, bool)>>()
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
format_pairs.push((single_format, video.clone(), audio, subtitles.clone()));
|
format_pairs.push((single_format, video.clone(), audio, subtitles.clone()));
|
||||||
single_format_to_format_pairs.push((single_format.clone(), video, subtitles));
|
single_format_to_format_pairs.push((single_format.clone(), video, subtitles))
|
||||||
|
|
||||||
stream.invalidate().await?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut download_formats = vec![];
|
let mut download_formats = vec![];
|
||||||
|
|
@ -600,7 +560,7 @@ async fn get_format(
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
MergeBehavior::Auto | MergeBehavior::Sync => {
|
MergeBehavior::Auto => {
|
||||||
let mut d_formats: Vec<(Duration, DownloadFormat)> = vec![];
|
let mut d_formats: Vec<(Duration, DownloadFormat)> = vec![];
|
||||||
|
|
||||||
for (single_format, video, audio, subtitles) in format_pairs {
|
for (single_format, video, audio, subtitles) in format_pairs {
|
||||||
|
|
@ -617,7 +577,7 @@ async fn get_format(
|
||||||
.sub(single_format.duration)
|
.sub(single_format.duration)
|
||||||
.abs()
|
.abs()
|
||||||
.num_milliseconds()
|
.num_milliseconds()
|
||||||
< archive.merge_time_tolerance.into() =>
|
< archive.merge_auto_tolerance.into() =>
|
||||||
{
|
{
|
||||||
// If less than `audio_error` apart, use same audio.
|
// If less than `audio_error` apart, use same audio.
|
||||||
closest_format
|
closest_format
|
||||||
|
|
|
||||||
466
crunchy-cli-core/src/archive/filter.rs
Normal file
466
crunchy-cli-core/src/archive/filter.rs
Normal file
|
|
@ -0,0 +1,466 @@
|
||||||
|
use crate::archive::command::Archive;
|
||||||
|
use crate::utils::filter::{real_dedup_vec, Filter};
|
||||||
|
use crate::utils::format::{Format, SingleFormat, SingleFormatCollection};
|
||||||
|
use crate::utils::interactive_select::{check_for_duplicated_seasons, get_duplicated_seasons};
|
||||||
|
use crate::utils::parse::{fract, UrlFilter};
|
||||||
|
use anyhow::Result;
|
||||||
|
use crunchyroll_rs::{Concert, Episode, Locale, Movie, MovieListing, MusicVideo, Season, Series};
|
||||||
|
use log::{info, warn};
|
||||||
|
use std::collections::{BTreeMap, HashMap};
|
||||||
|
use std::ops::Not;
|
||||||
|
|
||||||
|
enum Visited {
|
||||||
|
Series,
|
||||||
|
Season,
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) struct ArchiveFilter {
|
||||||
|
url_filter: UrlFilter,
|
||||||
|
archive: Archive,
|
||||||
|
interactive_input: bool,
|
||||||
|
skip_special: bool,
|
||||||
|
season_episodes: HashMap<String, Vec<Episode>>,
|
||||||
|
season_subtitles_missing: Vec<u32>,
|
||||||
|
seasons_with_premium: Option<Vec<u32>>,
|
||||||
|
season_sorting: Vec<String>,
|
||||||
|
visited: Visited,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ArchiveFilter {
|
||||||
|
pub(crate) fn new(
|
||||||
|
url_filter: UrlFilter,
|
||||||
|
archive: Archive,
|
||||||
|
interactive_input: bool,
|
||||||
|
skip_special: bool,
|
||||||
|
is_premium: bool,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
url_filter,
|
||||||
|
archive,
|
||||||
|
interactive_input,
|
||||||
|
skip_special,
|
||||||
|
season_episodes: HashMap::new(),
|
||||||
|
season_subtitles_missing: vec![],
|
||||||
|
seasons_with_premium: is_premium.not().then_some(vec![]),
|
||||||
|
season_sorting: vec![],
|
||||||
|
visited: Visited::None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Filter for ArchiveFilter {
|
||||||
|
type T = Vec<SingleFormat>;
|
||||||
|
type Output = SingleFormatCollection;
|
||||||
|
|
||||||
|
async fn visit_series(&mut self, series: Series) -> Result<Vec<Season>> {
|
||||||
|
// `series.audio_locales` isn't always populated b/c of crunchyrolls api. so check if the
|
||||||
|
// audio is matching only if the field is populated
|
||||||
|
if !series.audio_locales.is_empty() {
|
||||||
|
let missing_audio = missing_locales(&series.audio_locales, &self.archive.audio);
|
||||||
|
if !missing_audio.is_empty() {
|
||||||
|
warn!(
|
||||||
|
"Series {} is not available with {} audio",
|
||||||
|
series.title,
|
||||||
|
missing_audio
|
||||||
|
.into_iter()
|
||||||
|
.map(|l| l.to_string())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join(", ")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
let missing_subtitle =
|
||||||
|
missing_locales(&series.subtitle_locales, &self.archive.subtitle);
|
||||||
|
if !missing_subtitle.is_empty() {
|
||||||
|
warn!(
|
||||||
|
"Series {} is not available with {} subtitles",
|
||||||
|
series.title,
|
||||||
|
missing_subtitle
|
||||||
|
.into_iter()
|
||||||
|
.map(|l| l.to_string())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join(", ")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
self.visited = Visited::Series
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut seasons = series.seasons().await?;
|
||||||
|
let mut remove_ids = vec![];
|
||||||
|
for season in seasons.iter_mut() {
|
||||||
|
if !self.url_filter.is_season_valid(season.season_number)
|
||||||
|
|| (!season
|
||||||
|
.audio_locales
|
||||||
|
.iter()
|
||||||
|
.any(|l| self.archive.audio.contains(l))
|
||||||
|
&& !season
|
||||||
|
.available_versions()
|
||||||
|
.await?
|
||||||
|
.iter()
|
||||||
|
.any(|l| self.archive.audio.contains(l)))
|
||||||
|
{
|
||||||
|
remove_ids.push(season.id.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
seasons.retain(|s| !remove_ids.contains(&s.id));
|
||||||
|
|
||||||
|
let duplicated_seasons = get_duplicated_seasons(&seasons);
|
||||||
|
if !duplicated_seasons.is_empty() {
|
||||||
|
if self.interactive_input {
|
||||||
|
check_for_duplicated_seasons(&mut seasons);
|
||||||
|
} else {
|
||||||
|
info!(
|
||||||
|
"Found duplicated seasons: {}",
|
||||||
|
duplicated_seasons
|
||||||
|
.iter()
|
||||||
|
.map(|d| d.to_string())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join(", ")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(seasons)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn visit_season(&mut self, mut season: Season) -> Result<Vec<Episode>> {
|
||||||
|
if !self.url_filter.is_season_valid(season.season_number) {
|
||||||
|
return Ok(vec![]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut seasons = season.version(self.archive.audio.clone()).await?;
|
||||||
|
if self
|
||||||
|
.archive
|
||||||
|
.audio
|
||||||
|
.iter()
|
||||||
|
.any(|l| season.audio_locales.contains(l))
|
||||||
|
{
|
||||||
|
seasons.insert(0, season.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matches!(self.visited, Visited::Series) {
|
||||||
|
let mut audio_locales: Vec<Locale> = seasons
|
||||||
|
.iter()
|
||||||
|
.flat_map(|s| s.audio_locales.clone())
|
||||||
|
.collect();
|
||||||
|
real_dedup_vec(&mut audio_locales);
|
||||||
|
let missing_audio = missing_locales(&audio_locales, &self.archive.audio);
|
||||||
|
if !missing_audio.is_empty() {
|
||||||
|
warn!(
|
||||||
|
"Season {} is not available with {} audio",
|
||||||
|
season.season_number,
|
||||||
|
missing_audio
|
||||||
|
.into_iter()
|
||||||
|
.map(|l| l.to_string())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join(", ")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let subtitle_locales: Vec<Locale> = seasons
|
||||||
|
.iter()
|
||||||
|
.flat_map(|s| s.subtitle_locales.clone())
|
||||||
|
.collect();
|
||||||
|
let missing_subtitle = missing_locales(&subtitle_locales, &self.archive.subtitle);
|
||||||
|
if !missing_subtitle.is_empty() {
|
||||||
|
warn!(
|
||||||
|
"Season {} is not available with {} subtitles",
|
||||||
|
season.season_number,
|
||||||
|
missing_subtitle
|
||||||
|
.into_iter()
|
||||||
|
.map(|l| l.to_string())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join(", ")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
self.visited = Visited::Season
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut episodes = vec![];
|
||||||
|
for season in seasons {
|
||||||
|
self.season_sorting.push(season.id.clone());
|
||||||
|
let season_locale = if season.audio_locales.len() < 2 {
|
||||||
|
Some(
|
||||||
|
season
|
||||||
|
.audio_locales
|
||||||
|
.first()
|
||||||
|
.cloned()
|
||||||
|
.unwrap_or(Locale::ja_JP),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let mut eps = season.episodes().await?;
|
||||||
|
let before_len = eps.len();
|
||||||
|
|
||||||
|
for mut ep in eps.clone() {
|
||||||
|
if let Some(l) = &season_locale {
|
||||||
|
if &ep.audio_locale == l {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
eps.remove(eps.iter().position(|p| p.id == ep.id).unwrap());
|
||||||
|
} else {
|
||||||
|
let mut requested_locales = self.archive.audio.clone();
|
||||||
|
if let Some(idx) = requested_locales.iter().position(|p| p == &ep.audio_locale)
|
||||||
|
{
|
||||||
|
requested_locales.remove(idx);
|
||||||
|
} else {
|
||||||
|
eps.remove(eps.iter().position(|p| p.id == ep.id).unwrap());
|
||||||
|
}
|
||||||
|
eps.extend(ep.version(self.archive.audio.clone()).await?);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if eps.len() < before_len {
|
||||||
|
if eps.is_empty() {
|
||||||
|
if matches!(self.visited, Visited::Series) {
|
||||||
|
warn!(
|
||||||
|
"Season {} is not available with {} audio",
|
||||||
|
season.season_number,
|
||||||
|
season_locale.unwrap_or(Locale::ja_JP)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let last_episode = eps.last().unwrap();
|
||||||
|
warn!(
|
||||||
|
"Season {} is only available with {} audio until episode {} ({})",
|
||||||
|
season.season_number,
|
||||||
|
season_locale.unwrap_or(Locale::ja_JP),
|
||||||
|
last_episode.sequence_number,
|
||||||
|
last_episode.title
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
episodes.extend(eps)
|
||||||
|
}
|
||||||
|
|
||||||
|
if Format::has_relative_fmt(&self.archive.output) {
|
||||||
|
for episode in episodes.iter() {
|
||||||
|
self.season_episodes
|
||||||
|
.entry(episode.season_id.clone())
|
||||||
|
.or_default()
|
||||||
|
.push(episode.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(episodes)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn visit_episode(&mut self, mut episode: Episode) -> Result<Option<Self::T>> {
|
||||||
|
if !self
|
||||||
|
.url_filter
|
||||||
|
.is_episode_valid(episode.sequence_number, episode.season_number)
|
||||||
|
{
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
|
// skip the episode if it's a special
|
||||||
|
if self.skip_special
|
||||||
|
&& (episode.sequence_number == 0.0 || episode.sequence_number.fract() != 0.0)
|
||||||
|
{
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut episodes = vec![];
|
||||||
|
if !matches!(self.visited, Visited::Series) && !matches!(self.visited, Visited::Season) {
|
||||||
|
if self.archive.audio.contains(&episode.audio_locale) {
|
||||||
|
episodes.push((episode.clone(), episode.subtitle_locales.clone()))
|
||||||
|
}
|
||||||
|
episodes.extend(
|
||||||
|
episode
|
||||||
|
.version(self.archive.audio.clone())
|
||||||
|
.await?
|
||||||
|
.into_iter()
|
||||||
|
.map(|e| (e.clone(), e.subtitle_locales.clone())),
|
||||||
|
);
|
||||||
|
let audio_locales: Vec<Locale> = episodes
|
||||||
|
.iter()
|
||||||
|
.map(|(e, _)| e.audio_locale.clone())
|
||||||
|
.collect();
|
||||||
|
let missing_audio = missing_locales(&audio_locales, &self.archive.audio);
|
||||||
|
if !missing_audio.is_empty() {
|
||||||
|
warn!(
|
||||||
|
"Episode {} is not available with {} audio",
|
||||||
|
episode.sequence_number,
|
||||||
|
missing_audio
|
||||||
|
.into_iter()
|
||||||
|
.map(|l| l.to_string())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join(", ")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut subtitle_locales: Vec<Locale> =
|
||||||
|
episodes.iter().flat_map(|(_, s)| s.clone()).collect();
|
||||||
|
real_dedup_vec(&mut subtitle_locales);
|
||||||
|
let missing_subtitles = missing_locales(&subtitle_locales, &self.archive.subtitle);
|
||||||
|
if !missing_subtitles.is_empty()
|
||||||
|
&& !self
|
||||||
|
.season_subtitles_missing
|
||||||
|
.contains(&episode.season_number)
|
||||||
|
{
|
||||||
|
warn!(
|
||||||
|
"Episode {} is not available with {} subtitles",
|
||||||
|
episode.sequence_number,
|
||||||
|
missing_subtitles
|
||||||
|
.into_iter()
|
||||||
|
.map(|l| l.to_string())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join(", ")
|
||||||
|
);
|
||||||
|
self.season_subtitles_missing.push(episode.season_number)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
episodes.push((episode.clone(), episode.subtitle_locales.clone()))
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.seasons_with_premium.is_some() {
|
||||||
|
let episode_len_before = episodes.len();
|
||||||
|
episodes.retain(|(e, _)| !e.is_premium_only);
|
||||||
|
if episode_len_before < episodes.len()
|
||||||
|
&& !self
|
||||||
|
.seasons_with_premium
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.contains(&episode.season_number)
|
||||||
|
{
|
||||||
|
warn!(
|
||||||
|
"Skipping premium episodes in season {}",
|
||||||
|
episode.season_number
|
||||||
|
);
|
||||||
|
self.seasons_with_premium
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.push(episode.season_number)
|
||||||
|
}
|
||||||
|
|
||||||
|
if episodes.is_empty() {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut relative_episode_number = None;
|
||||||
|
let mut relative_sequence_number = None;
|
||||||
|
// get the relative episode number. only done if the output string has the pattern to include
|
||||||
|
// the relative episode number as this requires some extra fetching
|
||||||
|
if Format::has_relative_fmt(&self.archive.output) {
|
||||||
|
let season_eps = match self.season_episodes.get(&episode.season_id) {
|
||||||
|
Some(eps) => eps,
|
||||||
|
None => {
|
||||||
|
self.season_episodes.insert(
|
||||||
|
episode.season_id.clone(),
|
||||||
|
episode.season().await?.episodes().await?,
|
||||||
|
);
|
||||||
|
self.season_episodes.get(&episode.season_id).unwrap()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let mut non_integer_sequence_number_count = 0;
|
||||||
|
for (i, ep) in season_eps.iter().enumerate() {
|
||||||
|
if ep.sequence_number.fract() != 0.0 || ep.sequence_number == 0.0 {
|
||||||
|
non_integer_sequence_number_count += 1;
|
||||||
|
}
|
||||||
|
if ep.id == episode.id {
|
||||||
|
relative_episode_number = Some(i + 1);
|
||||||
|
relative_sequence_number = Some(
|
||||||
|
(i + 1 - non_integer_sequence_number_count) as f32
|
||||||
|
+ fract(ep.sequence_number),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if relative_episode_number.is_none() || relative_sequence_number.is_none() {
|
||||||
|
warn!(
|
||||||
|
"Failed to get relative episode number for episode {} ({}) of {} season {}",
|
||||||
|
episode.sequence_number,
|
||||||
|
episode.title,
|
||||||
|
episode.series_title,
|
||||||
|
episode.season_number,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Some(
|
||||||
|
episodes
|
||||||
|
.into_iter()
|
||||||
|
.map(|(e, s)| {
|
||||||
|
SingleFormat::new_from_episode(
|
||||||
|
e,
|
||||||
|
s,
|
||||||
|
relative_episode_number.map(|n| n as u32),
|
||||||
|
relative_sequence_number,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn visit_movie_listing(&mut self, movie_listing: MovieListing) -> Result<Vec<Movie>> {
|
||||||
|
Ok(movie_listing.movies().await?)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn visit_movie(&mut self, movie: Movie) -> Result<Option<Self::T>> {
|
||||||
|
Ok(Some(vec![SingleFormat::new_from_movie(movie, vec![])]))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn visit_music_video(&mut self, music_video: MusicVideo) -> Result<Option<Self::T>> {
|
||||||
|
Ok(Some(vec![SingleFormat::new_from_music_video(music_video)]))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn visit_concert(&mut self, concert: Concert) -> Result<Option<Self::T>> {
|
||||||
|
Ok(Some(vec![SingleFormat::new_from_concert(concert)]))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn finish(self, input: Vec<Self::T>) -> Result<Self::Output> {
|
||||||
|
let flatten_input: Self::T = input.into_iter().flatten().collect();
|
||||||
|
|
||||||
|
let mut single_format_collection = SingleFormatCollection::new();
|
||||||
|
|
||||||
|
let mut pre_sorted: BTreeMap<String, Self::T> = BTreeMap::new();
|
||||||
|
for data in flatten_input {
|
||||||
|
pre_sorted
|
||||||
|
.entry(data.identifier.clone())
|
||||||
|
.or_insert(vec![])
|
||||||
|
.push(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut sorted: Vec<(String, Self::T)> = pre_sorted.into_iter().collect();
|
||||||
|
sorted.sort_by(|(_, a), (_, b)| {
|
||||||
|
self.season_sorting
|
||||||
|
.iter()
|
||||||
|
.position(|p| p == &a.first().unwrap().season_id)
|
||||||
|
.unwrap()
|
||||||
|
.cmp(
|
||||||
|
&self
|
||||||
|
.season_sorting
|
||||||
|
.iter()
|
||||||
|
.position(|p| p == &b.first().unwrap().season_id)
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
for (_, mut data) in sorted {
|
||||||
|
data.sort_by(|a, b| {
|
||||||
|
self.archive
|
||||||
|
.audio
|
||||||
|
.iter()
|
||||||
|
.position(|p| p == &a.audio)
|
||||||
|
.unwrap_or(usize::MAX)
|
||||||
|
.cmp(
|
||||||
|
&self
|
||||||
|
.archive
|
||||||
|
.audio
|
||||||
|
.iter()
|
||||||
|
.position(|p| p == &b.audio)
|
||||||
|
.unwrap_or(usize::MAX),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
single_format_collection.add_single_formats(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(single_format_collection)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn missing_locales<'a>(available: &[Locale], searched: &'a [Locale]) -> Vec<&'a Locale> {
|
||||||
|
searched.iter().filter(|p| !available.contains(p)).collect()
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
mod command;
|
mod command;
|
||||||
|
mod filter;
|
||||||
|
|
||||||
pub use command::Archive;
|
pub use command::Archive;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
|
use crate::download::filter::DownloadFilter;
|
||||||
use crate::utils::context::Context;
|
use crate::utils::context::Context;
|
||||||
use crate::utils::download::{DownloadBuilder, DownloadFormat, DownloadFormatMetadata};
|
use crate::utils::download::{DownloadBuilder, DownloadFormat, DownloadFormatMetadata};
|
||||||
use crate::utils::ffmpeg::{FFmpegPreset, SOFTSUB_CONTAINERS};
|
use crate::utils::ffmpeg::{FFmpegPreset, SOFTSUB_CONTAINERS};
|
||||||
use crate::utils::filter::{Filter, FilterMediaScope};
|
use crate::utils::filter::Filter;
|
||||||
use crate::utils::format::{Format, SingleFormat};
|
use crate::utils::format::{Format, SingleFormat};
|
||||||
use crate::utils::locale::{resolve_locales, LanguageTagging};
|
use crate::utils::locale::{resolve_locales, LanguageTagging};
|
||||||
use crate::utils::log::progress;
|
use crate::utils::log::progress;
|
||||||
|
|
@ -13,7 +14,7 @@ use anyhow::bail;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use crunchyroll_rs::media::Resolution;
|
use crunchyroll_rs::media::Resolution;
|
||||||
use crunchyroll_rs::Locale;
|
use crunchyroll_rs::Locale;
|
||||||
use log::{debug, error, warn};
|
use log::{debug, warn};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
|
@ -249,53 +250,9 @@ impl Execute for Download {
|
||||||
|
|
||||||
for (i, (media_collection, url_filter)) in parsed_urls.into_iter().enumerate() {
|
for (i, (media_collection, url_filter)) in parsed_urls.into_iter().enumerate() {
|
||||||
let progress_handler = progress!("Fetching series details");
|
let progress_handler = progress!("Fetching series details");
|
||||||
let single_format_collection = Filter::new(
|
let single_format_collection = DownloadFilter::new(
|
||||||
url_filter,
|
url_filter,
|
||||||
vec![self.audio.clone()],
|
self.clone(),
|
||||||
self.subtitle.as_ref().map_or(vec![], |s| vec![s.clone()]),
|
|
||||||
|scope, locales| {
|
|
||||||
match scope {
|
|
||||||
FilterMediaScope::Series(series) => bail!("Series {} is not available with {} audio", series.title, locales[0]),
|
|
||||||
FilterMediaScope::Season(season) => {
|
|
||||||
error!("Season {} is not available with {} audio", season.season_number, locales[0]);
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
FilterMediaScope::Episode(episodes) => {
|
|
||||||
if episodes.len() == 1 {
|
|
||||||
warn!("Episode {} of season {} is not available with {} audio", episodes[0].sequence_number, episodes[0].season_title, locales[0])
|
|
||||||
} else if episodes.len() == 2 {
|
|
||||||
warn!("Season {} is only available with {} audio from episode {} to {}", episodes[0].season_number, locales[0], episodes[0].sequence_number, episodes[1].sequence_number)
|
|
||||||
} else {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|scope, locales| {
|
|
||||||
match scope {
|
|
||||||
FilterMediaScope::Series(series) => bail!("Series {} is not available with {} subtitles", series.title, locales[0]),
|
|
||||||
FilterMediaScope::Season(season) => {
|
|
||||||
warn!("Season {} is not available with {} subtitles", season.season_number, locales[0]);
|
|
||||||
Ok(false)
|
|
||||||
},
|
|
||||||
FilterMediaScope::Episode(episodes) => {
|
|
||||||
if episodes.len() == 1 {
|
|
||||||
warn!("Episode {} of season {} is not available with {} subtitles", episodes[0].sequence_number, episodes[0].season_title, locales[0])
|
|
||||||
} else if episodes.len() == 2 {
|
|
||||||
warn!("Season {} is only available with {} subtitles from episode {} to {}", episodes[0].season_number, locales[0], episodes[0].sequence_number, episodes[1].sequence_number)
|
|
||||||
} else {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|season| {
|
|
||||||
warn!("Skipping premium episodes in season {season}");
|
|
||||||
Ok(())
|
|
||||||
},
|
|
||||||
Format::has_relative_fmt(&self.output),
|
|
||||||
!self.yes,
|
!self.yes,
|
||||||
self.skip_specials,
|
self.skip_specials,
|
||||||
ctx.crunchy.premium().await,
|
ctx.crunchy.premium().await,
|
||||||
|
|
@ -427,20 +384,12 @@ async fn get_format(
|
||||||
let subtitle = if contains_hardsub {
|
let subtitle = if contains_hardsub {
|
||||||
None
|
None
|
||||||
} else if let Some(subtitle_locale) = &download.subtitle {
|
} else if let Some(subtitle_locale) = &download.subtitle {
|
||||||
if download.audio == Locale::ja_JP {
|
stream
|
||||||
stream
|
.subtitles
|
||||||
.subtitles
|
.get(subtitle_locale)
|
||||||
.get(subtitle_locale)
|
.cloned()
|
||||||
// use closed captions as fallback if no actual subtitles are found
|
// use closed captions as fallback if no actual subtitles are found
|
||||||
.or_else(|| stream.captions.get(subtitle_locale))
|
.or_else(|| stream.captions.get(subtitle_locale).cloned())
|
||||||
.cloned()
|
|
||||||
} else {
|
|
||||||
stream
|
|
||||||
.captions
|
|
||||||
.get(subtitle_locale)
|
|
||||||
.or_else(|| stream.subtitles.get(subtitle_locale))
|
|
||||||
.cloned()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
@ -451,7 +400,7 @@ async fn get_format(
|
||||||
subtitles: subtitle.clone().map_or(vec![], |s| {
|
subtitles: subtitle.clone().map_or(vec![], |s| {
|
||||||
vec![(
|
vec![(
|
||||||
s,
|
s,
|
||||||
single_format.audio != Locale::ja_JP && stream.subtitles.len() == 1,
|
single_format.audio == Locale::ja_JP || stream.subtitles.len() > 1,
|
||||||
)]
|
)]
|
||||||
}),
|
}),
|
||||||
metadata: DownloadFormatMetadata {
|
metadata: DownloadFormatMetadata {
|
||||||
|
|
@ -468,7 +417,7 @@ async fn get_format(
|
||||||
subtitle.map_or(vec![], |s| {
|
subtitle.map_or(vec![], |s| {
|
||||||
vec![(
|
vec![(
|
||||||
s,
|
s,
|
||||||
single_format.audio != Locale::ja_JP && stream.subtitles.len() == 1,
|
single_format.audio == Locale::ja_JP || stream.subtitles.len() > 1,
|
||||||
)]
|
)]
|
||||||
}),
|
}),
|
||||||
)]);
|
)]);
|
||||||
|
|
@ -477,7 +426,5 @@ async fn get_format(
|
||||||
subs.push(download.subtitle.clone().unwrap())
|
subs.push(download.subtitle.clone().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.invalidate().await?;
|
|
||||||
|
|
||||||
Ok((download_format, format))
|
Ok((download_format, format))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
307
crunchy-cli-core/src/download/filter.rs
Normal file
307
crunchy-cli-core/src/download/filter.rs
Normal file
|
|
@ -0,0 +1,307 @@
|
||||||
|
use crate::download::Download;
|
||||||
|
use crate::utils::filter::Filter;
|
||||||
|
use crate::utils::format::{Format, SingleFormat, SingleFormatCollection};
|
||||||
|
use crate::utils::interactive_select::{check_for_duplicated_seasons, get_duplicated_seasons};
|
||||||
|
use crate::utils::parse::{fract, UrlFilter};
|
||||||
|
use anyhow::{bail, Result};
|
||||||
|
use crunchyroll_rs::{Concert, Episode, Movie, MovieListing, MusicVideo, Season, Series};
|
||||||
|
use log::{error, info, warn};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::ops::Not;
|
||||||
|
|
||||||
|
pub(crate) struct DownloadFilter {
|
||||||
|
url_filter: UrlFilter,
|
||||||
|
download: Download,
|
||||||
|
interactive_input: bool,
|
||||||
|
skip_special: bool,
|
||||||
|
season_episodes: HashMap<u32, Vec<Episode>>,
|
||||||
|
season_subtitles_missing: Vec<u32>,
|
||||||
|
seasons_with_premium: Option<Vec<u32>>,
|
||||||
|
season_visited: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DownloadFilter {
|
||||||
|
pub(crate) fn new(
|
||||||
|
url_filter: UrlFilter,
|
||||||
|
download: Download,
|
||||||
|
interactive_input: bool,
|
||||||
|
skip_special: bool,
|
||||||
|
is_premium: bool,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
url_filter,
|
||||||
|
download,
|
||||||
|
interactive_input,
|
||||||
|
skip_special,
|
||||||
|
season_episodes: HashMap::new(),
|
||||||
|
season_subtitles_missing: vec![],
|
||||||
|
seasons_with_premium: is_premium.not().then_some(vec![]),
|
||||||
|
season_visited: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Filter for DownloadFilter {
|
||||||
|
type T = SingleFormat;
|
||||||
|
type Output = SingleFormatCollection;
|
||||||
|
|
||||||
|
async fn visit_series(&mut self, series: Series) -> Result<Vec<Season>> {
|
||||||
|
// `series.audio_locales` isn't always populated b/c of crunchyrolls api. so check if the
|
||||||
|
// audio is matching only if the field is populated
|
||||||
|
if !series.audio_locales.is_empty() && !series.audio_locales.contains(&self.download.audio)
|
||||||
|
{
|
||||||
|
error!(
|
||||||
|
"Series {} is not available with {} audio",
|
||||||
|
series.title, self.download.audio
|
||||||
|
);
|
||||||
|
return Ok(vec![]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut seasons = vec![];
|
||||||
|
for mut season in series.seasons().await? {
|
||||||
|
if !self.url_filter.is_season_valid(season.season_number) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !season
|
||||||
|
.audio_locales
|
||||||
|
.iter()
|
||||||
|
.any(|l| l == &self.download.audio)
|
||||||
|
{
|
||||||
|
if season
|
||||||
|
.available_versions()
|
||||||
|
.await?
|
||||||
|
.iter()
|
||||||
|
.any(|l| l == &self.download.audio)
|
||||||
|
{
|
||||||
|
season = season
|
||||||
|
.version(vec![self.download.audio.clone()])
|
||||||
|
.await?
|
||||||
|
.remove(0)
|
||||||
|
} else {
|
||||||
|
error!(
|
||||||
|
"Season {} - '{}' is not available with {} audio",
|
||||||
|
season.season_number,
|
||||||
|
season.title,
|
||||||
|
self.download.audio.clone(),
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
seasons.push(season)
|
||||||
|
}
|
||||||
|
|
||||||
|
let duplicated_seasons = get_duplicated_seasons(&seasons);
|
||||||
|
if !duplicated_seasons.is_empty() {
|
||||||
|
if self.interactive_input {
|
||||||
|
check_for_duplicated_seasons(&mut seasons);
|
||||||
|
} else {
|
||||||
|
info!(
|
||||||
|
"Found duplicated seasons: {}",
|
||||||
|
duplicated_seasons
|
||||||
|
.iter()
|
||||||
|
.map(|d| d.to_string())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join(", ")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(seasons)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn visit_season(&mut self, season: Season) -> Result<Vec<Episode>> {
|
||||||
|
self.season_visited = true;
|
||||||
|
|
||||||
|
let mut episodes = season.episodes().await?;
|
||||||
|
|
||||||
|
if Format::has_relative_fmt(&self.download.output) {
|
||||||
|
for episode in episodes.iter() {
|
||||||
|
self.season_episodes
|
||||||
|
.entry(episode.season_number)
|
||||||
|
.or_default()
|
||||||
|
.push(episode.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
episodes.retain(|e| {
|
||||||
|
self.url_filter
|
||||||
|
.is_episode_valid(e.sequence_number, season.season_number)
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(episodes)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn visit_episode(&mut self, mut episode: Episode) -> Result<Option<Self::T>> {
|
||||||
|
if !self
|
||||||
|
.url_filter
|
||||||
|
.is_episode_valid(episode.sequence_number, episode.season_number)
|
||||||
|
{
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
|
// skip the episode if it's a special
|
||||||
|
if self.skip_special
|
||||||
|
&& (episode.sequence_number == 0.0 || episode.sequence_number.fract() != 0.0)
|
||||||
|
{
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if the audio locale is correct.
|
||||||
|
// should only be incorrect if the console input was a episode url. otherwise
|
||||||
|
// `DownloadFilter::visit_season` returns the correct episodes with matching audio
|
||||||
|
if episode.audio_locale != self.download.audio {
|
||||||
|
// check if any other version (same episode, other language) of this episode is available
|
||||||
|
// with the requested audio. if not, return an error
|
||||||
|
if !episode
|
||||||
|
.available_versions()
|
||||||
|
.await?
|
||||||
|
.contains(&self.download.audio)
|
||||||
|
{
|
||||||
|
let error_message = format!(
|
||||||
|
"Episode {} ({}) of {} season {} is not available with {} audio",
|
||||||
|
episode.sequence_number,
|
||||||
|
episode.title,
|
||||||
|
episode.series_title,
|
||||||
|
episode.season_number,
|
||||||
|
self.download.audio
|
||||||
|
);
|
||||||
|
// sometimes a series randomly has episode in an other language. if this is the case,
|
||||||
|
// only error if the input url was a episode url
|
||||||
|
if self.season_visited {
|
||||||
|
warn!("{}", error_message);
|
||||||
|
return Ok(None);
|
||||||
|
} else {
|
||||||
|
bail!("{}", error_message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// overwrite the current episode with the other version episode
|
||||||
|
episode = episode
|
||||||
|
.version(vec![self.download.audio.clone()])
|
||||||
|
.await?
|
||||||
|
.remove(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if the subtitles are supported
|
||||||
|
if let Some(subtitle_locale) = &self.download.subtitle {
|
||||||
|
if !episode.subtitle_locales.contains(subtitle_locale) {
|
||||||
|
// if the episode doesn't have the requested subtitles, print a error. to print this
|
||||||
|
// error only once per season, it's checked if an error got printed before by looking
|
||||||
|
// up if the season id is present in `self.season_subtitles_missing`. if not, print
|
||||||
|
// the error and add the season id to `self.season_subtitles_missing`. if it is
|
||||||
|
// present, skip the error printing
|
||||||
|
if !self
|
||||||
|
.season_subtitles_missing
|
||||||
|
.contains(&episode.season_number)
|
||||||
|
{
|
||||||
|
self.season_subtitles_missing.push(episode.season_number);
|
||||||
|
error!(
|
||||||
|
"{} season {} is not available with {} subtitles",
|
||||||
|
episode.series_title, episode.season_number, subtitle_locale
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.seasons_with_premium.is_some() && episode.is_premium_only {
|
||||||
|
if !self
|
||||||
|
.seasons_with_premium
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.contains(&episode.season_number)
|
||||||
|
{
|
||||||
|
warn!(
|
||||||
|
"Skipping premium episodes in season {}",
|
||||||
|
episode.season_number
|
||||||
|
);
|
||||||
|
self.seasons_with_premium
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.push(episode.season_number)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut relative_episode_number = None;
|
||||||
|
let mut relative_sequence_number = None;
|
||||||
|
// get the relative episode number. only done if the output string has the pattern to include
|
||||||
|
// the relative episode number as this requires some extra fetching
|
||||||
|
if Format::has_relative_fmt(&self.download.output) {
|
||||||
|
let season_eps = match self.season_episodes.get(&episode.season_number) {
|
||||||
|
Some(eps) => eps,
|
||||||
|
None => {
|
||||||
|
self.season_episodes.insert(
|
||||||
|
episode.season_number,
|
||||||
|
episode.season().await?.episodes().await?,
|
||||||
|
);
|
||||||
|
self.season_episodes.get(&episode.season_number).unwrap()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let mut non_integer_sequence_number_count = 0;
|
||||||
|
for (i, ep) in season_eps.iter().enumerate() {
|
||||||
|
if ep.sequence_number.fract() != 0.0 || ep.sequence_number == 0.0 {
|
||||||
|
non_integer_sequence_number_count += 1;
|
||||||
|
}
|
||||||
|
if ep.id == episode.id {
|
||||||
|
relative_episode_number = Some(i + 1);
|
||||||
|
relative_sequence_number = Some(
|
||||||
|
(i + 1 - non_integer_sequence_number_count) as f32
|
||||||
|
+ fract(ep.sequence_number),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if relative_episode_number.is_none() || relative_sequence_number.is_none() {
|
||||||
|
warn!(
|
||||||
|
"Failed to get relative episode number for episode {} ({}) of {} season {}",
|
||||||
|
episode.sequence_number,
|
||||||
|
episode.title,
|
||||||
|
episode.series_title,
|
||||||
|
episode.season_number,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Some(SingleFormat::new_from_episode(
|
||||||
|
episode.clone(),
|
||||||
|
self.download.subtitle.clone().map_or(vec![], |s| {
|
||||||
|
if episode.subtitle_locales.contains(&s) {
|
||||||
|
vec![s]
|
||||||
|
} else {
|
||||||
|
vec![]
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
relative_episode_number.map(|n| n as u32),
|
||||||
|
relative_sequence_number,
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn visit_movie_listing(&mut self, movie_listing: MovieListing) -> Result<Vec<Movie>> {
|
||||||
|
Ok(movie_listing.movies().await?)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn visit_movie(&mut self, movie: Movie) -> Result<Option<Self::T>> {
|
||||||
|
Ok(Some(SingleFormat::new_from_movie(movie, vec![])))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn visit_music_video(&mut self, music_video: MusicVideo) -> Result<Option<Self::T>> {
|
||||||
|
Ok(Some(SingleFormat::new_from_music_video(music_video)))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn visit_concert(&mut self, concert: Concert) -> Result<Option<Self::T>> {
|
||||||
|
Ok(Some(SingleFormat::new_from_concert(concert)))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn finish(self, input: Vec<Self::T>) -> Result<Self::Output> {
|
||||||
|
let mut single_format_collection = SingleFormatCollection::new();
|
||||||
|
|
||||||
|
for data in input {
|
||||||
|
single_format_collection.add_single_formats(vec![data])
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(single_format_collection)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
mod command;
|
mod command;
|
||||||
|
mod filter;
|
||||||
|
|
||||||
pub use command::Download;
|
pub use command::Download;
|
||||||
|
|
|
||||||
|
|
@ -111,10 +111,6 @@ impl Execute for Search {
|
||||||
warn!("Using `search` anonymously or with a non-premium account may return incomplete results")
|
warn!("Using `search` anonymously or with a non-premium account may return incomplete results")
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.output.contains("{{stream.is_drm}}") {
|
|
||||||
warn!("The `{{{{stream.is_drm}}}}` option is deprecated as it isn't reliable anymore and will be removed soon")
|
|
||||||
}
|
|
||||||
|
|
||||||
let input = if crunchyroll_rs::parse::parse_url(&self.input).is_some() {
|
let input = if crunchyroll_rs::parse::parse_url(&self.input).is_some() {
|
||||||
match parse_url(&ctx.crunchy, self.input.clone(), true).await {
|
match parse_url(&ctx.crunchy, self.input.clone(), true).await {
|
||||||
Ok(ok) => vec![ok],
|
Ok(ok) => vec![ok],
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@ impl From<&Stream> for FormatStream {
|
||||||
Self {
|
Self {
|
||||||
locale: value.audio_locale.clone(),
|
locale: value.audio_locale.clone(),
|
||||||
dash_url: value.url.clone(),
|
dash_url: value.url.clone(),
|
||||||
is_drm: false,
|
is_drm: value.session.uses_stream_limits,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -241,6 +241,14 @@ macro_rules! must_match_if_true {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! self_and_versions {
|
||||||
|
($var:expr => $audio:expr) => {{
|
||||||
|
let mut items = vec![$var.clone()];
|
||||||
|
items.extend($var.clone().version($audio).await?);
|
||||||
|
items
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Format {
|
pub struct Format {
|
||||||
pattern: Vec<(Range<usize>, Scope, String)>,
|
pattern: Vec<(Range<usize>, Scope, String)>,
|
||||||
pattern_count: HashMap<Scope, u32>,
|
pattern_count: HashMap<Scope, u32>,
|
||||||
|
|
@ -413,15 +421,7 @@ impl Format {
|
||||||
};
|
};
|
||||||
let mut seasons = vec![];
|
let mut seasons = vec![];
|
||||||
for season in tmp_seasons {
|
for season in tmp_seasons {
|
||||||
seasons.push(season.clone());
|
seasons.extend(self_and_versions!(season => self.filter_options.audio.clone()))
|
||||||
for version in season.versions {
|
|
||||||
if season.id == version.id {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if self.filter_options.audio.contains(&version.audio_locale) {
|
|
||||||
seasons.push(version.season().await?)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
tree.extend(
|
tree.extend(
|
||||||
self.filter_options
|
self.filter_options
|
||||||
|
|
@ -435,15 +435,7 @@ impl Format {
|
||||||
if !episode_empty || !stream_empty {
|
if !episode_empty || !stream_empty {
|
||||||
match &media_collection {
|
match &media_collection {
|
||||||
MediaCollection::Episode(episode) => {
|
MediaCollection::Episode(episode) => {
|
||||||
let mut episodes = vec![episode.clone()];
|
let episodes = self_and_versions!(episode => self.filter_options.audio.clone());
|
||||||
for version in &episode.versions {
|
|
||||||
if episode.id == version.id {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if self.filter_options.audio.contains(&version.audio_locale) {
|
|
||||||
episodes.push(version.episode().await?)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tree.push((
|
tree.push((
|
||||||
Season::default(),
|
Season::default(),
|
||||||
episodes
|
episodes
|
||||||
|
|
@ -472,9 +464,7 @@ impl Format {
|
||||||
if !stream_empty {
|
if !stream_empty {
|
||||||
for (_, episodes) in tree.iter_mut() {
|
for (_, episodes) in tree.iter_mut() {
|
||||||
for (episode, streams) in episodes {
|
for (episode, streams) in episodes {
|
||||||
let stream = episode.stream_maybe_without_drm().await?;
|
streams.push(episode.stream_maybe_without_drm().await?)
|
||||||
stream.clone().invalidate().await?;
|
|
||||||
streams.push(stream)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,30 @@
|
||||||
use crate::utils::ffmpeg::FFmpegPreset;
|
use crate::utils::ffmpeg::FFmpegPreset;
|
||||||
use crate::utils::filter::real_dedup_vec;
|
use crate::utils::filter::real_dedup_vec;
|
||||||
use crate::utils::fmt::format_time_delta;
|
|
||||||
use crate::utils::log::progress;
|
use crate::utils::log::progress;
|
||||||
use crate::utils::os::{cache_dir, is_special_file, temp_directory, temp_named_pipe, tempfile};
|
use crate::utils::os::{
|
||||||
|
cache_dir, is_special_file, temp_directory, temp_named_pipe, tempdir, tempfile,
|
||||||
|
};
|
||||||
use crate::utils::rate_limit::RateLimiterService;
|
use crate::utils::rate_limit::RateLimiterService;
|
||||||
use crate::utils::sync::{sync_audios, SyncAudio};
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use chrono::{NaiveTime, TimeDelta};
|
use chrono::{NaiveTime, TimeDelta};
|
||||||
use crunchyroll_rs::media::{SkipEvents, SkipEventsEvent, StreamData, StreamSegment, Subtitle};
|
use crunchyroll_rs::media::{SkipEvents, SkipEventsEvent, StreamData, StreamSegment, Subtitle};
|
||||||
use crunchyroll_rs::Locale;
|
use crunchyroll_rs::Locale;
|
||||||
|
use image_hasher::{Hasher, HasherConfig, ImageHash};
|
||||||
use indicatif::{ProgressBar, ProgressDrawTarget, ProgressFinish, ProgressStyle};
|
use indicatif::{ProgressBar, ProgressDrawTarget, ProgressFinish, ProgressStyle};
|
||||||
use log::{debug, warn, LevelFilter};
|
use log::{debug, warn, LevelFilter};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use rsubs_lib::{SSA, VTT};
|
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::{BTreeMap, HashMap};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::ops::Add;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::{env, fs};
|
use std::{env, fs};
|
||||||
use tempfile::TempPath;
|
use tempfile::TempPath;
|
||||||
use time::Time;
|
|
||||||
use tokio::io::{AsyncBufReadExt, AsyncReadExt, BufReader};
|
use tokio::io::{AsyncBufReadExt, AsyncReadExt, BufReader};
|
||||||
use tokio::select;
|
use tokio::select;
|
||||||
use tokio::sync::mpsc::unbounded_channel;
|
use tokio::sync::mpsc::unbounded_channel;
|
||||||
|
|
@ -39,7 +38,6 @@ pub enum MergeBehavior {
|
||||||
Video,
|
Video,
|
||||||
Audio,
|
Audio,
|
||||||
Auto,
|
Auto,
|
||||||
Sync,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MergeBehavior {
|
impl MergeBehavior {
|
||||||
|
|
@ -48,7 +46,6 @@ impl MergeBehavior {
|
||||||
"video" => MergeBehavior::Video,
|
"video" => MergeBehavior::Video,
|
||||||
"audio" => MergeBehavior::Audio,
|
"audio" => MergeBehavior::Audio,
|
||||||
"auto" => MergeBehavior::Auto,
|
"auto" => MergeBehavior::Auto,
|
||||||
"sync" => MergeBehavior::Sync,
|
|
||||||
_ => return Err(format!("'{}' is not a valid merge behavior", s)),
|
_ => return Err(format!("'{}' is not a valid merge behavior", s)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -66,8 +63,7 @@ pub struct DownloadBuilder {
|
||||||
force_hardsub: bool,
|
force_hardsub: bool,
|
||||||
download_fonts: bool,
|
download_fonts: bool,
|
||||||
no_closed_caption: bool,
|
no_closed_caption: bool,
|
||||||
merge_sync_tolerance: Option<u32>,
|
sync_start_value: Option<f64>,
|
||||||
merge_sync_precision: Option<u32>,
|
|
||||||
threads: usize,
|
threads: usize,
|
||||||
ffmpeg_threads: Option<usize>,
|
ffmpeg_threads: Option<usize>,
|
||||||
audio_locale_output_map: HashMap<Locale, String>,
|
audio_locale_output_map: HashMap<Locale, String>,
|
||||||
|
|
@ -87,8 +83,7 @@ impl DownloadBuilder {
|
||||||
force_hardsub: false,
|
force_hardsub: false,
|
||||||
download_fonts: false,
|
download_fonts: false,
|
||||||
no_closed_caption: false,
|
no_closed_caption: false,
|
||||||
merge_sync_tolerance: None,
|
sync_start_value: None,
|
||||||
merge_sync_precision: None,
|
|
||||||
threads: num_cpus::get(),
|
threads: num_cpus::get(),
|
||||||
ffmpeg_threads: None,
|
ffmpeg_threads: None,
|
||||||
audio_locale_output_map: HashMap::new(),
|
audio_locale_output_map: HashMap::new(),
|
||||||
|
|
@ -110,8 +105,7 @@ impl DownloadBuilder {
|
||||||
download_fonts: self.download_fonts,
|
download_fonts: self.download_fonts,
|
||||||
no_closed_caption: self.no_closed_caption,
|
no_closed_caption: self.no_closed_caption,
|
||||||
|
|
||||||
merge_sync_tolerance: self.merge_sync_tolerance,
|
sync_start_value: self.sync_start_value,
|
||||||
merge_sync_precision: self.merge_sync_precision,
|
|
||||||
|
|
||||||
download_threads: self.threads,
|
download_threads: self.threads,
|
||||||
ffmpeg_threads: self.ffmpeg_threads,
|
ffmpeg_threads: self.ffmpeg_threads,
|
||||||
|
|
@ -170,8 +164,7 @@ pub struct Downloader {
|
||||||
download_fonts: bool,
|
download_fonts: bool,
|
||||||
no_closed_caption: bool,
|
no_closed_caption: bool,
|
||||||
|
|
||||||
merge_sync_tolerance: Option<u32>,
|
sync_start_value: Option<f64>,
|
||||||
merge_sync_precision: Option<u32>,
|
|
||||||
|
|
||||||
download_threads: usize,
|
download_threads: usize,
|
||||||
ffmpeg_threads: Option<usize>,
|
ffmpeg_threads: Option<usize>,
|
||||||
|
|
@ -234,13 +227,13 @@ impl Downloader {
|
||||||
if let Some(subtitle_sort) = &self.subtitle_sort {
|
if let Some(subtitle_sort) = &self.subtitle_sort {
|
||||||
format
|
format
|
||||||
.subtitles
|
.subtitles
|
||||||
.sort_by(|(a_subtitle, a_cc), (b_subtitle, b_cc)| {
|
.sort_by(|(a_subtitle, a_not_cc), (b_subtitle, b_not_cc)| {
|
||||||
let ordering = subtitle_sort
|
let ordering = subtitle_sort
|
||||||
.iter()
|
.iter()
|
||||||
.position(|l| l == &a_subtitle.locale)
|
.position(|l| l == &a_subtitle.locale)
|
||||||
.cmp(&subtitle_sort.iter().position(|l| l == &b_subtitle.locale));
|
.cmp(&subtitle_sort.iter().position(|l| l == &b_subtitle.locale));
|
||||||
if matches!(ordering, Ordering::Equal) {
|
if matches!(ordering, Ordering::Equal) {
|
||||||
a_cc.cmp(b_cc).reverse()
|
a_not_cc.cmp(b_not_cc).reverse()
|
||||||
} else {
|
} else {
|
||||||
ordering
|
ordering
|
||||||
}
|
}
|
||||||
|
|
@ -251,7 +244,6 @@ impl Downloader {
|
||||||
let mut video_offset = None;
|
let mut video_offset = None;
|
||||||
let mut audio_offsets = HashMap::new();
|
let mut audio_offsets = HashMap::new();
|
||||||
let mut subtitle_offsets = HashMap::new();
|
let mut subtitle_offsets = HashMap::new();
|
||||||
let mut raw_audios = vec![];
|
|
||||||
let mut videos = vec![];
|
let mut videos = vec![];
|
||||||
let mut audios = vec![];
|
let mut audios = vec![];
|
||||||
let mut subtitles = vec![];
|
let mut subtitles = vec![];
|
||||||
|
|
@ -270,33 +262,40 @@ impl Downloader {
|
||||||
.max()
|
.max()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// downloads all audios
|
if self.formats.len() > 1 && self.sync_start_value.is_some() {
|
||||||
for (i, format) in self.formats.iter().enumerate() {
|
let all_segments_count: Vec<usize> = self
|
||||||
for (stream_data, locale) in &format.audios {
|
.formats
|
||||||
|
.iter()
|
||||||
|
.map(|f| f.video.0.segments().len())
|
||||||
|
.collect();
|
||||||
|
let sync_segments = 11.max(
|
||||||
|
all_segments_count.iter().max().unwrap() - all_segments_count.iter().min().unwrap(),
|
||||||
|
);
|
||||||
|
let mut sync_vids = vec![];
|
||||||
|
for (i, format) in self.formats.iter().enumerate() {
|
||||||
let path = self
|
let path = self
|
||||||
.download_audio(
|
.download_video(
|
||||||
stream_data,
|
&format.video.0,
|
||||||
format!("{:<1$}", format!("Downloading {} audio", locale), fmt_space),
|
format!("Downloading video #{} sync segments", i + 1),
|
||||||
|
Some(sync_segments),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
raw_audios.push(SyncAudio {
|
sync_vids.push(SyncVideo {
|
||||||
format_id: i,
|
|
||||||
path,
|
path,
|
||||||
locale: locale.clone(),
|
length: len_from_segments(&format.video.0.segments()),
|
||||||
sample_rate: stream_data.sampling_rate().unwrap(),
|
available_frames: (len_from_segments(
|
||||||
video_idx: i,
|
&format.video.0.segments()[0..sync_segments],
|
||||||
|
)
|
||||||
|
.num_milliseconds() as f64
|
||||||
|
* format.video.0.fps().unwrap()
|
||||||
|
/ 1000.0) as u64,
|
||||||
|
idx: i,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if self.formats.len() > 1 && self.merge_sync_tolerance.is_some() {
|
|
||||||
let _progress_handler =
|
let _progress_handler =
|
||||||
progress!("Syncing video start times (this might take some time)");
|
progress!("Syncing video start times (this might take some time)");
|
||||||
let mut offsets = sync_audios(
|
let mut offsets = sync_videos(sync_vids, self.sync_start_value.unwrap())?;
|
||||||
&raw_audios,
|
|
||||||
self.merge_sync_tolerance.unwrap(),
|
|
||||||
self.merge_sync_precision.unwrap(),
|
|
||||||
)?;
|
|
||||||
drop(_progress_handler);
|
drop(_progress_handler);
|
||||||
|
|
||||||
let mut offset_pre_checked = false;
|
let mut offset_pre_checked = false;
|
||||||
|
|
@ -307,14 +306,19 @@ impl Downloader {
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, f)| {
|
.map(|(i, f)| {
|
||||||
len_from_segments(&f.video.0.segments())
|
len_from_segments(&f.video.0.segments())
|
||||||
- tmp_offsets.get(&i).copied().unwrap_or_default()
|
- TimeDelta::milliseconds(
|
||||||
|
tmp_offsets
|
||||||
|
.get(&i)
|
||||||
|
.map(|o| (*o as f64 / f.video.0.fps().unwrap() * 1000.0) as i64)
|
||||||
|
.unwrap_or_default(),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let min = formats_with_offset.iter().min().unwrap();
|
let min = formats_with_offset.iter().min().unwrap();
|
||||||
let max = formats_with_offset.iter().max().unwrap();
|
let max = formats_with_offset.iter().max().unwrap();
|
||||||
|
|
||||||
if max.num_seconds() - min.num_seconds() > 15 {
|
if max.num_seconds() - min.num_seconds() > 15 {
|
||||||
warn!("Found difference of >15 seconds after sync, so the application was skipped");
|
warn!("Found difference of >15 seconds after sync, skipping applying it");
|
||||||
offsets = None;
|
offsets = None;
|
||||||
offset_pre_checked = true
|
offset_pre_checked = true
|
||||||
}
|
}
|
||||||
|
|
@ -322,25 +326,45 @@ impl Downloader {
|
||||||
|
|
||||||
if let Some(offsets) = offsets {
|
if let Some(offsets) = offsets {
|
||||||
let mut root_format_idx = 0;
|
let mut root_format_idx = 0;
|
||||||
let mut root_format_offset = u64::MAX;
|
let mut root_format_length = 0;
|
||||||
|
let mut audio_count: usize = 0;
|
||||||
|
let mut subtitle_count: usize = 0;
|
||||||
for (i, format) in self.formats.iter().enumerate() {
|
for (i, format) in self.formats.iter().enumerate() {
|
||||||
let offset = offsets.get(&i).copied().unwrap_or_default();
|
let format_fps = format.video.0.fps().unwrap();
|
||||||
let format_offset = offset.num_milliseconds() as u64;
|
let format_len = format
|
||||||
if format_offset < root_format_offset {
|
.video
|
||||||
|
.0
|
||||||
|
.segments()
|
||||||
|
.iter()
|
||||||
|
.map(|s| s.length.as_millis())
|
||||||
|
.sum::<u128>() as u64
|
||||||
|
- offsets.get(&i).map_or(0, |o| *o);
|
||||||
|
if format_len > root_format_length {
|
||||||
root_format_idx = i;
|
root_format_idx = i;
|
||||||
root_format_offset = format_offset;
|
root_format_length = format_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
for _ in &format.audios {
|
for _ in &format.audios {
|
||||||
if let Some(offset) = &offsets.get(&i) {
|
if let Some(offset) = &offsets.get(&i) {
|
||||||
audio_offsets.insert(i, **offset);
|
audio_offsets.insert(
|
||||||
|
audio_count,
|
||||||
|
TimeDelta::milliseconds(
|
||||||
|
(**offset as f64 / format_fps * 1000.0) as i64,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
audio_count += 1
|
||||||
}
|
}
|
||||||
for _ in &format.subtitles {
|
for _ in &format.subtitles {
|
||||||
if let Some(offset) = &offsets.get(&i) {
|
if let Some(offset) = &offsets.get(&i) {
|
||||||
subtitle_offsets.insert(i, **offset);
|
subtitle_offsets.insert(
|
||||||
|
subtitle_count,
|
||||||
|
TimeDelta::milliseconds(
|
||||||
|
(**offset as f64 / format_fps * 1000.0) as i64,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
subtitle_count += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -365,28 +389,20 @@ impl Downloader {
|
||||||
root_format.subtitles.extend(subtitle_append);
|
root_format.subtitles.extend(subtitle_append);
|
||||||
|
|
||||||
self.formats = vec![root_format];
|
self.formats = vec![root_format];
|
||||||
video_offset = offsets.get(&root_format_idx).copied();
|
video_offset = offsets.get(&root_format_idx).map(|o| {
|
||||||
for raw_audio in raw_audios.iter_mut() {
|
TimeDelta::milliseconds(
|
||||||
raw_audio.video_idx = root_format_idx;
|
(*o as f64 / self.formats[0].video.0.fps().unwrap() * 1000.0) as i64,
|
||||||
}
|
)
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
for format in &mut self.formats {
|
for format in &mut self.formats {
|
||||||
format.metadata.skip_events = None
|
format.metadata.skip_events = None
|
||||||
}
|
}
|
||||||
if !offset_pre_checked {
|
|
||||||
warn!("Couldn't find reliable sync positions")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// add audio metadata
|
if !offset_pre_checked {
|
||||||
for raw_audio in raw_audios {
|
warn!("Couldn't find reliable sync positions")
|
||||||
audios.push(FFmpegAudioMeta {
|
}
|
||||||
path: raw_audio.path,
|
|
||||||
locale: raw_audio.locale,
|
|
||||||
start_time: audio_offsets.get(&raw_audio.format_id).copied(),
|
|
||||||
video_idx: raw_audio.video_idx,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// downloads all videos
|
// downloads all videos
|
||||||
|
|
@ -418,6 +434,24 @@ impl Downloader {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// downloads all audios
|
||||||
|
for (i, format) in self.formats.iter().enumerate() {
|
||||||
|
for (j, (stream_data, locale)) in format.audios.iter().enumerate() {
|
||||||
|
let path = self
|
||||||
|
.download_audio(
|
||||||
|
stream_data,
|
||||||
|
format!("{:<1$}", format!("Downloading {} audio", locale), fmt_space),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
audios.push(FFmpegAudioMeta {
|
||||||
|
path,
|
||||||
|
locale: locale.clone(),
|
||||||
|
start_time: audio_offsets.get(&j).cloned(),
|
||||||
|
video_idx: i,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (i, format) in self.formats.iter().enumerate() {
|
for (i, format) in self.formats.iter().enumerate() {
|
||||||
if format.subtitles.is_empty() {
|
if format.subtitles.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -443,8 +477,8 @@ impl Downloader {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
for (j, (subtitle, cc)) in format.subtitles.iter().enumerate() {
|
for (j, (subtitle, not_cc)) in format.subtitles.iter().enumerate() {
|
||||||
if *cc && self.no_closed_caption {
|
if !not_cc && self.no_closed_caption {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -454,7 +488,7 @@ impl Downloader {
|
||||||
progress_message += ", "
|
progress_message += ", "
|
||||||
}
|
}
|
||||||
progress_message += &subtitle.locale.to_string();
|
progress_message += &subtitle.locale.to_string();
|
||||||
if *cc {
|
if !not_cc {
|
||||||
progress_message += " (CC)";
|
progress_message += " (CC)";
|
||||||
}
|
}
|
||||||
if i.min(videos.len() - 1) != 0 {
|
if i.min(videos.len() - 1) != 0 {
|
||||||
|
|
@ -469,12 +503,12 @@ impl Downloader {
|
||||||
debug!(
|
debug!(
|
||||||
"Downloaded {} subtitles{}",
|
"Downloaded {} subtitles{}",
|
||||||
subtitle.locale,
|
subtitle.locale,
|
||||||
cc.then_some(" (cc)").unwrap_or_default(),
|
(!not_cc).then_some(" (cc)").unwrap_or_default(),
|
||||||
);
|
);
|
||||||
subtitles.push(FFmpegSubtitleMeta {
|
subtitles.push(FFmpegSubtitleMeta {
|
||||||
path,
|
path,
|
||||||
locale: subtitle.locale.clone(),
|
locale: subtitle.locale.clone(),
|
||||||
cc: *cc,
|
cc: !not_cc,
|
||||||
start_time: subtitle_offsets.get(&j).cloned(),
|
start_time: subtitle_offsets.get(&j).cloned(),
|
||||||
video_idx: i,
|
video_idx: i,
|
||||||
})
|
})
|
||||||
|
|
@ -561,7 +595,7 @@ impl Downloader {
|
||||||
|
|
||||||
for (i, meta) in videos.iter().enumerate() {
|
for (i, meta) in videos.iter().enumerate() {
|
||||||
if let Some(start_time) = meta.start_time {
|
if let Some(start_time) = meta.start_time {
|
||||||
input.extend(["-itsoffset".to_string(), format_time_delta(&start_time)])
|
input.extend(["-ss".to_string(), format_time_delta(start_time)])
|
||||||
}
|
}
|
||||||
input.extend(["-i".to_string(), meta.path.to_string_lossy().to_string()]);
|
input.extend(["-i".to_string(), meta.path.to_string_lossy().to_string()]);
|
||||||
maps.extend(["-map".to_string(), i.to_string()]);
|
maps.extend(["-map".to_string(), i.to_string()]);
|
||||||
|
|
@ -582,7 +616,7 @@ impl Downloader {
|
||||||
}
|
}
|
||||||
for (i, meta) in audios.iter().enumerate() {
|
for (i, meta) in audios.iter().enumerate() {
|
||||||
if let Some(start_time) = meta.start_time {
|
if let Some(start_time) = meta.start_time {
|
||||||
input.extend(["-itsoffset".to_string(), format_time_delta(&start_time)])
|
input.extend(["-ss".to_string(), format_time_delta(start_time)])
|
||||||
}
|
}
|
||||||
input.extend(["-i".to_string(), meta.path.to_string_lossy().to_string()]);
|
input.extend(["-i".to_string(), meta.path.to_string_lossy().to_string()]);
|
||||||
maps.extend(["-map".to_string(), (i + videos.len()).to_string()]);
|
maps.extend(["-map".to_string(), (i + videos.len()).to_string()]);
|
||||||
|
|
@ -629,7 +663,7 @@ impl Downloader {
|
||||||
if container_supports_softsubs {
|
if container_supports_softsubs {
|
||||||
for (i, meta) in subtitles.iter().enumerate() {
|
for (i, meta) in subtitles.iter().enumerate() {
|
||||||
if let Some(start_time) = meta.start_time {
|
if let Some(start_time) = meta.start_time {
|
||||||
input.extend(["-itsoffset".to_string(), format_time_delta(&start_time)])
|
input.extend(["-ss".to_string(), format_time_delta(start_time)])
|
||||||
}
|
}
|
||||||
input.extend(["-i".to_string(), meta.path.to_string_lossy().to_string()]);
|
input.extend(["-i".to_string(), meta.path.to_string_lossy().to_string()]);
|
||||||
maps.extend([
|
maps.extend([
|
||||||
|
|
@ -648,7 +682,7 @@ impl Downloader {
|
||||||
metadata.extend([
|
metadata.extend([
|
||||||
format!("-metadata:s:s:{}", i),
|
format!("-metadata:s:s:{}", i),
|
||||||
format!("title={}", {
|
format!("title={}", {
|
||||||
let mut title = meta.locale.to_human_readable();
|
let mut title = meta.locale.to_string();
|
||||||
if meta.cc {
|
if meta.cc {
|
||||||
title += " (CC)"
|
title += " (CC)"
|
||||||
}
|
}
|
||||||
|
|
@ -722,7 +756,7 @@ impl Downloader {
|
||||||
output_presets.remove(i - remove_count);
|
output_presets.remove(i - remove_count);
|
||||||
remove_count += 1;
|
remove_count += 1;
|
||||||
}
|
}
|
||||||
last.clone_from(s);
|
last = s.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
output_presets.extend([
|
output_presets.extend([
|
||||||
|
|
@ -923,45 +957,14 @@ impl Downloader {
|
||||||
subtitle: Subtitle,
|
subtitle: Subtitle,
|
||||||
max_length: TimeDelta,
|
max_length: TimeDelta,
|
||||||
) -> Result<TempPath> {
|
) -> Result<TempPath> {
|
||||||
let buf = subtitle.data().await?;
|
|
||||||
let mut ass = match subtitle.format.as_str() {
|
|
||||||
"ass" => SSA::parse(String::from_utf8_lossy(&buf))?,
|
|
||||||
"vtt" => VTT::parse(String::from_utf8_lossy(&buf))?.to_ssa(),
|
|
||||||
_ => bail!("unknown subtitle format: {}", subtitle.format),
|
|
||||||
};
|
|
||||||
// subtitles aren't always correct sorted and video players may have issues with that. to
|
|
||||||
// prevent issues, the subtitles are sorted
|
|
||||||
// (https://github.com/crunchy-labs/crunchy-cli/issues/208)
|
|
||||||
ass.events.sort_by(|a, b| a.start.cmp(&b.start));
|
|
||||||
// it might be the case that the start and/or end time are greater than the actual video
|
|
||||||
// length. this might also result in issues with video players, thus the times are stripped
|
|
||||||
// to be at most as long as `max_length`
|
|
||||||
// (https://github.com/crunchy-labs/crunchy-cli/issues/32)
|
|
||||||
for i in (0..ass.events.len()).rev() {
|
|
||||||
let max_len = Time::from_hms(0, 0, 0)
|
|
||||||
.unwrap()
|
|
||||||
.add(Duration::from_millis(max_length.num_milliseconds() as u64));
|
|
||||||
|
|
||||||
if ass.events[i].start > max_len {
|
|
||||||
if ass.events[i].end > max_len {
|
|
||||||
ass.events[i].start = max_len
|
|
||||||
}
|
|
||||||
ass.events[i].end = max_len
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// without this additional info, subtitle look very messy in some video player
|
|
||||||
// (https://github.com/crunchy-labs/crunchy-cli/issues/66)
|
|
||||||
ass.info
|
|
||||||
.additional_fields
|
|
||||||
.insert("ScaledBorderAndShadow".to_string(), "yes".to_string());
|
|
||||||
|
|
||||||
let tempfile = tempfile(".ass")?;
|
let tempfile = tempfile(".ass")?;
|
||||||
let path = tempfile.into_temp_path();
|
let (mut file, path) = tempfile.into_parts();
|
||||||
|
|
||||||
fs::write(&path, ass.to_string())?;
|
let mut buf = vec![];
|
||||||
|
subtitle.write_to(&mut buf).await?;
|
||||||
|
fix_subtitles(&mut buf, max_length);
|
||||||
|
|
||||||
|
file.write_all(buf.as_slice())?;
|
||||||
|
|
||||||
Ok(path)
|
Ok(path)
|
||||||
}
|
}
|
||||||
|
|
@ -1325,6 +1328,93 @@ fn get_subtitle_stats(path: &Path) -> Result<Vec<String>> {
|
||||||
Ok(fonts)
|
Ok(fonts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Fix the subtitles in multiple ways as Crunchyroll sometimes delivers them malformed.
|
||||||
|
///
|
||||||
|
/// Look and feel fix: Add `ScaledBorderAndShadows: yes` to subtitles; without it they look very
|
||||||
|
/// messy on some video players. See
|
||||||
|
/// [crunchy-labs/crunchy-cli#66](https://github.com/crunchy-labs/crunchy-cli/issues/66) for more
|
||||||
|
/// information.
|
||||||
|
/// Length fix: Sometimes subtitles have an unnecessary long entry which exceeds the video length,
|
||||||
|
/// some video players can't handle this correctly. To prevent this, the subtitles must be checked
|
||||||
|
/// if any entry is longer than the video length and if so the entry ending must be hard set to not
|
||||||
|
/// exceed the video length. See [crunchy-labs/crunchy-cli#32](https://github.com/crunchy-labs/crunchy-cli/issues/32)
|
||||||
|
/// for more information.
|
||||||
|
/// Sort fix: Sometimes subtitle entries aren't sorted correctly by time which confuses some video
|
||||||
|
/// players. To prevent this, the subtitle entries must be manually sorted. See
|
||||||
|
/// [crunchy-labs/crunchy-cli#208](https://github.com/crunchy-labs/crunchy-cli/issues/208) for more
|
||||||
|
/// information.
|
||||||
|
fn fix_subtitles(raw: &mut Vec<u8>, max_length: TimeDelta) {
|
||||||
|
let re = Regex::new(
|
||||||
|
r"^Dialogue:\s(?P<layer>\d+),(?P<start>\d+:\d+:\d+\.\d+),(?P<end>\d+:\d+:\d+\.\d+),",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut entries = (vec![], vec![]);
|
||||||
|
|
||||||
|
let mut as_lines: Vec<String> = String::from_utf8_lossy(raw.as_slice())
|
||||||
|
.split('\n')
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
for (i, line) in as_lines.iter_mut().enumerate() {
|
||||||
|
if line.trim() == "[Script Info]" {
|
||||||
|
line.push_str("\nScaledBorderAndShadow: yes")
|
||||||
|
} else if let Some(capture) = re.captures(line) {
|
||||||
|
let mut start = capture
|
||||||
|
.name("start")
|
||||||
|
.map_or(NaiveTime::default(), |s| {
|
||||||
|
NaiveTime::parse_from_str(s.as_str(), "%H:%M:%S.%f").unwrap()
|
||||||
|
})
|
||||||
|
.signed_duration_since(NaiveTime::MIN);
|
||||||
|
let mut end = capture
|
||||||
|
.name("end")
|
||||||
|
.map_or(NaiveTime::default(), |e| {
|
||||||
|
NaiveTime::parse_from_str(e.as_str(), "%H:%M:%S.%f").unwrap()
|
||||||
|
})
|
||||||
|
.signed_duration_since(NaiveTime::MIN);
|
||||||
|
|
||||||
|
if start > max_length || end > max_length {
|
||||||
|
let layer = capture
|
||||||
|
.name("layer")
|
||||||
|
.map_or(0, |l| i32::from_str(l.as_str()).unwrap());
|
||||||
|
|
||||||
|
if start > max_length {
|
||||||
|
start = max_length;
|
||||||
|
}
|
||||||
|
if start > max_length || end > max_length {
|
||||||
|
end = max_length;
|
||||||
|
}
|
||||||
|
|
||||||
|
*line = re
|
||||||
|
.replace(
|
||||||
|
line,
|
||||||
|
format!(
|
||||||
|
"Dialogue: {},{},{},",
|
||||||
|
layer,
|
||||||
|
format_time_delta(start),
|
||||||
|
format_time_delta(end)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
entries.0.push((start, i));
|
||||||
|
entries.1.push(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
entries.0.sort_by(|(a, _), (b, _)| a.cmp(b));
|
||||||
|
for i in 0..entries.0.len() {
|
||||||
|
let (_, original_position) = entries.0[i];
|
||||||
|
let new_position = entries.1[i];
|
||||||
|
|
||||||
|
if original_position != new_position {
|
||||||
|
as_lines.swap(original_position, new_position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*raw = as_lines.join("\n").into_bytes()
|
||||||
|
}
|
||||||
|
|
||||||
fn write_ffmpeg_chapters(
|
fn write_ffmpeg_chapters(
|
||||||
file: &mut fs::File,
|
file: &mut fs::File,
|
||||||
video_len: TimeDelta,
|
video_len: TimeDelta,
|
||||||
|
|
@ -1448,6 +1538,146 @@ async fn ffmpeg_progress<R: AsyncReadExt + Unpin>(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct SyncVideo {
|
||||||
|
path: TempPath,
|
||||||
|
length: TimeDelta,
|
||||||
|
available_frames: u64,
|
||||||
|
idx: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sync_videos(mut sync_videos: Vec<SyncVideo>, value: f64) -> Result<Option<HashMap<usize, u64>>> {
|
||||||
|
let mut result = HashMap::new();
|
||||||
|
let hasher = HasherConfig::new().preproc_dct().to_hasher();
|
||||||
|
let start_frame = 300;
|
||||||
|
|
||||||
|
sync_videos.sort_by_key(|sv| sv.length);
|
||||||
|
|
||||||
|
let sync_base = sync_videos.remove(0);
|
||||||
|
let sync_hashes = extract_frame_hashes(&sync_base.path, start_frame, 50, &hasher)?;
|
||||||
|
|
||||||
|
for sync_video in sync_videos {
|
||||||
|
let mut highest_frame_match = f64::INFINITY;
|
||||||
|
let mut frame = start_frame;
|
||||||
|
let mut hashes = vec![];
|
||||||
|
|
||||||
|
loop {
|
||||||
|
if frame == sync_video.available_frames {
|
||||||
|
debug!(
|
||||||
|
"Failed to sync videos, end of stream {} reached (highest frame match: {})",
|
||||||
|
sync_video.idx + 1,
|
||||||
|
highest_frame_match
|
||||||
|
);
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
|
hashes.drain(0..(hashes.len() as i32 - sync_hashes.len() as i32).max(0) as usize);
|
||||||
|
hashes.extend(extract_frame_hashes(
|
||||||
|
&sync_video.path,
|
||||||
|
frame,
|
||||||
|
300 - hashes.len() as u64,
|
||||||
|
&hasher,
|
||||||
|
)?);
|
||||||
|
|
||||||
|
let mut check_frame_windows_result: Vec<(usize, f64)> =
|
||||||
|
check_frame_windows(&sync_hashes, &hashes)
|
||||||
|
.into_iter()
|
||||||
|
.enumerate()
|
||||||
|
.collect();
|
||||||
|
check_frame_windows_result.sort_by(|(_, a), (_, b)| a.partial_cmp(&b).unwrap());
|
||||||
|
if check_frame_windows_result[0].1 <= value {
|
||||||
|
result.insert(
|
||||||
|
sync_video.idx,
|
||||||
|
frame + check_frame_windows_result[0].0 as u64 - start_frame,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
} else if check_frame_windows_result[0].1 < highest_frame_match {
|
||||||
|
highest_frame_match = check_frame_windows_result[0].1
|
||||||
|
}
|
||||||
|
|
||||||
|
frame = (frame + 300 - sync_hashes.len() as u64).min(sync_video.available_frames)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Some(result))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extract_frame_hashes(
|
||||||
|
input_file: &Path,
|
||||||
|
start_frame: u64,
|
||||||
|
frame_count: u64,
|
||||||
|
hasher: &Hasher,
|
||||||
|
) -> Result<Vec<ImageHash>> {
|
||||||
|
let frame_dir = tempdir(format!(
|
||||||
|
"{}_sync_frames",
|
||||||
|
input_file
|
||||||
|
.file_name()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_string_lossy()
|
||||||
|
.trim_end_matches(
|
||||||
|
&input_file
|
||||||
|
.file_stem()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_string_lossy()
|
||||||
|
.to_string()
|
||||||
|
)
|
||||||
|
))?;
|
||||||
|
let extract_output = Command::new("ffmpeg")
|
||||||
|
.arg("-hide_banner")
|
||||||
|
.arg("-y")
|
||||||
|
.args(["-i", input_file.to_string_lossy().to_string().as_str()])
|
||||||
|
.args([
|
||||||
|
"-vf",
|
||||||
|
format!(
|
||||||
|
r#"select=between(n\,{}\,{}),setpts=PTS-STARTPTS,scale=-1:240"#,
|
||||||
|
start_frame,
|
||||||
|
start_frame + frame_count
|
||||||
|
)
|
||||||
|
.as_str(),
|
||||||
|
])
|
||||||
|
.args(["-vframes", frame_count.to_string().as_str()])
|
||||||
|
.arg(format!("{}/%03d.jpg", frame_dir.path().to_string_lossy()))
|
||||||
|
.output()?;
|
||||||
|
if !extract_output.status.success() {
|
||||||
|
bail!(
|
||||||
|
"{}",
|
||||||
|
String::from_utf8_lossy(extract_output.stderr.as_slice())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut hashes = vec![];
|
||||||
|
for file in frame_dir.path().read_dir()? {
|
||||||
|
let file = file?;
|
||||||
|
let img = image::open(file.path())?;
|
||||||
|
hashes.push(hasher.hash_image(&img))
|
||||||
|
}
|
||||||
|
Ok(hashes)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_frame_windows(base_hashes: &[ImageHash], check_hashes: &[ImageHash]) -> Vec<f64> {
|
||||||
|
let mut results = vec![];
|
||||||
|
|
||||||
|
for i in 0..(check_hashes.len() - base_hashes.len()) {
|
||||||
|
let check_window = &check_hashes[i..(base_hashes.len() + i)];
|
||||||
|
let sum = std::iter::zip(base_hashes, check_window)
|
||||||
|
.map(|(a, b)| a.dist(b))
|
||||||
|
.sum::<u32>();
|
||||||
|
results.push(sum as f64 / check_window.len() as f64);
|
||||||
|
}
|
||||||
|
results
|
||||||
|
}
|
||||||
|
|
||||||
|
fn format_time_delta(time_delta: TimeDelta) -> String {
|
||||||
|
let hours = time_delta.num_hours();
|
||||||
|
let minutes = time_delta.num_minutes() - time_delta.num_hours() * 60;
|
||||||
|
let seconds = time_delta.num_seconds() - time_delta.num_minutes() * 60;
|
||||||
|
let milliseconds = time_delta.num_milliseconds() - time_delta.num_seconds() * 1000;
|
||||||
|
|
||||||
|
format!(
|
||||||
|
"{}:{:0>2}:{:0>2}.{:0>3}",
|
||||||
|
hours, minutes, seconds, milliseconds
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fn len_from_segments(segments: &[StreamSegment]) -> TimeDelta {
|
fn len_from_segments(segments: &[StreamSegment]) -> TimeDelta {
|
||||||
TimeDelta::milliseconds(segments.iter().map(|s| s.length.as_millis()).sum::<u128>() as i64)
|
TimeDelta::milliseconds(segments.iter().map(|s| s.length.as_millis()).sum::<u128>() as i64)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::fmt;
|
|
||||||
use std::fmt::Formatter;
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
pub const SOFTSUB_CONTAINERS: [&str; 3] = ["mkv", "mov", "mp4"];
|
pub const SOFTSUB_CONTAINERS: [&str; 3] = ["mkv", "mov", "mp4"];
|
||||||
|
|
@ -35,11 +33,11 @@ macro_rules! ffmpeg_enum {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for $name {
|
impl ToString for $name {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
fn to_string(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
$(
|
$(
|
||||||
&$name::$field => write!(f, "{}", stringify!($field).to_string().to_lowercase())
|
&$name::$field => stringify!($field).to_string().to_lowercase()
|
||||||
),*
|
),*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -137,16 +135,23 @@ impl FFmpegPreset {
|
||||||
for (codec, hwaccel, quality) in FFmpegPreset::available_matches() {
|
for (codec, hwaccel, quality) in FFmpegPreset::available_matches() {
|
||||||
let mut description_details = vec![];
|
let mut description_details = vec![];
|
||||||
if let Some(h) = &hwaccel {
|
if let Some(h) = &hwaccel {
|
||||||
description_details.push(format!("{h} hardware acceleration"))
|
description_details.push(format!("{} hardware acceleration", h.to_string()))
|
||||||
}
|
}
|
||||||
if let Some(q) = &quality {
|
if let Some(q) = &quality {
|
||||||
description_details.push(format!("{q} video quality/compression"))
|
description_details.push(format!("{} video quality/compression", q.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
let description = if description_details.is_empty() {
|
let description = if description_details.is_empty() {
|
||||||
format!("{codec} encoded with default video quality/compression",)
|
format!(
|
||||||
|
"{} encoded with default video quality/compression",
|
||||||
|
codec.to_string()
|
||||||
|
)
|
||||||
} else if description_details.len() == 1 {
|
} else if description_details.len() == 1 {
|
||||||
format!("{} encoded with {}", codec, description_details[0])
|
format!(
|
||||||
|
"{} encoded with {}",
|
||||||
|
codec.to_string(),
|
||||||
|
description_details[0]
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
let first = description_details.remove(0);
|
let first = description_details.remove(0);
|
||||||
let last = description_details.remove(description_details.len() - 1);
|
let last = description_details.remove(description_details.len() - 1);
|
||||||
|
|
@ -156,7 +161,13 @@ impl FFmpegPreset {
|
||||||
"".to_string()
|
"".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
format!("{codec} encoded with {first}{mid} and {last}",)
|
format!(
|
||||||
|
"{} encoded with {}{} and {}",
|
||||||
|
codec.to_string(),
|
||||||
|
first,
|
||||||
|
mid,
|
||||||
|
last
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
return_values.push(format!(
|
return_values.push(format!(
|
||||||
|
|
@ -190,7 +201,11 @@ impl FFmpegPreset {
|
||||||
.find(|p| p.to_string() == token.to_lowercase())
|
.find(|p| p.to_string() == token.to_lowercase())
|
||||||
{
|
{
|
||||||
if let Some(cc) = codec {
|
if let Some(cc) = codec {
|
||||||
return Err(format!("cannot use multiple codecs (found {cc} and {c})",));
|
return Err(format!(
|
||||||
|
"cannot use multiple codecs (found {} and {})",
|
||||||
|
cc.to_string(),
|
||||||
|
c.to_string()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
codec = Some(c)
|
codec = Some(c)
|
||||||
} else if let Some(h) = FFmpegHwAccel::all()
|
} else if let Some(h) = FFmpegHwAccel::all()
|
||||||
|
|
@ -199,7 +214,9 @@ impl FFmpegPreset {
|
||||||
{
|
{
|
||||||
if let Some(hh) = hwaccel {
|
if let Some(hh) = hwaccel {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"cannot use multiple hardware accelerations (found {hh} and {h})",
|
"cannot use multiple hardware accelerations (found {} and {})",
|
||||||
|
hh.to_string(),
|
||||||
|
h.to_string()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
hwaccel = Some(h)
|
hwaccel = Some(h)
|
||||||
|
|
@ -209,7 +226,9 @@ impl FFmpegPreset {
|
||||||
{
|
{
|
||||||
if let Some(qq) = quality {
|
if let Some(qq) = quality {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"cannot use multiple ffmpeg preset qualities (found {qq} and {q})",
|
"cannot use multiple ffmpeg preset qualities (found {} and {})",
|
||||||
|
qq.to_string(),
|
||||||
|
q.to_string()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
quality = Some(q)
|
quality = Some(q)
|
||||||
|
|
|
||||||
|
|
@ -1,407 +1,24 @@
|
||||||
use crate::utils::format::{SingleFormat, SingleFormatCollection};
|
|
||||||
use crate::utils::interactive_select::{check_for_duplicated_seasons, get_duplicated_seasons};
|
|
||||||
use crate::utils::parse::{fract, UrlFilter};
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use crunchyroll_rs::{
|
use crunchyroll_rs::{
|
||||||
Concert, Episode, Locale, MediaCollection, Movie, MovieListing, MusicVideo, Season, Series,
|
Concert, Episode, MediaCollection, Movie, MovieListing, MusicVideo, Season, Series,
|
||||||
};
|
};
|
||||||
use log::{info, warn};
|
|
||||||
use std::collections::{BTreeMap, HashMap};
|
|
||||||
use std::ops::Not;
|
|
||||||
|
|
||||||
pub(crate) enum FilterMediaScope<'a> {
|
pub trait Filter {
|
||||||
Series(&'a Series),
|
type T: Send + Sized;
|
||||||
Season(&'a Season),
|
type Output: Send + Sized;
|
||||||
/// Always contains 1 or 2 episodes.
|
|
||||||
/// - 1: The episode's audio is completely missing
|
|
||||||
/// - 2: The requested audio is only available from first entry to last entry
|
|
||||||
Episode(Vec<&'a Episode>),
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) struct Filter {
|
async fn visit_series(&mut self, series: Series) -> Result<Vec<Season>>;
|
||||||
url_filter: UrlFilter,
|
async fn visit_season(&mut self, season: Season) -> Result<Vec<Episode>>;
|
||||||
|
async fn visit_episode(&mut self, episode: Episode) -> Result<Option<Self::T>>;
|
||||||
|
async fn visit_movie_listing(&mut self, movie_listing: MovieListing) -> Result<Vec<Movie>>;
|
||||||
|
async fn visit_movie(&mut self, movie: Movie) -> Result<Option<Self::T>>;
|
||||||
|
async fn visit_music_video(&mut self, music_video: MusicVideo) -> Result<Option<Self::T>>;
|
||||||
|
async fn visit_concert(&mut self, concert: Concert) -> Result<Option<Self::T>>;
|
||||||
|
|
||||||
skip_specials: bool,
|
async fn visit(mut self, media_collection: MediaCollection) -> Result<Self::Output>
|
||||||
interactive_input: bool,
|
where
|
||||||
|
Self: Send + Sized,
|
||||||
relative_episode_number: bool,
|
{
|
||||||
|
|
||||||
audio_locales: Vec<Locale>,
|
|
||||||
subtitle_locales: Vec<Locale>,
|
|
||||||
|
|
||||||
audios_missing: fn(FilterMediaScope, Vec<&Locale>) -> Result<bool>,
|
|
||||||
subtitles_missing: fn(FilterMediaScope, Vec<&Locale>) -> Result<bool>,
|
|
||||||
no_premium: fn(u32) -> Result<()>,
|
|
||||||
|
|
||||||
is_premium: bool,
|
|
||||||
|
|
||||||
series_visited: bool,
|
|
||||||
season_episodes: HashMap<String, Vec<Episode>>,
|
|
||||||
season_with_premium: Option<Vec<u32>>,
|
|
||||||
season_sorting: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Filter {
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
pub(crate) fn new(
|
|
||||||
url_filter: UrlFilter,
|
|
||||||
audio_locales: Vec<Locale>,
|
|
||||||
subtitle_locales: Vec<Locale>,
|
|
||||||
audios_missing: fn(FilterMediaScope, Vec<&Locale>) -> Result<bool>,
|
|
||||||
subtitles_missing: fn(FilterMediaScope, Vec<&Locale>) -> Result<bool>,
|
|
||||||
no_premium: fn(u32) -> Result<()>,
|
|
||||||
relative_episode_number: bool,
|
|
||||||
interactive_input: bool,
|
|
||||||
skip_specials: bool,
|
|
||||||
is_premium: bool,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
url_filter,
|
|
||||||
audio_locales,
|
|
||||||
subtitle_locales,
|
|
||||||
relative_episode_number,
|
|
||||||
interactive_input,
|
|
||||||
audios_missing,
|
|
||||||
subtitles_missing,
|
|
||||||
no_premium,
|
|
||||||
is_premium,
|
|
||||||
series_visited: false,
|
|
||||||
season_episodes: HashMap::new(),
|
|
||||||
skip_specials,
|
|
||||||
season_with_premium: is_premium.not().then_some(vec![]),
|
|
||||||
season_sorting: vec![],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn visit_series(&mut self, series: Series) -> Result<Vec<Season>> {
|
|
||||||
// the audio locales field isn't always populated
|
|
||||||
if !series.audio_locales.is_empty() {
|
|
||||||
let missing_audios = missing_locales(&series.audio_locales, &self.audio_locales);
|
|
||||||
if !missing_audios.is_empty()
|
|
||||||
&& !(self.audios_missing)(FilterMediaScope::Series(&series), missing_audios)?
|
|
||||||
{
|
|
||||||
return Ok(vec![]);
|
|
||||||
}
|
|
||||||
let missing_subtitles =
|
|
||||||
missing_locales(&series.subtitle_locales, &self.subtitle_locales);
|
|
||||||
if !missing_subtitles.is_empty()
|
|
||||||
&& !(self.subtitles_missing)(FilterMediaScope::Series(&series), missing_subtitles)?
|
|
||||||
{
|
|
||||||
return Ok(vec![]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut seasons = vec![];
|
|
||||||
for season in series.seasons().await? {
|
|
||||||
if !self.url_filter.is_season_valid(season.season_number) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let missing_audios = missing_locales(
|
|
||||||
&season
|
|
||||||
.versions
|
|
||||||
.iter()
|
|
||||||
.map(|l| l.audio_locale.clone())
|
|
||||||
.collect::<Vec<Locale>>(),
|
|
||||||
&self.audio_locales,
|
|
||||||
);
|
|
||||||
if !missing_audios.is_empty()
|
|
||||||
&& !(self.audios_missing)(FilterMediaScope::Season(&season), missing_audios)?
|
|
||||||
{
|
|
||||||
return Ok(vec![]);
|
|
||||||
}
|
|
||||||
seasons.push(season)
|
|
||||||
}
|
|
||||||
|
|
||||||
let duplicated_seasons = get_duplicated_seasons(&seasons);
|
|
||||||
if !duplicated_seasons.is_empty() {
|
|
||||||
if self.interactive_input {
|
|
||||||
check_for_duplicated_seasons(&mut seasons)
|
|
||||||
} else {
|
|
||||||
info!(
|
|
||||||
"Found duplicated seasons: {}",
|
|
||||||
duplicated_seasons
|
|
||||||
.iter()
|
|
||||||
.map(|d| d.to_string())
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.join(", ")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.series_visited = true;
|
|
||||||
|
|
||||||
Ok(seasons)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn visit_season(&mut self, season: Season) -> Result<Vec<Episode>> {
|
|
||||||
if !self.url_filter.is_season_valid(season.season_number) {
|
|
||||||
return Ok(vec![]);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut seasons = vec![];
|
|
||||||
if self
|
|
||||||
.audio_locales
|
|
||||||
.iter()
|
|
||||||
.any(|l| season.audio_locales.contains(l))
|
|
||||||
{
|
|
||||||
seasons.push(season.clone())
|
|
||||||
}
|
|
||||||
for version in season.versions {
|
|
||||||
if season.id == version.id {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if self.audio_locales.contains(&version.audio_locale) {
|
|
||||||
seasons.push(version.season().await?)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut episodes = vec![];
|
|
||||||
for season in seasons {
|
|
||||||
self.season_sorting.push(season.id.clone());
|
|
||||||
let mut eps = season.episodes().await?;
|
|
||||||
|
|
||||||
// removes any episode that does not have the audio locale of the season. yes, this is
|
|
||||||
// the case sometimes
|
|
||||||
if season.audio_locales.len() < 2 {
|
|
||||||
let season_locale = season
|
|
||||||
.audio_locales
|
|
||||||
.first()
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or(Locale::ja_JP);
|
|
||||||
eps.retain(|e| e.audio_locale == season_locale)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::if_same_then_else)]
|
|
||||||
if eps.len() < season.number_of_episodes as usize {
|
|
||||||
if eps.is_empty()
|
|
||||||
&& !(self.audios_missing)(
|
|
||||||
FilterMediaScope::Season(&season),
|
|
||||||
season.audio_locales.iter().collect(),
|
|
||||||
)?
|
|
||||||
{
|
|
||||||
return Ok(vec![]);
|
|
||||||
} else if !eps.is_empty()
|
|
||||||
&& !(self.audios_missing)(
|
|
||||||
FilterMediaScope::Episode(vec![eps.first().unwrap(), eps.last().unwrap()]),
|
|
||||||
vec![&eps.first().unwrap().audio_locale],
|
|
||||||
)?
|
|
||||||
{
|
|
||||||
return Ok(vec![]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
episodes.extend(eps)
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.relative_episode_number {
|
|
||||||
for episode in &episodes {
|
|
||||||
self.season_episodes
|
|
||||||
.entry(episode.season_id.clone())
|
|
||||||
.or_default()
|
|
||||||
.push(episode.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(episodes)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn visit_episode(&mut self, episode: Episode) -> Result<Vec<SingleFormat>> {
|
|
||||||
if !self
|
|
||||||
.url_filter
|
|
||||||
.is_episode_valid(episode.sequence_number, episode.season_number)
|
|
||||||
{
|
|
||||||
return Ok(vec![]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// skip the episode if it's a special
|
|
||||||
if self.skip_specials
|
|
||||||
&& (episode.sequence_number == 0.0 || episode.sequence_number.fract() != 0.0)
|
|
||||||
{
|
|
||||||
return Ok(vec![]);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut episodes = vec![];
|
|
||||||
if !self.series_visited {
|
|
||||||
if self.audio_locales.contains(&episode.audio_locale) {
|
|
||||||
episodes.push(episode.clone())
|
|
||||||
}
|
|
||||||
for version in &episode.versions {
|
|
||||||
// `episode` is also a version of itself. the if block above already adds the
|
|
||||||
// episode if it matches the requested audio, so it doesn't need to be requested
|
|
||||||
// here again
|
|
||||||
if version.id == episode.id {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if self.audio_locales.contains(&version.audio_locale) {
|
|
||||||
episodes.push(version.episode().await?)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let audio_locales: Vec<Locale> =
|
|
||||||
episodes.iter().map(|e| e.audio_locale.clone()).collect();
|
|
||||||
let missing_audios = missing_locales(&audio_locales, &self.audio_locales);
|
|
||||||
if !missing_audios.is_empty()
|
|
||||||
&& !(self.audios_missing)(
|
|
||||||
FilterMediaScope::Episode(vec![&episode]),
|
|
||||||
missing_audios,
|
|
||||||
)?
|
|
||||||
{
|
|
||||||
return Ok(vec![]);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut subtitle_locales: Vec<Locale> = episodes
|
|
||||||
.iter()
|
|
||||||
.flat_map(|e| e.subtitle_locales.clone())
|
|
||||||
.collect();
|
|
||||||
subtitle_locales.sort();
|
|
||||||
subtitle_locales.dedup();
|
|
||||||
let missing_subtitles = missing_locales(&subtitle_locales, &self.subtitle_locales);
|
|
||||||
if !missing_subtitles.is_empty()
|
|
||||||
&& !(self.subtitles_missing)(
|
|
||||||
FilterMediaScope::Episode(vec![&episode]),
|
|
||||||
missing_subtitles,
|
|
||||||
)?
|
|
||||||
{
|
|
||||||
return Ok(vec![]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
episodes.push(episode.clone())
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(seasons_with_premium) = &mut self.season_with_premium {
|
|
||||||
let episodes_len_before = episodes.len();
|
|
||||||
episodes.retain(|e| !e.is_premium_only && !self.is_premium);
|
|
||||||
if episodes_len_before < episodes.len()
|
|
||||||
&& !seasons_with_premium.contains(&episode.season_number)
|
|
||||||
{
|
|
||||||
(self.no_premium)(episode.season_number)?;
|
|
||||||
seasons_with_premium.push(episode.season_number)
|
|
||||||
}
|
|
||||||
|
|
||||||
if episodes.is_empty() {
|
|
||||||
return Ok(vec![]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut relative_episode_number = None;
|
|
||||||
let mut relative_sequence_number = None;
|
|
||||||
if self.relative_episode_number {
|
|
||||||
let season_eps = match self.season_episodes.get(&episode.season_id) {
|
|
||||||
Some(eps) => eps,
|
|
||||||
None => {
|
|
||||||
self.season_episodes.insert(
|
|
||||||
episode.season_id.clone(),
|
|
||||||
episode.season().await?.episodes().await?,
|
|
||||||
);
|
|
||||||
self.season_episodes.get(&episode.season_id).unwrap()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let mut non_integer_sequence_number_count = 0;
|
|
||||||
for (i, ep) in season_eps.iter().enumerate() {
|
|
||||||
if ep.sequence_number != 0.0 || ep.sequence_number.fract() == 0.0 {
|
|
||||||
non_integer_sequence_number_count += 1
|
|
||||||
}
|
|
||||||
if ep.id == episode.id {
|
|
||||||
relative_episode_number = Some(i + 1);
|
|
||||||
relative_sequence_number = Some(
|
|
||||||
(i + 1 - non_integer_sequence_number_count) as f32
|
|
||||||
+ fract(ep.sequence_number),
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if relative_episode_number.is_none() || relative_sequence_number.is_none() {
|
|
||||||
warn!(
|
|
||||||
"Failed to get relative episode number for episode {} ({}) of {} season {}",
|
|
||||||
episode.sequence_number,
|
|
||||||
episode.title,
|
|
||||||
episode.series_title,
|
|
||||||
episode.season_number,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(episodes
|
|
||||||
.into_iter()
|
|
||||||
.map(|e| {
|
|
||||||
SingleFormat::new_from_episode(
|
|
||||||
e.clone(),
|
|
||||||
e.subtitle_locales,
|
|
||||||
relative_episode_number.map(|n| n as u32),
|
|
||||||
relative_sequence_number,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn visit_movie_listing(&mut self, movie_listing: MovieListing) -> Result<Vec<Movie>> {
|
|
||||||
Ok(movie_listing.movies().await?)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn visit_movie(&mut self, movie: Movie) -> Result<Vec<SingleFormat>> {
|
|
||||||
Ok(vec![SingleFormat::new_from_movie(movie, vec![])])
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn visit_music_video(&mut self, music_video: MusicVideo) -> Result<Vec<SingleFormat>> {
|
|
||||||
Ok(vec![SingleFormat::new_from_music_video(music_video)])
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn visit_concert(&mut self, concert: Concert) -> Result<Vec<SingleFormat>> {
|
|
||||||
Ok(vec![SingleFormat::new_from_concert(concert)])
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn finish(self, input: Vec<Vec<SingleFormat>>) -> Result<SingleFormatCollection> {
|
|
||||||
let flatten_input: Vec<SingleFormat> = input.into_iter().flatten().collect();
|
|
||||||
|
|
||||||
let mut single_format_collection = SingleFormatCollection::new();
|
|
||||||
|
|
||||||
let mut pre_sorted: BTreeMap<String, Vec<SingleFormat>> = BTreeMap::new();
|
|
||||||
for data in flatten_input {
|
|
||||||
pre_sorted
|
|
||||||
.entry(data.identifier.clone())
|
|
||||||
.or_default()
|
|
||||||
.push(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut sorted: Vec<(String, Vec<SingleFormat>)> = pre_sorted.into_iter().collect();
|
|
||||||
sorted.sort_by(|(_, a), (_, b)| {
|
|
||||||
self.season_sorting
|
|
||||||
.iter()
|
|
||||||
.position(|p| p == &a.first().unwrap().season_id)
|
|
||||||
.unwrap()
|
|
||||||
.cmp(
|
|
||||||
&self
|
|
||||||
.season_sorting
|
|
||||||
.iter()
|
|
||||||
.position(|p| p == &b.first().unwrap().season_id)
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
for (_, mut data) in sorted {
|
|
||||||
data.sort_by(|a, b| {
|
|
||||||
self.audio_locales
|
|
||||||
.iter()
|
|
||||||
.position(|p| p == &a.audio)
|
|
||||||
.unwrap_or(usize::MAX)
|
|
||||||
.cmp(
|
|
||||||
&self
|
|
||||||
.audio_locales
|
|
||||||
.iter()
|
|
||||||
.position(|p| p == &b.audio)
|
|
||||||
.unwrap_or(usize::MAX),
|
|
||||||
)
|
|
||||||
});
|
|
||||||
single_format_collection.add_single_formats(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(single_format_collection)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) async fn visit(
|
|
||||||
mut self,
|
|
||||||
media_collection: MediaCollection,
|
|
||||||
) -> Result<SingleFormatCollection> {
|
|
||||||
let mut items = vec![media_collection];
|
let mut items = vec![media_collection];
|
||||||
let mut result = vec![];
|
let mut result = vec![];
|
||||||
|
|
||||||
|
|
@ -425,7 +42,9 @@ impl Filter {
|
||||||
.collect::<Vec<MediaCollection>>(),
|
.collect::<Vec<MediaCollection>>(),
|
||||||
),
|
),
|
||||||
MediaCollection::Episode(episode) => {
|
MediaCollection::Episode(episode) => {
|
||||||
result.push(self.visit_episode(episode).await?)
|
if let Some(t) = self.visit_episode(episode).await? {
|
||||||
|
result.push(t)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
MediaCollection::MovieListing(movie_listing) => new_items.extend(
|
MediaCollection::MovieListing(movie_listing) => new_items.extend(
|
||||||
self.visit_movie_listing(movie_listing)
|
self.visit_movie_listing(movie_listing)
|
||||||
|
|
@ -434,12 +53,20 @@ impl Filter {
|
||||||
.map(|m| m.into())
|
.map(|m| m.into())
|
||||||
.collect::<Vec<MediaCollection>>(),
|
.collect::<Vec<MediaCollection>>(),
|
||||||
),
|
),
|
||||||
MediaCollection::Movie(movie) => result.push(self.visit_movie(movie).await?),
|
MediaCollection::Movie(movie) => {
|
||||||
|
if let Some(t) = self.visit_movie(movie).await? {
|
||||||
|
result.push(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
MediaCollection::MusicVideo(music_video) => {
|
MediaCollection::MusicVideo(music_video) => {
|
||||||
result.push(self.visit_music_video(music_video).await?)
|
if let Some(t) = self.visit_music_video(music_video).await? {
|
||||||
|
result.push(t)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
MediaCollection::Concert(concert) => {
|
MediaCollection::Concert(concert) => {
|
||||||
result.push(self.visit_concert(concert).await?)
|
if let Some(t) = self.visit_concert(concert).await? {
|
||||||
|
result.push(t)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -449,10 +76,8 @@ impl Filter {
|
||||||
|
|
||||||
self.finish(result).await
|
self.finish(result).await
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn missing_locales<'a>(available: &[Locale], searched: &'a [Locale]) -> Vec<&'a Locale> {
|
async fn finish(self, input: Vec<Self::T>) -> Result<Self::Output>;
|
||||||
searched.iter().filter(|p| !available.contains(p)).collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove all duplicates from a [`Vec`].
|
/// Remove all duplicates from a [`Vec`].
|
||||||
|
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
use chrono::TimeDelta;
|
|
||||||
|
|
||||||
pub fn format_time_delta(time_delta: &TimeDelta) -> String {
|
|
||||||
let negative = *time_delta < TimeDelta::zero();
|
|
||||||
let time_delta = time_delta.abs();
|
|
||||||
let hours = time_delta.num_hours();
|
|
||||||
let minutes = time_delta.num_minutes() - time_delta.num_hours() * 60;
|
|
||||||
let seconds = time_delta.num_seconds() - time_delta.num_minutes() * 60;
|
|
||||||
let milliseconds = time_delta.num_milliseconds() - time_delta.num_seconds() * 1000;
|
|
||||||
|
|
||||||
format!(
|
|
||||||
"{}{}:{:0>2}:{:0>2}.{:0>3}",
|
|
||||||
if negative { "-" } else { "" },
|
|
||||||
hours,
|
|
||||||
minutes,
|
|
||||||
seconds,
|
|
||||||
milliseconds
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
@ -4,7 +4,7 @@ use crate::utils::log::tab_info;
|
||||||
use crate::utils::os::{is_special_file, sanitize};
|
use crate::utils::os::{is_special_file, sanitize};
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use chrono::{Datelike, Duration};
|
use chrono::{Datelike, Duration};
|
||||||
use crunchyroll_rs::media::{SkipEvents, Stream, StreamData, Subtitle};
|
use crunchyroll_rs::media::{Resolution, SkipEvents, Stream, StreamData, Subtitle};
|
||||||
use crunchyroll_rs::{Concert, Episode, Locale, MediaCollection, Movie, MusicVideo};
|
use crunchyroll_rs::{Concert, Episode, Locale, MediaCollection, Movie, MusicVideo};
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
|
@ -12,7 +12,6 @@ use std::collections::BTreeMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct SingleFormat {
|
pub struct SingleFormat {
|
||||||
pub identifier: String,
|
pub identifier: String,
|
||||||
|
|
@ -168,19 +167,18 @@ impl SingleFormat {
|
||||||
|
|
||||||
pub async fn stream(&self) -> Result<Stream> {
|
pub async fn stream(&self) -> Result<Stream> {
|
||||||
let stream = match &self.source {
|
let stream = match &self.source {
|
||||||
MediaCollection::Episode(e) => e.stream_maybe_without_drm().await,
|
MediaCollection::Episode(e) => e.stream_maybe_without_drm().await?,
|
||||||
MediaCollection::Movie(m) => m.stream_maybe_without_drm().await,
|
MediaCollection::Movie(m) => m.stream_maybe_without_drm().await?,
|
||||||
MediaCollection::MusicVideo(mv) => mv.stream_maybe_without_drm().await,
|
MediaCollection::MusicVideo(mv) => mv.stream_maybe_without_drm().await?,
|
||||||
MediaCollection::Concert(c) => c.stream_maybe_without_drm().await,
|
MediaCollection::Concert(c) => c.stream_maybe_without_drm().await?,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(crunchyroll_rs::error::Error::Request { message, .. }) = &stream {
|
if stream.session.uses_stream_limits {
|
||||||
if message.starts_with("TOO_MANY_ACTIVE_STREAMS") {
|
bail!("Found a stream which probably uses DRM. DRM downloads aren't supported")
|
||||||
bail!("Too many active/parallel streams. Please close at least one stream you're watching and try again")
|
}
|
||||||
}
|
|
||||||
};
|
Ok(stream)
|
||||||
Ok(stream?)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn skip_events(&self) -> Result<Option<SkipEvents>> {
|
pub async fn skip_events(&self) -> Result<Option<SkipEvents>> {
|
||||||
|
|
@ -348,7 +346,6 @@ impl Iterator for SingleFormatCollectionIterator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Format {
|
pub struct Format {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
|
|
@ -356,6 +353,8 @@ pub struct Format {
|
||||||
|
|
||||||
pub locales: Vec<(Locale, Vec<Locale>)>,
|
pub locales: Vec<(Locale, Vec<Locale>)>,
|
||||||
|
|
||||||
|
// deprecated
|
||||||
|
pub resolution: Resolution,
|
||||||
pub width: u64,
|
pub width: u64,
|
||||||
pub height: u64,
|
pub height: u64,
|
||||||
pub fps: f64,
|
pub fps: f64,
|
||||||
|
|
@ -401,6 +400,7 @@ impl Format {
|
||||||
title: first_format.title,
|
title: first_format.title,
|
||||||
description: first_format.description,
|
description: first_format.description,
|
||||||
locales,
|
locales,
|
||||||
|
resolution: first_stream.resolution().unwrap(),
|
||||||
width: first_stream.resolution().unwrap().width,
|
width: first_stream.resolution().unwrap().width,
|
||||||
height: first_stream.resolution().unwrap().height,
|
height: first_stream.resolution().unwrap().height,
|
||||||
fps: first_stream.fps().unwrap(),
|
fps: first_stream.fps().unwrap(),
|
||||||
|
|
@ -448,11 +448,11 @@ impl Format {
|
||||||
)
|
)
|
||||||
.replace(
|
.replace(
|
||||||
"{width}",
|
"{width}",
|
||||||
&sanitize(self.width.to_string(), true, universal),
|
&sanitize(self.resolution.width.to_string(), true, universal),
|
||||||
)
|
)
|
||||||
.replace(
|
.replace(
|
||||||
"{height}",
|
"{height}",
|
||||||
&sanitize(self.height.to_string(), true, universal),
|
&sanitize(self.resolution.height.to_string(), true, universal),
|
||||||
)
|
)
|
||||||
.replace("{series_id}", &sanitize(&self.series_id, true, universal))
|
.replace("{series_id}", &sanitize(&self.series_id, true, universal))
|
||||||
.replace(
|
.replace(
|
||||||
|
|
@ -526,33 +526,7 @@ impl Format {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut path = PathBuf::from(path);
|
PathBuf::from(path)
|
||||||
|
|
||||||
// make sure that every path section has a maximum of 255 characters
|
|
||||||
if path.file_name().unwrap_or_default().to_string_lossy().len() > 255 {
|
|
||||||
let name = path
|
|
||||||
.file_stem()
|
|
||||||
.unwrap_or_default()
|
|
||||||
.to_string_lossy()
|
|
||||||
.to_string();
|
|
||||||
let ext = path
|
|
||||||
.extension()
|
|
||||||
.unwrap_or_default()
|
|
||||||
.to_string_lossy()
|
|
||||||
.to_string();
|
|
||||||
if ext != name {
|
|
||||||
path.set_file_name(format!("{}.{}", &name[..(255 - ext.len() - 1)], ext))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
path.iter()
|
|
||||||
.map(|s| {
|
|
||||||
if s.len() > 255 {
|
|
||||||
s.to_string_lossy()[..255].to_string()
|
|
||||||
} else {
|
|
||||||
s.to_string_lossy().to_string()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn visual_output(&self, dst: &Path) {
|
pub fn visual_output(&self, dst: &Path) {
|
||||||
|
|
@ -588,7 +562,7 @@ impl Format {
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join(", ")
|
.join(", ")
|
||||||
);
|
);
|
||||||
tab_info!("Resolution: {}x{}", self.height, self.width);
|
tab_info!("Resolution: {}", self.resolution);
|
||||||
tab_info!("FPS: {:.2}", self.fps)
|
tab_info!("FPS: {:.2}", self.fps)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ pub mod context;
|
||||||
pub mod download;
|
pub mod download;
|
||||||
pub mod ffmpeg;
|
pub mod ffmpeg;
|
||||||
pub mod filter;
|
pub mod filter;
|
||||||
pub mod fmt;
|
|
||||||
pub mod format;
|
pub mod format;
|
||||||
pub mod interactive_select;
|
pub mod interactive_select;
|
||||||
pub mod locale;
|
pub mod locale;
|
||||||
|
|
@ -11,5 +10,4 @@ pub mod log;
|
||||||
pub mod os;
|
pub mod os;
|
||||||
pub mod parse;
|
pub mod parse;
|
||||||
pub mod rate_limit;
|
pub mod rate_limit;
|
||||||
pub mod sync;
|
|
||||||
pub mod video;
|
pub mod video;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use std::pin::Pin;
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use std::{env, fs, io};
|
use std::{env, fs, io};
|
||||||
use tempfile::{Builder, NamedTempFile, TempPath};
|
use tempfile::{Builder, NamedTempFile, TempDir, TempPath};
|
||||||
use tokio::io::{AsyncRead, ReadBuf};
|
use tokio::io::{AsyncRead, ReadBuf};
|
||||||
|
|
||||||
pub fn has_ffmpeg() -> bool {
|
pub fn has_ffmpeg() -> bool {
|
||||||
|
|
@ -46,6 +46,22 @@ pub fn tempfile<S: AsRef<str>>(suffix: S) -> io::Result<NamedTempFile> {
|
||||||
Ok(tempfile)
|
Ok(tempfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Any tempdir should be created with this function. The prefix and directory of every directory
|
||||||
|
/// created with this function stays the same which is helpful to query all existing tempdirs and
|
||||||
|
/// e.g. remove them in a case of ctrl-c. Having one function also good to prevent mistakes like
|
||||||
|
/// setting the wrong prefix if done manually.
|
||||||
|
pub fn tempdir<S: AsRef<str>>(suffix: S) -> io::Result<TempDir> {
|
||||||
|
let tempdir = Builder::default()
|
||||||
|
.prefix(".crunchy-cli_")
|
||||||
|
.suffix(suffix.as_ref())
|
||||||
|
.tempdir_in(temp_directory())?;
|
||||||
|
debug!(
|
||||||
|
"Created temporary directory: {}",
|
||||||
|
tempdir.path().to_string_lossy()
|
||||||
|
);
|
||||||
|
Ok(tempdir)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn cache_dir<S: AsRef<str>>(name: S) -> io::Result<PathBuf> {
|
pub fn cache_dir<S: AsRef<str>>(name: S) -> io::Result<PathBuf> {
|
||||||
let cache_dir = temp_directory().join(format!(".crunchy-cli_{}_cache", name.as_ref()));
|
let cache_dir = temp_directory().join(format!(".crunchy-cli_{}_cache", name.as_ref()));
|
||||||
fs::create_dir_all(&cache_dir)?;
|
fs::create_dir_all(&cache_dir)?;
|
||||||
|
|
|
||||||
|
|
@ -1,432 +0,0 @@
|
||||||
use std::io::Read;
|
|
||||||
use std::process::Stdio;
|
|
||||||
use std::{
|
|
||||||
cmp,
|
|
||||||
collections::{HashMap, HashSet},
|
|
||||||
mem,
|
|
||||||
ops::Not,
|
|
||||||
path::Path,
|
|
||||||
process::Command,
|
|
||||||
};
|
|
||||||
|
|
||||||
use chrono::TimeDelta;
|
|
||||||
use crunchyroll_rs::Locale;
|
|
||||||
use log::debug;
|
|
||||||
use tempfile::TempPath;
|
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
|
||||||
use rusty_chromaprint::{Configuration, Fingerprinter};
|
|
||||||
|
|
||||||
use super::fmt::format_time_delta;
|
|
||||||
|
|
||||||
pub struct SyncAudio {
|
|
||||||
pub format_id: usize,
|
|
||||||
pub path: TempPath,
|
|
||||||
pub locale: Locale,
|
|
||||||
pub sample_rate: u32,
|
|
||||||
pub video_idx: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
struct TimeRange {
|
|
||||||
start: f64,
|
|
||||||
end: f64,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn sync_audios(
|
|
||||||
available_audios: &Vec<SyncAudio>,
|
|
||||||
sync_tolerance: u32,
|
|
||||||
sync_precision: u32,
|
|
||||||
) -> Result<Option<HashMap<usize, TimeDelta>>> {
|
|
||||||
let mut result: HashMap<usize, TimeDelta> = HashMap::new();
|
|
||||||
|
|
||||||
let mut sync_audios = vec![];
|
|
||||||
let mut chromaprints = HashMap::new();
|
|
||||||
let mut formats = HashSet::new();
|
|
||||||
for audio in available_audios {
|
|
||||||
if formats.contains(&audio.format_id) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
formats.insert(audio.format_id);
|
|
||||||
sync_audios.push((audio.format_id, &audio.path, audio.sample_rate));
|
|
||||||
chromaprints.insert(
|
|
||||||
audio.format_id,
|
|
||||||
generate_chromaprint(
|
|
||||||
&audio.path,
|
|
||||||
audio.sample_rate,
|
|
||||||
&TimeDelta::zero(),
|
|
||||||
&TimeDelta::zero(),
|
|
||||||
&TimeDelta::zero(),
|
|
||||||
)?,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
sync_audios.sort_by_key(|sync_audio| chromaprints.get(&sync_audio.0).unwrap().len());
|
|
||||||
|
|
||||||
let base_audio = sync_audios.remove(0);
|
|
||||||
|
|
||||||
let mut start = f64::MAX;
|
|
||||||
let mut end = f64::MIN;
|
|
||||||
let mut initial_offsets = HashMap::new();
|
|
||||||
for audio in &sync_audios {
|
|
||||||
debug!(
|
|
||||||
"Initial comparison of format {} to {}",
|
|
||||||
audio.0, &base_audio.0
|
|
||||||
);
|
|
||||||
|
|
||||||
let (lhs_ranges, rhs_ranges) = compare_chromaprints(
|
|
||||||
chromaprints.get(&base_audio.0).unwrap(),
|
|
||||||
chromaprints.get(&audio.0).unwrap(),
|
|
||||||
sync_tolerance,
|
|
||||||
);
|
|
||||||
if lhs_ranges.is_empty() || rhs_ranges.is_empty() {
|
|
||||||
bail!(
|
|
||||||
"Failed to sync videos, couldn't find matching audio parts between format {} and {}",
|
|
||||||
base_audio.0 + 1,
|
|
||||||
audio.0 + 1
|
|
||||||
);
|
|
||||||
}
|
|
||||||
let lhs_range = lhs_ranges[0];
|
|
||||||
let rhs_range = rhs_ranges[0];
|
|
||||||
start = start.min(lhs_range.start);
|
|
||||||
end = end.max(lhs_range.end);
|
|
||||||
start = start.min(rhs_range.start);
|
|
||||||
end = end.max(rhs_range.end);
|
|
||||||
let offset = TimeDelta::milliseconds(((rhs_range.start - lhs_range.start) * 1000.0) as i64);
|
|
||||||
initial_offsets.insert(audio.0, TimeDelta::zero().checked_sub(&offset).unwrap());
|
|
||||||
debug!(
|
|
||||||
"Found initial offset of {}ms ({} - {} {}s) ({} - {} {}s) for format {} to {}",
|
|
||||||
offset.num_milliseconds(),
|
|
||||||
lhs_range.start,
|
|
||||||
lhs_range.end,
|
|
||||||
lhs_range.end - lhs_range.start,
|
|
||||||
rhs_range.start,
|
|
||||||
rhs_range.end,
|
|
||||||
rhs_range.end - rhs_range.start,
|
|
||||||
audio.0,
|
|
||||||
base_audio.0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
debug!(
|
|
||||||
"Found matching audio parts at {} - {}, narrowing search",
|
|
||||||
start, end
|
|
||||||
);
|
|
||||||
|
|
||||||
let start = TimeDelta::milliseconds((start * 1000.0) as i64 - 20000);
|
|
||||||
let end = TimeDelta::milliseconds((end * 1000.0) as i64 + 20000);
|
|
||||||
|
|
||||||
for sync_audio in &sync_audios {
|
|
||||||
let chromaprint = generate_chromaprint(
|
|
||||||
sync_audio.1,
|
|
||||||
sync_audio.2,
|
|
||||||
&start,
|
|
||||||
&end,
|
|
||||||
initial_offsets.get(&sync_audio.0).unwrap(),
|
|
||||||
)?;
|
|
||||||
chromaprints.insert(sync_audio.0, chromaprint);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut runs: HashMap<usize, i64> = HashMap::new();
|
|
||||||
let iterator_range_limits: i64 = 2 ^ sync_precision as i64;
|
|
||||||
for i in -iterator_range_limits..=iterator_range_limits {
|
|
||||||
let base_offset = TimeDelta::milliseconds(
|
|
||||||
((0.128 / iterator_range_limits as f64 * i as f64) * 1000.0) as i64,
|
|
||||||
);
|
|
||||||
chromaprints.insert(
|
|
||||||
base_audio.0,
|
|
||||||
generate_chromaprint(base_audio.1, base_audio.2, &start, &end, &base_offset)?,
|
|
||||||
);
|
|
||||||
for audio in &sync_audios {
|
|
||||||
let initial_offset = initial_offsets.get(&audio.0).copied().unwrap();
|
|
||||||
let offset = find_offset(
|
|
||||||
(&base_audio.0, chromaprints.get(&base_audio.0).unwrap()),
|
|
||||||
&base_offset,
|
|
||||||
(&audio.0, chromaprints.get(&audio.0).unwrap()),
|
|
||||||
&initial_offset,
|
|
||||||
&start,
|
|
||||||
sync_tolerance,
|
|
||||||
);
|
|
||||||
if offset.is_none() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let offset = offset.unwrap();
|
|
||||||
|
|
||||||
result.insert(
|
|
||||||
audio.0,
|
|
||||||
result
|
|
||||||
.get(&audio.0)
|
|
||||||
.copied()
|
|
||||||
.unwrap_or_default()
|
|
||||||
.checked_add(&offset)
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
runs.insert(audio.0, runs.get(&audio.0).copied().unwrap_or_default() + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let mut result: HashMap<usize, TimeDelta> = result
|
|
||||||
.iter()
|
|
||||||
.map(|(format_id, offset)| {
|
|
||||||
(
|
|
||||||
*format_id,
|
|
||||||
TimeDelta::milliseconds(
|
|
||||||
offset.num_milliseconds() / runs.get(format_id).copied().unwrap(),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
result.insert(base_audio.0, TimeDelta::milliseconds(0));
|
|
||||||
|
|
||||||
Ok(Some(result))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_offset(
|
|
||||||
lhs: (&usize, &Vec<u32>),
|
|
||||||
lhs_shift: &TimeDelta,
|
|
||||||
rhs: (&usize, &Vec<u32>),
|
|
||||||
rhs_shift: &TimeDelta,
|
|
||||||
start: &TimeDelta,
|
|
||||||
sync_tolerance: u32,
|
|
||||||
) -> Option<TimeDelta> {
|
|
||||||
let (lhs_ranges, rhs_ranges) = compare_chromaprints(lhs.1, rhs.1, sync_tolerance);
|
|
||||||
if lhs_ranges.is_empty() || rhs_ranges.is_empty() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
let lhs_range = lhs_ranges[0];
|
|
||||||
let rhs_range = rhs_ranges[0];
|
|
||||||
let offset = rhs_range.end - lhs_range.end;
|
|
||||||
let offset = TimeDelta::milliseconds((offset * 1000.0) as i64)
|
|
||||||
.checked_add(lhs_shift)?
|
|
||||||
.checked_sub(rhs_shift)?;
|
|
||||||
debug!(
|
|
||||||
"Found offset of {}ms ({} - {} {}s) ({} - {} {}s) for format {} to {}",
|
|
||||||
offset.num_milliseconds(),
|
|
||||||
lhs_range.start + start.num_milliseconds() as f64 / 1000.0,
|
|
||||||
lhs_range.end + start.num_milliseconds() as f64 / 1000.0,
|
|
||||||
lhs_range.end - lhs_range.start,
|
|
||||||
rhs_range.start + start.num_milliseconds() as f64 / 1000.0,
|
|
||||||
rhs_range.end + start.num_milliseconds() as f64 / 1000.0,
|
|
||||||
rhs_range.end - rhs_range.start,
|
|
||||||
rhs.0,
|
|
||||||
lhs.0
|
|
||||||
);
|
|
||||||
Some(offset)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn generate_chromaprint(
|
|
||||||
input_file: &Path,
|
|
||||||
sample_rate: u32,
|
|
||||||
start: &TimeDelta,
|
|
||||||
end: &TimeDelta,
|
|
||||||
offset: &TimeDelta,
|
|
||||||
) -> Result<Vec<u32>> {
|
|
||||||
let mut ss_argument: &TimeDelta = &start.checked_sub(offset).unwrap();
|
|
||||||
let mut offset_argument = &TimeDelta::zero();
|
|
||||||
if *offset < TimeDelta::zero() {
|
|
||||||
ss_argument = start;
|
|
||||||
offset_argument = offset;
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut printer = Fingerprinter::new(&Configuration::preset_test1());
|
|
||||||
printer.start(sample_rate, 2)?;
|
|
||||||
|
|
||||||
let mut command = Command::new("ffmpeg");
|
|
||||||
command
|
|
||||||
.arg("-hide_banner")
|
|
||||||
.arg("-y")
|
|
||||||
.args(["-ss", format_time_delta(ss_argument).as_str()]);
|
|
||||||
|
|
||||||
if end.is_zero().not() {
|
|
||||||
command.args(["-to", format_time_delta(end).as_str()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
command
|
|
||||||
.args(["-itsoffset", format_time_delta(offset_argument).as_str()])
|
|
||||||
.args(["-i", input_file.to_string_lossy().to_string().as_str()])
|
|
||||||
.args(["-ac", "2"])
|
|
||||||
.args([
|
|
||||||
"-f",
|
|
||||||
if cfg!(target_endian = "big") {
|
|
||||||
"s16be"
|
|
||||||
} else {
|
|
||||||
"s16le"
|
|
||||||
},
|
|
||||||
])
|
|
||||||
.arg("-");
|
|
||||||
|
|
||||||
let mut handle = command
|
|
||||||
.stdout(Stdio::piped())
|
|
||||||
.stderr(Stdio::piped())
|
|
||||||
.spawn()?;
|
|
||||||
|
|
||||||
// the stdout is read in chunks because keeping all the raw audio data in memory would take up
|
|
||||||
// a significant amount of space
|
|
||||||
let mut stdout = handle.stdout.take().unwrap();
|
|
||||||
let mut buf: [u8; 128_000] = [0; 128_000];
|
|
||||||
while handle.try_wait()?.is_none() {
|
|
||||||
loop {
|
|
||||||
let read_bytes = stdout.read(&mut buf)?;
|
|
||||||
if read_bytes == 0 {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
let data: [i16; 64_000] = unsafe { mem::transmute(buf) };
|
|
||||||
printer.consume(&data[0..(read_bytes / 2)])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !handle.wait()?.success() {
|
|
||||||
bail!("{}", std::io::read_to_string(handle.stderr.unwrap())?)
|
|
||||||
}
|
|
||||||
|
|
||||||
printer.finish();
|
|
||||||
return Ok(printer.fingerprint().into());
|
|
||||||
}
|
|
||||||
|
|
||||||
fn compare_chromaprints(
|
|
||||||
lhs_chromaprint: &Vec<u32>,
|
|
||||||
rhs_chromaprint: &Vec<u32>,
|
|
||||||
sync_tolerance: u32,
|
|
||||||
) -> (Vec<TimeRange>, Vec<TimeRange>) {
|
|
||||||
let lhs_inverse_index = create_inverse_index(lhs_chromaprint);
|
|
||||||
let rhs_inverse_index = create_inverse_index(rhs_chromaprint);
|
|
||||||
|
|
||||||
let mut possible_shifts = HashSet::new();
|
|
||||||
for lhs_pair in lhs_inverse_index {
|
|
||||||
let original_point = lhs_pair.0;
|
|
||||||
for i in -2..=2 {
|
|
||||||
let modified_point = (original_point as i32 + i) as u32;
|
|
||||||
if rhs_inverse_index.contains_key(&modified_point) {
|
|
||||||
let rhs_index = rhs_inverse_index.get(&modified_point).copied().unwrap();
|
|
||||||
possible_shifts.insert(rhs_index as i32 - lhs_pair.1 as i32);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut all_lhs_time_ranges = vec![];
|
|
||||||
let mut all_rhs_time_ranges = vec![];
|
|
||||||
for shift_amount in possible_shifts {
|
|
||||||
let time_range_pair = find_time_ranges(
|
|
||||||
lhs_chromaprint,
|
|
||||||
rhs_chromaprint,
|
|
||||||
shift_amount,
|
|
||||||
sync_tolerance,
|
|
||||||
);
|
|
||||||
if time_range_pair.is_none() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let (mut lhs_time_ranges, mut rhs_time_ranges) = time_range_pair.unwrap();
|
|
||||||
let mut lhs_time_ranges: Vec<TimeRange> = lhs_time_ranges
|
|
||||||
.drain(..)
|
|
||||||
.filter(|time_range| {
|
|
||||||
(20.0 < (time_range.end - time_range.start))
|
|
||||||
&& ((time_range.end - time_range.start) < 180.0)
|
|
||||||
&& time_range.end > 0.0
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
lhs_time_ranges.sort_by(|a, b| (b.end - b.start).total_cmp(&(a.end - a.start)));
|
|
||||||
let mut rhs_time_ranges: Vec<TimeRange> = rhs_time_ranges
|
|
||||||
.drain(..)
|
|
||||||
.filter(|time_range| {
|
|
||||||
(20.0 < (time_range.end - time_range.start))
|
|
||||||
&& ((time_range.end - time_range.start) < 180.0)
|
|
||||||
&& time_range.end > 0.0
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
rhs_time_ranges.sort_by(|a, b| (b.end - b.start).total_cmp(&(a.end - a.start)));
|
|
||||||
if lhs_time_ranges.is_empty() || rhs_time_ranges.is_empty() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
all_lhs_time_ranges.push(lhs_time_ranges[0]);
|
|
||||||
all_rhs_time_ranges.push(rhs_time_ranges[0]);
|
|
||||||
}
|
|
||||||
all_lhs_time_ranges.sort_by(|a, b| (a.end - a.start).total_cmp(&(b.end - b.start)));
|
|
||||||
all_lhs_time_ranges.reverse();
|
|
||||||
all_rhs_time_ranges.sort_by(|a, b| (a.end - a.start).total_cmp(&(b.end - b.start)));
|
|
||||||
all_rhs_time_ranges.reverse();
|
|
||||||
|
|
||||||
(all_lhs_time_ranges, all_rhs_time_ranges)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn create_inverse_index(chromaprint: &Vec<u32>) -> HashMap<u32, usize> {
|
|
||||||
let mut inverse_index = HashMap::with_capacity(chromaprint.capacity());
|
|
||||||
for (i, fingerprint) in chromaprint.iter().enumerate().take(chromaprint.capacity()) {
|
|
||||||
inverse_index.insert(*fingerprint, i);
|
|
||||||
}
|
|
||||||
inverse_index
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_time_ranges(
|
|
||||||
lhs_chromaprint: &[u32],
|
|
||||||
rhs_chromaprint: &[u32],
|
|
||||||
shift_amount: i32,
|
|
||||||
sync_tolerance: u32,
|
|
||||||
) -> Option<(Vec<TimeRange>, Vec<TimeRange>)> {
|
|
||||||
let mut lhs_shift: i32 = 0;
|
|
||||||
let mut rhs_shift: i32 = 0;
|
|
||||||
if shift_amount < 0 {
|
|
||||||
lhs_shift -= shift_amount;
|
|
||||||
} else {
|
|
||||||
rhs_shift += shift_amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut lhs_matching_timestamps = vec![];
|
|
||||||
let mut rhs_matching_timestamps = vec![];
|
|
||||||
let upper_limit =
|
|
||||||
cmp::min(lhs_chromaprint.len(), rhs_chromaprint.len()) as i32 - shift_amount.abs();
|
|
||||||
|
|
||||||
for i in 0..upper_limit {
|
|
||||||
let lhs_position = i + lhs_shift;
|
|
||||||
let rhs_position = i + rhs_shift;
|
|
||||||
let difference = (lhs_chromaprint[lhs_position as usize]
|
|
||||||
^ rhs_chromaprint[rhs_position as usize])
|
|
||||||
.count_ones();
|
|
||||||
|
|
||||||
if difference > sync_tolerance {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
lhs_matching_timestamps.push(lhs_position as f64 * 0.128);
|
|
||||||
rhs_matching_timestamps.push(rhs_position as f64 * 0.128);
|
|
||||||
}
|
|
||||||
lhs_matching_timestamps.push(f64::MAX);
|
|
||||||
rhs_matching_timestamps.push(f64::MAX);
|
|
||||||
|
|
||||||
let lhs_time_ranges = timestamps_to_ranges(lhs_matching_timestamps);
|
|
||||||
lhs_time_ranges.as_ref()?;
|
|
||||||
let lhs_time_ranges = lhs_time_ranges.unwrap();
|
|
||||||
let rhs_time_ranges = timestamps_to_ranges(rhs_matching_timestamps).unwrap();
|
|
||||||
|
|
||||||
Some((lhs_time_ranges, rhs_time_ranges))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn timestamps_to_ranges(mut timestamps: Vec<f64>) -> Option<Vec<TimeRange>> {
|
|
||||||
if timestamps.is_empty() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
timestamps.sort_by(|a, b| a.total_cmp(b));
|
|
||||||
|
|
||||||
let mut time_ranges = vec![];
|
|
||||||
let mut current_range = TimeRange {
|
|
||||||
start: timestamps[0],
|
|
||||||
end: timestamps[0],
|
|
||||||
};
|
|
||||||
|
|
||||||
for i in 0..timestamps.len() - 1 {
|
|
||||||
let current = timestamps[i];
|
|
||||||
let next = timestamps[i + 1];
|
|
||||||
if next - current <= 1.0 {
|
|
||||||
current_range.end = next;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
time_ranges.push(current_range);
|
|
||||||
current_range.start = next;
|
|
||||||
current_range.end = next;
|
|
||||||
}
|
|
||||||
if !time_ranges.is_empty() {
|
|
||||||
Some(time_ranges)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -5,12 +5,28 @@ use crunchyroll_rs::Locale;
|
||||||
pub async fn stream_data_from_stream(
|
pub async fn stream_data_from_stream(
|
||||||
stream: &Stream,
|
stream: &Stream,
|
||||||
resolution: &Resolution,
|
resolution: &Resolution,
|
||||||
hardsub_subtitle: Option<Locale>,
|
subtitle: Option<Locale>,
|
||||||
) -> Result<Option<(StreamData, StreamData, bool)>> {
|
) -> Result<Option<(StreamData, StreamData, bool)>> {
|
||||||
let (hardsub_locale, mut contains_hardsub) = if hardsub_subtitle.is_some() {
|
// sometimes Crunchyroll marks episodes without real subtitles that they have subtitles and
|
||||||
(hardsub_subtitle, true)
|
// reports that only hardsub episode are existing. the following lines are trying to prevent
|
||||||
|
// potential errors which might get caused by this incorrect reporting
|
||||||
|
// (https://github.com/crunchy-labs/crunchy-cli/issues/231)
|
||||||
|
let mut hardsub_locales: Vec<Locale> = stream.hard_subs.keys().cloned().collect();
|
||||||
|
let (hardsub_locale, mut contains_hardsub) = if !hardsub_locales
|
||||||
|
.contains(&Locale::Custom("".to_string()))
|
||||||
|
&& !hardsub_locales.contains(&Locale::Custom(":".to_string()))
|
||||||
|
{
|
||||||
|
// if only one hardsub locale exists, assume that this stream doesn't really contains hardsubs
|
||||||
|
if hardsub_locales.len() == 1 {
|
||||||
|
(Some(hardsub_locales.remove(0)), false)
|
||||||
|
} else {
|
||||||
|
// fallback to `None`. this should trigger an error message in `stream.dash_streaming_data`
|
||||||
|
// that the requested stream is not available
|
||||||
|
(None, false)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
(None, false)
|
let hardsubs_requested = subtitle.is_some();
|
||||||
|
(subtitle, hardsubs_requested)
|
||||||
};
|
};
|
||||||
|
|
||||||
let (mut videos, mut audios) = match stream.stream_data(hardsub_locale).await {
|
let (mut videos, mut audios) = match stream.stream_data(hardsub_locale).await {
|
||||||
|
|
@ -27,11 +43,6 @@ pub async fn stream_data_from_stream(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
if videos.iter().any(|v| v.drm.is_some()) || audios.iter().any(|v| v.drm.is_some()) {
|
|
||||||
bail!("Stream is DRM protected")
|
|
||||||
}
|
|
||||||
|
|
||||||
videos.sort_by(|a, b| a.bandwidth.cmp(&b.bandwidth).reverse());
|
videos.sort_by(|a, b| a.bandwidth.cmp(&b.bandwidth).reverse());
|
||||||
audios.sort_by(|a, b| a.bandwidth.cmp(&b.bandwidth).reverse());
|
audios.sort_by(|a, b| a.bandwidth.cmp(&b.bandwidth).reverse());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue