From 0115730d608c68d4b54095166d1fabafbf02c476 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Tue, 9 Apr 2024 18:36:18 +0200
Subject: [PATCH 01/65] Add archive `--sync-start` flag documentation to README
---
README.md | 12 +++++++++++-
crunchy-cli-core/src/archive/command.rs | 23 ++++++++++++-----------
2 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/README.md b/README.md
index 5463e30..b30852b 100644
--- a/README.md
+++ b/README.md
@@ -468,7 +468,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
- Merge behavior
- Due to censorship, some episodes have multiple lengths for different languages.
+ Due to censorship or additional intros, some episodes have multiple lengths for different languages.
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.
With the `-m` / `--merge` flag you can define the behaviour when an episodes' video tracks differ in length.
@@ -492,6 +492,16 @@ The `archive` command lets you download episodes with multiple audios and subtit
Default are `200` milliseconds.
+- Sync start
+
+ 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`.
+ 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.
+
+ Default is `7.5`.
+
- Language tagging
You can force the usage of a specific language tagging in the output file with the `--language-tagging` flag.
diff --git a/crunchy-cli-core/src/archive/command.rs b/crunchy-cli-core/src/archive/command.rs
index 234bf68..1c18133 100644
--- a/crunchy-cli-core/src/archive/command.rs
+++ b/crunchy-cli-core/src/archive/command.rs
@@ -89,17 +89,6 @@ pub struct Archive {
#[arg(value_parser = crate::utils::clap::clap_parse_resolution)]
pub(crate) resolution: Resolution,
- #[arg(help = "Tries to sync the timing of all downloaded audios to match one video")]
- #[arg(
- 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, require_equals = true, num_args = 0..=1, default_missing_value = "7.5")]
- pub(crate) sync_start: Option,
#[arg(
help = "Sets the behavior of the stream merging. Valid behaviors are 'auto', 'audio' and 'video'"
)]
@@ -121,6 +110,18 @@ pub struct Archive {
help = "Specified which language tagging the audio and subtitle tracks and language specific format options should have. \
Valid options are: 'default' (how Crunchyroll uses it internally), 'ietf' (according to the IETF standard)"
)]
+ #[arg(help = "Tries to sync the timing of all downloaded audios to match one video")]
+ #[arg(
+ 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, require_equals = true, num_args = 0..=1, default_missing_value = "7.5")]
+ pub(crate) sync_start: Option,
+
#[arg(
long_help = "Specified which language tagging the audio and subtitle tracks and language specific format options should have. \
Valid options are: 'default' (how Crunchyroll uses it internally), 'ietf' (according to the IETF standard; you might run in issues as there are multiple locales which resolve to the same IETF language code, e.g. 'es-LA' and 'es-ES' are both resolving to 'es')"
From a73773ce1deb26e8cf08fe6b7b6f358cdca9e673 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Tue, 9 Apr 2024 18:55:15 +0200
Subject: [PATCH 02/65] Add id to every flag in README
---
README.md | 98 ++++++++++++++++++++++++++++---------------------------
1 file changed, 50 insertions(+), 48 deletions(-)
diff --git a/README.md b/README.md
index b30852b..09db003 100644
--- a/README.md
+++ b/README.md
@@ -116,13 +116,13 @@ crunchy-cli requires you to log in.
Though you can use a non-premium account, you will not have access to premium content without a subscription.
You can authenticate with your credentials (email:password) or by using a refresh token.
-- Credentials
+- Credentials
```shell
$ crunchy-cli --credentials "email:password"
```
-- Refresh Token
+- Refresh Token
To obtain a refresh token, you have to log in at [crunchyroll.com](https://www.crunchyroll.com/) and extract the `etp_rt` cookie.
The easiest way to get it is via a browser extension which lets you export your cookies, like [Cookie-Editor](https://cookie-editor.cgagnier.ca/) ([Firefox](https://addons.mozilla.org/en-US/firefox/addon/cookie-editor/) / [Chrome](https://chrome.google.com/webstore/detail/cookie-editor/hlkenndednhfkekhgcdicdfddnkalmdm)).
@@ -132,7 +132,7 @@ You can authenticate with your credentials (email:password) or by using a refres
$ crunchy-cli --etp-rt "4ebf1690-53a4-491a-a2ac-488309120f5d"
```
-- Stay Anonymous
+- Stay Anonymous
Login without an account (you won't be able to access premium content):
@@ -144,7 +144,7 @@ You can authenticate with your credentials (email:password) or by using a refres
You can set specific settings which will be
-- Verbose output
+- Verbose output
If you want to include debug information in the output, use the `-v` / `--verbose` flag to show it.
@@ -152,9 +152,9 @@ You can set specific settings which will be
$ crunchy-cli -v
```
- This flag can't be used with `-q` / `--quiet`.
+ This flag can't be used in combination with `-q` / `--quiet`.
-- Quiet output
+- Quiet output
If you want to hide all output, use the `-q` / `--quiet` flag to do so.
This is especially useful if you want to pipe the output video to an external program (like a video player).
@@ -163,7 +163,9 @@ You can set specific settings which will be
$ crunchy-cli -q
```
-- Language
+ This flag can't be used in combination with `-v` / `--verbose`.
+
+- Language
By default, the resulting metadata like title or description are shown in your system language (if Crunchyroll supports it, else in English).
If you want to show the results in another language, use the `--lang` flag to set it.
@@ -172,7 +174,7 @@ You can set specific settings which will be
$ crunchy-cli --lang de-DE
```
-- Experimental fixes
+- Experimental fixes
Crunchyroll constantly changes and breaks its services or just delivers incorrect answers.
The `--experimental-fixes` flag tries to fix some of those issues.
@@ -184,7 +186,7 @@ You can set specific settings which will be
For an overview which parts this flag affects, see the [documentation](https://docs.rs/crunchyroll-rs/latest/crunchyroll_rs/crunchyroll/struct.CrunchyrollBuilder.html) of the underlying Crunchyroll library, all functions beginning with `stabilization_` are applied.
-- Proxy
+- Proxy
The `--proxy` flag supports https and socks5 proxies to route all your traffic through.
This may be helpful to bypass the geo-restrictions Crunchyroll has on certain series.
@@ -197,7 +199,7 @@ You can set specific settings which will be
Make sure that proxy can either forward TLS requests, which is needed to bypass the (cloudflare) bot protection, or that it is configured so that the proxy can bypass the protection itself.
-- User Agent
+- User Agent
There might be cases where a custom user agent is necessary, e.g. to bypass the cloudflare bot protection (#104).
In such cases, the `--user-agent` flag can be used to set a custom user agent.
@@ -208,7 +210,7 @@ You can set specific settings which will be
Default is the user agent, defined in the underlying [library](https://github.com/crunchy-labs/crunchyroll-rs).
-- Speed limit
+- Speed limit
If you want to limit how fast requests/downloads should be, you can use the `--speed-limit` flag. Allowed units are `B` (bytes), `KB` (kilobytes) and `MB` (megabytes).
@@ -247,7 +249,7 @@ The `download` command lets you download episodes with a specific audio language
**Options**
-- Audio language
+- Audio language
Set the audio language with the `-a` / `--audio` flag.
This only works if the url points to a series since episode urls are language specific.
@@ -258,7 +260,7 @@ The `download` command lets you download episodes with a specific audio language
Default is your system locale. If not supported by Crunchyroll, `en-US` (American English) is the default.
-- Subtitle language
+- Subtitle language
Besides the audio, you can specify the subtitle language by using the `-s` / `--subtitle` flag.
In formats that support it (.mp4, .mov and .mkv ), subtitles are stored as soft-subs. All other formats are hardsubbed: the subtitles will be burned into the video track (cf. [hardsub](https://www.urbandictionary.com/define.php?term=hardsub)) and thus can not be turned off.
@@ -269,7 +271,7 @@ The `download` command lets you download episodes with a specific audio language
Default is none.
-- Output template
+- Output template
Define an output template by using the `-o` / `--output` flag.
@@ -279,7 +281,7 @@ The `download` command lets you download episodes with a specific audio language
Default is `{title}.mp4`. See the [Template Options section](#output-template-options) below for more options.
-- Output template for special episodes
+- Output template for special episodes
Define an output template which only gets used when the episode is a special (episode number is 0 or has non-zero decimal places) by using the `--output-special` flag.
@@ -289,7 +291,7 @@ The `download` command lets you download episodes with a specific audio language
Default is the template, set by the `-o` / `--output` flag. See the [Template Options section](#output-template-options) below for more options.
-- Universal output
+- Universal output
The output template options can be forced to get sanitized via the `--universal-output` flag to be valid across all supported operating systems (Windows has a lot of characters which aren't allowed in filenames...).
@@ -297,7 +299,7 @@ The `download` command lets you download episodes with a specific audio language
$ crunchy-cli download --universal-output -o https://www.crunchyroll.com/watch/G7PU4XD48/tales-veldoras-journal-2
```
-- Resolution
+- Resolution
The resolution for videos can be set via the `-r` / `--resolution` flag.
@@ -307,7 +309,7 @@ The `download` command lets you download episodes with a specific audio language
Default is `best`.
-- Language tagging
+- Language tagging
You can force the usage of a specific language tagging in the output file with the `--language-tagging` flag.
This might be useful as some video players doesn't recognize the language tagging Crunchyroll uses internally.
@@ -316,7 +318,7 @@ The `download` command lets you download episodes with a specific audio language
$ crunchy-cli download --language-tagging ietf https://www.crunchyroll.com/watch/GRDQPM1ZY/alone-and-lonesome
```
-- FFmpeg Preset
+- FFmpeg Preset
You can specify specific built-in presets with the `--ffmpeg-preset` flag to convert videos to a specific coding while downloading.
Multiple predefined presets how videos should be encoded (h264, h265, av1, ...) are available, you can see them with `crunchy-cli download --help`.
@@ -326,7 +328,7 @@ The `download` command lets you download episodes with a specific audio language
$ crunchy-cli download --ffmpeg-preset av1-lossless https://www.crunchyroll.com/watch/GRDQPM1ZY/alone-and-lonesome
```
-- FFmpeg threads
+- FFmpeg threads
If you want to manually set how many threads FFmpeg should use, you can use the `--ffmpeg-threads` flag. This does not work with every codec/preset and is skipped entirely when specifying custom ffmpeg output arguments instead of a preset for `--ffmpeg-preset`.
@@ -334,7 +336,7 @@ The `download` command lets you download episodes with a specific audio language
$ crunchy-cli download --ffmpeg-threads 4 https://www.crunchyroll.com/watch/GRDQPM1ZY/alone-and-lonesome
```
-- Skip existing
+- Skip existing
If you re-download a series but want to skip episodes you've already downloaded, the `--skip-existing` flag skips the already existing/downloaded files.
@@ -342,7 +344,7 @@ The `download` command lets you download episodes with a specific audio language
$ crunchy-cli download --skip-existing https://www.crunchyroll.com/series/GY8VEQ95Y/darling-in-the-franxx
```
-- Skip specials
+- Skip specials
If you doesn't want to download special episodes, use the `--skip-specials` flag to skip the download of them.
@@ -350,7 +352,7 @@ The `download` command lets you download episodes with a specific audio language
$ crunchy-cli download --skip-specials https://www.crunchyroll.com/series/GYZJ43JMR/that-time-i-got-reincarnated-as-a-slime[S2]
```
-- Include chapters
+- Include chapters
Crunchyroll sometimes provide information about skippable events like the intro or credits.
These information can be stored as chapters in the resulting video file via the `--include-chapters` flag.
@@ -359,7 +361,7 @@ The `download` command lets you download episodes with a specific audio language
$ crunchy-cli download --include-chapters https://www.crunchyroll.com/watch/G0DUND0K2/the-journeys-end
```
-- Yes
+- Yes
Sometimes different seasons have the same season number (e.g. Sword Art Online Alicization and Alicization War of Underworld are both marked as season 3), in such cases an interactive prompt is shown which needs user further user input to decide which season to download.
The `--yes` flag suppresses this interactive prompt and just downloads all seasons.
@@ -370,7 +372,7 @@ The `download` command lets you download episodes with a specific audio language
If you've passed the `-q` / `--quiet` [global flag](#global-settings), this flag is automatically set.
-- Force hardsub
+- Force hardsub
If you want to burn-in the subtitles, even if the output format/container supports soft-subs (e.g. `.mp4`), use the `--force-hardsub` flag to do so.
@@ -378,7 +380,7 @@ The `download` command lets you download episodes with a specific audio language
$ crunchy-cli download --force-hardsub -s en-US https://www.crunchyroll.com/watch/GRDQPM1ZY/alone-and-lonesome
```
-- Threads
+- Threads
To increase the download speed, video segments are downloaded simultaneously by creating multiple threads.
If you want to manually specify how many threads to use when downloading, do this with the `-t` / `--threads` flag.
@@ -406,7 +408,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
**Options**
-- Audio languages
+- Audio languages
Set the audio language with the `-a` / `--audio` flag. Can be used multiple times.
@@ -416,7 +418,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
Default is your system locale (if not supported by Crunchyroll, `en-US` (American English) and `ja-JP` (Japanese) are used).
-- Subtitle languages
+- Subtitle languages
Besides the audio, you can specify the subtitle language by using the `-s` / `--subtitle` flag.
@@ -426,7 +428,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
Default is `all` subtitles.
-- Output template
+- Output template
Define an output template by using the `-o` / `--output` flag.
_crunchy-cli_ exclusively uses the [`.mkv`](https://en.wikipedia.org/wiki/Matroska) container format, because of its ability to store multiple audio, video and subtitle tracks at once.
@@ -437,7 +439,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
Default is `{title}.mkv`. See the [Template Options section](#output-template-options) below for more options.
-- Output template for special episodes
+- Output template for special episodes
Define an output template which only gets used when the episode is a special (episode number is 0 or has non-zero decimal places) by using the `--output-special` flag.
_crunchy-cli_ exclusively uses the [`.mkv`](https://en.wikipedia.org/wiki/Matroska) container format, because of its ability to store multiple audio, video and subtitle tracks at once.
@@ -448,7 +450,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
Default is the template, set by the `-o` / `--output` flag. See the [Template Options section](#output-template-options) below for more options.
-- Universal output
+- Universal output
The output template options can be forced to get sanitized via the `--universal-output` flag to be valid across all supported operating systems (Windows has a lot of characters which aren't allowed in filenames...).
@@ -456,7 +458,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
$ crunchy-cli archive --universal-output -o https://www.crunchyroll.com/watch/G7PU4XD48/tales-veldoras-journal-2
```
-- Resolution
+- Resolution
The resolution for videos can be set via the `-r` / `--resolution` flag.
@@ -466,7 +468,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
Default is `best`.
-- Merge behavior
+- Merge behavior
Due to censorship or additional intros, some episodes have multiple lengths for different languages.
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.
@@ -481,7 +483,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
Default is `auto`.
-- Merge auto tolerance
+- Merge auto tolerance
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-auto-tolerance` flag that only downloads one video if the length difference is in the given range.
@@ -492,7 +494,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
Default are `200` milliseconds.
-- Sync start
+- Sync start
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`.
It tries to sync the timing of all downloaded audios to match one video.
@@ -502,7 +504,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
Default is `7.5`.
-- Language tagging
+- Language tagging
You can force the usage of a specific language tagging in the output file with the `--language-tagging` flag.
This might be useful as some video players doesn't recognize the language tagging Crunchyroll uses internally.
@@ -511,7 +513,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
$ crunchy-cli archive --language-tagging ietf https://www.crunchyroll.com/series/GY8VEQ95Y/darling-in-the-franxx
```
-- FFmpeg Preset
+- FFmpeg Preset
You can specify specific built-in presets with the `--ffmpeg-preset` flag to convert videos to a specific coding while downloading.
Multiple predefined presets how videos should be encoded (h264, h265, av1, ...) are available, you can see them with `crunchy-cli archive --help`.
@@ -521,7 +523,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
$ crunchy-cli archive --ffmpeg-preset av1-lossless https://www.crunchyroll.com/watch/GRDQPM1ZY/alone-and-lonesome
```
-- FFmpeg threads
+- FFmpeg threads
If you want to manually set how many threads FFmpeg should use, you can use the `--ffmpeg-threads` flag. This does not work with every codec/preset and is skipped entirely when specifying custom ffmpeg output arguments instead of a preset for `--ffmpeg-preset`.
@@ -529,7 +531,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
$ crunchy-cli archive --ffmpeg-threads 4 https://www.crunchyroll.com/watch/GRDQPM1ZY/alone-and-lonesome
```
-- Default subtitle
+- Default subtitle
`--default-subtitle` Set which subtitle language is to be flagged as **default** and **forced**.
@@ -539,7 +541,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
Default is none.
-- Include fonts
+- Include fonts
You can include the fonts required by subtitles directly into the output file with the `--include-fonts` flag. This will use the embedded font for subtitles instead of the system font when playing the video in a video player which supports it.
@@ -547,7 +549,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
$ crunchy-cli archive --include-fonts https://www.crunchyroll.com/series/GY8VEQ95Y/darling-in-the-franxx
```
-- Include chapters
+- Include chapters
Crunchyroll sometimes provide information about skippable events like the intro or credits.
These information can be stored as chapters in the resulting video file via the `--include-chapters` flag.
@@ -557,7 +559,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
$ crunchy-cli archive --include-chapters https://www.crunchyroll.com/watch/G0DUND0K2/the-journeys-end
```
-- Skip existing
+- Skip existing
If you re-download a series but want to skip episodes you've already downloaded, the `--skip-existing` flag skips the already existing/downloaded files.
@@ -565,7 +567,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
$ crunchy-cli archive --skip-existing https://www.crunchyroll.com/series/GY8VEQ95Y/darling-in-the-franxx
```
-- Skip existing method
+- Skip existing method
By default, already existing files are determined by their name and the download of the corresponding episode is skipped.
But sometimes Crunchyroll adds dubs or subs to an already existing episode and these changes aren't recognized and `--skip-existing` just skips it.
@@ -575,7 +577,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
$ crunchy-cli archive --skip-existing-method audio --skip-existing-method video https://www.crunchyroll.com/series/GY8VEQ95Y/darling-in-the-franxx
```
-- Skip specials
+- Skip specials
If you doesn't want to download special episodes, use the `--skip-specials` flag to skip the download of them.
@@ -583,7 +585,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
$ crunchy-cli archive --skip-specials https://www.crunchyroll.com/series/GYZJ43JMR/that-time-i-got-reincarnated-as-a-slime[S2]
```
-- Yes
+- Yes
Sometimes different seasons have the same season number (e.g. Sword Art Online Alicization and Alicization War of Underworld are both marked as season 3), in such cases an interactive prompt is shown which needs user further user input to decide which season to download.
The `--yes` flag suppresses this interactive prompt and just downloads all seasons.
@@ -594,7 +596,7 @@ The `archive` command lets you download episodes with multiple audios and subtit
If you've passed the `-q` / `--quiet` [global flag](#global-settings), this flag is automatically set.
-- Threads
+- Threads
To increase the download speed, video segments are downloaded simultaneously by creating multiple threads.
If you want to manually specify how many threads to use when downloading, do this with the `-t` / `--threads` flag.
@@ -628,7 +630,7 @@ _Using this command with the `--anonymous` flag or a non-premium account may ret
**Options**
-- Audio
+- Audio
Set the audio language to search via the `--audio` flag. Can be used multiple times.
@@ -638,7 +640,7 @@ _Using this command with the `--anonymous` flag or a non-premium account may ret
Default is your system locale.
-- Result limit
+- Result limit
If your input is a search term instead of an url, you have multiple options to control which results to process.
The `--search-top-results-limit` flag sets the limit of top search results to process.
From ea39dcbc71b13048dcb27282527bab520ad42df1 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Tue, 9 Apr 2024 18:59:41 +0200
Subject: [PATCH 03/65] Embed chapters only to archive merge auto if
`--sync-start` flag is set
---
crunchy-cli-core/src/archive/command.rs | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/crunchy-cli-core/src/archive/command.rs b/crunchy-cli-core/src/archive/command.rs
index 1c18133..cf0038f 100644
--- a/crunchy-cli-core/src/archive/command.rs
+++ b/crunchy-cli-core/src/archive/command.rs
@@ -585,7 +585,11 @@ async fn get_format(
audios: vec![(audio, single_format.audio.clone())],
subtitles,
metadata: DownloadFormatMetadata {
- skip_events: single_format.skip_events().await?,
+ skip_events: if archive.include_chapters {
+ single_format.skip_events().await?
+ } else {
+ None
+ },
},
},
));
From b9f5fadbb3ac3e6739129971e90e939d157122fa Mon Sep 17 00:00:00 2001
From: bytedream
Date: Tue, 9 Apr 2024 22:50:25 +0200
Subject: [PATCH 04/65] Fix archive `--language-tagging` sometimes causing
crash
---
crunchy-cli-core/src/archive/command.rs | 1 +
1 file changed, 1 insertion(+)
diff --git a/crunchy-cli-core/src/archive/command.rs b/crunchy-cli-core/src/archive/command.rs
index cf0038f..4210828 100644
--- a/crunchy-cli-core/src/archive/command.rs
+++ b/crunchy-cli-core/src/archive/command.rs
@@ -126,6 +126,7 @@ pub struct Archive {
long_help = "Specified which language tagging the audio and subtitle tracks and language specific format options should have. \
Valid options are: 'default' (how Crunchyroll uses it internally), 'ietf' (according to the IETF standard; you might run in issues as there are multiple locales which resolve to the same IETF language code, e.g. 'es-LA' and 'es-ES' are both resolving to 'es')"
)]
+ #[arg(long)]
#[arg(value_parser = LanguageTagging::parse)]
pub(crate) language_tagging: Option,
From 9e5feef4d41c1f3085c6009018c8b6c8f020cfa1 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Tue, 9 Apr 2024 22:58:28 +0200
Subject: [PATCH 05/65] Change archive `--sync-start` defaults
---
crunchy-cli-core/src/utils/download.rs | 36 ++++++++++++--------------
1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/crunchy-cli-core/src/utils/download.rs b/crunchy-cli-core/src/utils/download.rs
index 122d436..85fe3dc 100644
--- a/crunchy-cli-core/src/utils/download.rs
+++ b/crunchy-cli-core/src/utils/download.rs
@@ -1527,13 +1527,13 @@ struct SyncVideo {
fn sync_videos(mut sync_videos: Vec, value: f64) -> Result
From ab63dcd2e010cccd4b5a99c48d6576fa6c22d664 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Mon, 6 May 2024 20:29:22 +0200
Subject: [PATCH 41/65] Update dependencies and version
---
Cargo.lock | 30 +++++++++++++++---------------
Cargo.toml | 2 +-
crunchy-cli-core/Cargo.toml | 4 ++--
3 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index b9dce7b..44a47cd 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -92,9 +92,9 @@ dependencies = [
[[package]]
name = "anyhow"
-version = "1.0.82"
+version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519"
+checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3"
[[package]]
name = "async-speed-limit"
@@ -188,9 +188,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
[[package]]
name = "cc"
-version = "1.0.96"
+version = "1.0.97"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "065a29261d53ba54260972629f9ca6bffa69bac13cd1fed61420f7fa68b9f8bd"
+checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4"
[[package]]
name = "cfg-if"
@@ -343,7 +343,7 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]]
name = "crunchy-cli"
-version = "3.6.0"
+version = "3.6.1"
dependencies = [
"chrono",
"clap",
@@ -356,7 +356,7 @@ dependencies = [
[[package]]
name = "crunchy-cli-core"
-version = "3.6.0"
+version = "3.6.1"
dependencies = [
"anyhow",
"async-speed-limit",
@@ -712,9 +712,9 @@ dependencies = [
[[package]]
name = "getrandom"
-version = "0.2.14"
+version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c"
+checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"js-sys",
@@ -1511,9 +1511,9 @@ checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316"
[[package]]
name = "rsubs-lib"
-version = "0.2.0"
+version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0df7559a05635a4132b737c736ee286af83f3969cb98d9028d17d333e6b41cc5"
+checksum = "9dcca2a9560fca05de8f95bc3767e46673d4b4c1f2c7a11092e10efd95bbdf62"
dependencies = [
"regex",
"serde",
@@ -1646,11 +1646,11 @@ dependencies = [
[[package]]
name = "security-framework"
-version = "2.10.0"
+version = "2.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6"
+checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0"
dependencies = [
- "bitflags 1.3.2",
+ "bitflags 2.5.0",
"core-foundation",
"core-foundation-sys",
"libc",
@@ -1659,9 +1659,9 @@ dependencies = [
[[package]]
name = "security-framework-sys"
-version = "2.10.0"
+version = "2.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef"
+checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7"
dependencies = [
"core-foundation-sys",
"libc",
diff --git a/Cargo.toml b/Cargo.toml
index fe7b301..26f71f3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "crunchy-cli"
authors = ["Crunchy Labs Maintainers"]
-version = "3.6.0"
+version = "3.6.1"
edition = "2021"
license = "MIT"
diff --git a/crunchy-cli-core/Cargo.toml b/crunchy-cli-core/Cargo.toml
index 896b68f..8e1ba3a 100644
--- a/crunchy-cli-core/Cargo.toml
+++ b/crunchy-cli-core/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "crunchy-cli-core"
authors = ["Crunchy Labs Maintainers"]
-version = "3.6.0"
+version = "3.6.1"
edition = "2021"
license = "MIT"
@@ -30,7 +30,7 @@ log = { version = "0.4", features = ["std"] }
num_cpus = "1.16"
regex = "1.10"
reqwest = { version = "0.12", features = ["socks", "stream"] }
-rsubs-lib = "0.2"
+rsubs-lib = ">=0.2.1"
rusty-chromaprint = "0.2"
serde = "1.0"
serde_json = "1.0"
From 53a710a3732047a1e08d475f6f112b440b8bde8e Mon Sep 17 00:00:00 2001
From: Simon <47527944+Frooastside@users.noreply.github.com>
Date: Tue, 7 May 2024 16:13:10 +0200
Subject: [PATCH 42/65] Fix audio syncing using wrong internal index (#407)
---
crunchy-cli-core/src/utils/download.rs | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/crunchy-cli-core/src/utils/download.rs b/crunchy-cli-core/src/utils/download.rs
index 565ed7d..8a8ad57 100644
--- a/crunchy-cli-core/src/utils/download.rs
+++ b/crunchy-cli-core/src/utils/download.rs
@@ -321,8 +321,6 @@ impl Downloader {
if let Some(offsets) = offsets {
let mut root_format_idx = 0;
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() {
let offset = offsets.get(&i).copied().unwrap_or_default();
let format_len = format
@@ -340,15 +338,13 @@ impl Downloader {
for _ in &format.audios {
if let Some(offset) = &offsets.get(&i) {
- audio_offsets.insert(audio_count, **offset);
+ audio_offsets.insert(i, **offset);
}
- audio_count += 1
}
for _ in &format.subtitles {
if let Some(offset) = &offsets.get(&i) {
- subtitle_offsets.insert(subtitle_count, **offset);
+ subtitle_offsets.insert(i, **offset);
}
- subtitle_count += 1
}
}
From 48bb7a5ef669d3d89ccecfbf02929adeea99a6bd Mon Sep 17 00:00:00 2001
From: bytedream
Date: Tue, 14 May 2024 16:11:55 +0200
Subject: [PATCH 43/65] Fix crashes when converting subtitles (#408)
---
Cargo.lock | 6 ++--
crunchy-cli-core/Cargo.toml | 3 +-
crunchy-cli-core/src/utils/download.rs | 39 ++++++++++++++++----------
3 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 44a47cd..cd1f282 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -386,6 +386,7 @@ dependencies = [
"shlex",
"sys-locale",
"tempfile",
+ "time",
"tokio",
"tokio-util",
"tower-service",
@@ -1511,12 +1512,13 @@ checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316"
[[package]]
name = "rsubs-lib"
-version = "0.2.1"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9dcca2a9560fca05de8f95bc3767e46673d4b4c1f2c7a11092e10efd95bbdf62"
+checksum = "f43e1a7f184bc76407dbaa67bd2aeea8a15430d7e1e498070963336d03ebedee"
dependencies = [
"regex",
"serde",
+ "time",
]
[[package]]
diff --git a/crunchy-cli-core/Cargo.toml b/crunchy-cli-core/Cargo.toml
index 8e1ba3a..49f7a5e 100644
--- a/crunchy-cli-core/Cargo.toml
+++ b/crunchy-cli-core/Cargo.toml
@@ -30,7 +30,7 @@ log = { version = "0.4", features = ["std"] }
num_cpus = "1.16"
regex = "1.10"
reqwest = { version = "0.12", features = ["socks", "stream"] }
-rsubs-lib = ">=0.2.1"
+rsubs-lib = "0.3"
rusty-chromaprint = "0.2"
serde = "1.0"
serde_json = "1.0"
@@ -38,6 +38,7 @@ serde_plain = "1.0"
shlex = "1.3"
sys-locale = "0.3"
tempfile = "3.10"
+time = "0.3"
tokio = { version = "1.37", features = ["io-util", "macros", "net", "rt-multi-thread", "time"] }
tokio-util = "0.7"
tower-service = "0.3"
diff --git a/crunchy-cli-core/src/utils/download.rs b/crunchy-cli-core/src/utils/download.rs
index 8a8ad57..43d165b 100644
--- a/crunchy-cli-core/src/utils/download.rs
+++ b/crunchy-cli-core/src/utils/download.rs
@@ -13,17 +13,19 @@ use indicatif::{ProgressBar, ProgressDrawTarget, ProgressFinish, ProgressStyle};
use log::{debug, warn, LevelFilter};
use regex::Regex;
use reqwest::Client;
-use rsubs_lib::{ssa, vtt};
+use rsubs_lib::{SSA, VTT};
use std::borrow::Borrow;
use std::cmp::Ordering;
use std::collections::{BTreeMap, HashMap};
use std::io::Write;
+use std::ops::Add;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::sync::Arc;
use std::time::Duration;
use std::{env, fs};
use tempfile::TempPath;
+use time::Time;
use tokio::io::{AsyncBufReadExt, AsyncReadExt, BufReader};
use tokio::select;
use tokio::sync::mpsc::unbounded_channel;
@@ -929,36 +931,43 @@ impl Downloader {
) -> Result {
let buf = subtitle.data().await?;
let mut ass = match subtitle.format.as_str() {
- "ass" => ssa::parse(String::from_utf8_lossy(&buf).to_string()),
- "vtt" => vtt::parse(String::from_utf8_lossy(&buf).to_string()).to_ass(),
+ "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
- ass.events
- .sort_by(|a, b| a.line_start.total_ms().cmp(&b.line_start.total_ms()));
+ // (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 maxim
+ // 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() {
- if ass.events[i].line_end.total_ms() > max_length.num_milliseconds() as u32 {
- if ass.events[i].line_start.total_ms() > max_length.num_milliseconds() as u32 {
- ass.events[i]
- .line_start
- .set_ms(max_length.num_milliseconds() as u32);
+ 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]
- .line_end
- .set_ms(max_length.num_milliseconds() as u32);
+ 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("ScaledBorderAndShadows".to_string(), "yes".to_string());
+
let tempfile = tempfile(".ass")?;
let path = tempfile.into_temp_path();
- ass.to_file(path.to_string_lossy().to_string().as_str())?;
+ fs::write(&path, ass.to_string())?;
Ok(path)
}
From 817963af4fbf0eef1fde26a02f0771e343ce35d9 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Tue, 14 May 2024 21:22:23 +0200
Subject: [PATCH 44/65] Fix video containing hardsub if not requested (#415)
---
crunchy-cli-core/src/download/command.rs | 20 ++++++++++++++------
crunchy-cli-core/src/utils/video.rs | 24 ++++--------------------
2 files changed, 18 insertions(+), 26 deletions(-)
diff --git a/crunchy-cli-core/src/download/command.rs b/crunchy-cli-core/src/download/command.rs
index bb0c1fd..a9c3acf 100644
--- a/crunchy-cli-core/src/download/command.rs
+++ b/crunchy-cli-core/src/download/command.rs
@@ -384,12 +384,20 @@ async fn get_format(
let subtitle = if contains_hardsub {
None
} else if let Some(subtitle_locale) = &download.subtitle {
- stream
- .subtitles
- .get(subtitle_locale)
- .cloned()
- // use closed captions as fallback if no actual subtitles are found
- .or_else(|| stream.captions.get(subtitle_locale).cloned())
+ if download.audio == Locale::ja_JP {
+ stream
+ .subtitles
+ .get(subtitle_locale)
+ // use closed captions as fallback if no actual subtitles are found
+ .or_else(|| stream.captions.get(subtitle_locale))
+ .cloned()
+ } else {
+ stream
+ .captions
+ .get(subtitle_locale)
+ .or_else(|| stream.subtitles.get(subtitle_locale))
+ .cloned()
+ }
} else {
None
};
diff --git a/crunchy-cli-core/src/utils/video.rs b/crunchy-cli-core/src/utils/video.rs
index 07f6e76..8b25791 100644
--- a/crunchy-cli-core/src/utils/video.rs
+++ b/crunchy-cli-core/src/utils/video.rs
@@ -5,28 +5,12 @@ use crunchyroll_rs::Locale;
pub async fn stream_data_from_stream(
stream: &Stream,
resolution: &Resolution,
- subtitle: Option,
+ hardsub_subtitle: Option,
) -> Result
> {
- // sometimes Crunchyroll marks episodes without real subtitles that they have subtitles and
- // 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 = 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)
- }
+ let (hardsub_locale, mut contains_hardsub) = if hardsub_subtitle.is_some() {
+ (hardsub_subtitle, true)
} else {
- let hardsubs_requested = subtitle.is_some();
- (subtitle, hardsubs_requested)
+ (None, false)
};
let (mut videos, mut audios) = match stream.stream_data(hardsub_locale).await {
From 590242712b00c90c6c4cd49744764a1b04b64789 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Tue, 14 May 2024 21:36:12 +0200
Subject: [PATCH 45/65] Add warning message the `--skip-existing-method` has no
effect without `--skip-existing` (#418)
---
crunchy-cli-core/src/archive/command.rs | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/crunchy-cli-core/src/archive/command.rs b/crunchy-cli-core/src/archive/command.rs
index 38bddc1..44a30de 100644
--- a/crunchy-cli-core/src/archive/command.rs
+++ b/crunchy-cli-core/src/archive/command.rs
@@ -234,6 +234,10 @@ impl Execute for Archive {
bail!("`--include-chapters` can only be used if `--merge` is set to 'audio' or 'sync'")
}
+ if !self.skip_existing_method.is_empty() && !self.skip_existing {
+ warn!("`--skip-existing-method` has no effect if `--skip-existing` is not set")
+ }
+
self.audio = all_locale_in_locales(self.audio.clone());
self.subtitle = all_locale_in_locales(self.subtitle.clone());
From a98e31f959892fed57a0510356a0c6a47a5c8672 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Tue, 14 May 2024 22:36:59 +0200
Subject: [PATCH 46/65] Only include one CC subtitle
---
crunchy-cli-core/src/archive/command.rs | 31 +++++++++++--------------
1 file changed, 14 insertions(+), 17 deletions(-)
diff --git a/crunchy-cli-core/src/archive/command.rs b/crunchy-cli-core/src/archive/command.rs
index 44a30de..113447f 100644
--- a/crunchy-cli-core/src/archive/command.rs
+++ b/crunchy-cli-core/src/archive/command.rs
@@ -501,24 +501,21 @@ async fn get_format(
.subtitle
.iter()
.flat_map(|s| {
- let subtitles = stream
- .subtitles
- .get(s)
- .cloned()
- // the subtitle is probably cc if the audio is not japanese or only one
- // subtitle exists for this stream
- .map(|l| {
- (
- l,
- single_format.audio != Locale::ja_JP && stream.subtitles.len() == 1,
- )
- });
- let cc = stream.captions.get(s).cloned().map(|l| (l, true));
-
+ let mut subtitles = vec![];
+ if let Some(caption) = stream.captions.get(s) {
+ subtitles.push((caption.clone(), true))
+ }
+ if let Some(subtitle) = stream.subtitles.get(s) {
+ // the subtitle is probably cc if the audio is not japanese or only one subtitle
+ // exists for this stream
+ 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
+ // not cc
+ if subtitles.is_empty() || !cc {
+ subtitles.push((subtitle.clone(), cc))
+ }
+ }
subtitles
- .into_iter()
- .chain(cc.into_iter())
- .collect::>()
})
.collect();
From 5279a9b75910992ad1731557ad65ce4302bb9208 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Tue, 14 May 2024 23:42:37 +0200
Subject: [PATCH 47/65] Update dependencies and version
---
Cargo.lock | 57 +++++++++++++++++++------------------
Cargo.toml | 2 +-
crunchy-cli-core/Cargo.toml | 2 +-
3 files changed, 31 insertions(+), 30 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index cd1f282..198afc9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -343,7 +343,7 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]]
name = "crunchy-cli"
-version = "3.6.1"
+version = "3.6.2"
dependencies = [
"chrono",
"clap",
@@ -356,7 +356,7 @@ dependencies = [
[[package]]
name = "crunchy-cli-core"
-version = "3.6.1"
+version = "3.6.2"
dependencies = [
"anyhow",
"async-speed-limit",
@@ -476,12 +476,13 @@ dependencies = [
[[package]]
name = "dash-mpd"
-version = "0.16.1"
+version = "0.16.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "79b4bdd5f1c0c7493d780c645f0bff5b9361e6408210fa88910adb181efca64c"
+checksum = "876a00c22923799ac46365eb528c10134f979bf58ced5e3113de5b98d9835290"
dependencies = [
"base64 0.22.1",
"base64-serde",
+ "bytes",
"chrono",
"fs-err",
"iso8601",
@@ -581,9 +582,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "errno"
-version = "0.3.8"
+version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245"
+checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba"
dependencies = [
"libc",
"windows-sys 0.52.0",
@@ -1156,9 +1157,9 @@ dependencies = [
[[package]]
name = "num-complex"
-version = "0.4.5"
+version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6"
+checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
dependencies = [
"num-traits",
]
@@ -1345,9 +1346,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
-version = "1.0.81"
+version = "1.0.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba"
+checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b"
dependencies = [
"unicode-ident",
]
@@ -1535,9 +1536,9 @@ dependencies = [
[[package]]
name = "rustc-demangle"
-version = "0.1.23"
+version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
+checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
[[package]]
name = "rustfft"
@@ -1606,9 +1607,9 @@ dependencies = [
[[package]]
name = "rustls-pki-types"
-version = "1.5.0"
+version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "beb461507cee2c2ff151784c52762cf4d9ff6a61f3e80968600ed24fa837fa54"
+checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d"
[[package]]
name = "rustls-webpki"
@@ -1633,9 +1634,9 @@ dependencies = [
[[package]]
name = "ryu"
-version = "1.0.17"
+version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
+checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
[[package]]
name = "schannel"
@@ -1671,18 +1672,18 @@ dependencies = [
[[package]]
name = "serde"
-version = "1.0.200"
+version = "1.0.201"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ddc6f9cc94d67c0e21aaf7eda3a010fd3af78ebf6e096aa6e2e13c79749cce4f"
+checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
-version = "1.0.200"
+version = "1.0.201"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "856f046b9400cee3c8c94ed572ecdb752444c24528c035cd35882aad6f492bcb"
+checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865"
dependencies = [
"proc-macro2",
"quote",
@@ -1691,9 +1692,9 @@ dependencies = [
[[package]]
name = "serde_json"
-version = "1.0.116"
+version = "1.0.117"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813"
+checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3"
dependencies = [
"itoa",
"ryu",
@@ -1841,9 +1842,9 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
[[package]]
name = "syn"
-version = "2.0.60"
+version = "2.0.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3"
+checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704"
dependencies = [
"proc-macro2",
"quote",
@@ -1900,18 +1901,18 @@ dependencies = [
[[package]]
name = "thiserror"
-version = "1.0.59"
+version = "1.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa"
+checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
-version = "1.0.59"
+version = "1.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66"
+checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524"
dependencies = [
"proc-macro2",
"quote",
diff --git a/Cargo.toml b/Cargo.toml
index 26f71f3..1a1c76f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "crunchy-cli"
authors = ["Crunchy Labs Maintainers"]
-version = "3.6.1"
+version = "3.6.2"
edition = "2021"
license = "MIT"
diff --git a/crunchy-cli-core/Cargo.toml b/crunchy-cli-core/Cargo.toml
index 49f7a5e..f3388f7 100644
--- a/crunchy-cli-core/Cargo.toml
+++ b/crunchy-cli-core/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "crunchy-cli-core"
authors = ["Crunchy Labs Maintainers"]
-version = "3.6.1"
+version = "3.6.2"
edition = "2021"
license = "MIT"
From 9819b622594e3cb2164aedcef71827618b421c41 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Fri, 17 May 2024 23:45:41 +0200
Subject: [PATCH 48/65] Fix typo in additional subtitle field (#421)
---
crunchy-cli-core/src/utils/download.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/crunchy-cli-core/src/utils/download.rs b/crunchy-cli-core/src/utils/download.rs
index 43d165b..d54b0bc 100644
--- a/crunchy-cli-core/src/utils/download.rs
+++ b/crunchy-cli-core/src/utils/download.rs
@@ -962,7 +962,7 @@ impl Downloader {
// (https://github.com/crunchy-labs/crunchy-cli/issues/66)
ass.info
.additional_fields
- .insert("ScaledBorderAndShadows".to_string(), "yes".to_string());
+ .insert("ScaledBorderAndShadow".to_string(), "yes".to_string());
let tempfile = tempfile(".ass")?;
let path = tempfile.into_temp_path();
From 301dac478f177b70723672effa3f2651ff8419d1 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Mon, 20 May 2024 15:57:28 +0200
Subject: [PATCH 49/65] Update dependencies and version
---
Cargo.lock | 99 ++++++++++++++++++-------------------
Cargo.toml | 5 +-
crunchy-cli-core/Cargo.toml | 2 +-
3 files changed, 53 insertions(+), 53 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 198afc9..140125d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -92,9 +92,9 @@ dependencies = [
[[package]]
name = "anyhow"
-version = "1.0.83"
+version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3"
+checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
[[package]]
name = "async-speed-limit"
@@ -119,6 +119,12 @@ dependencies = [
"syn",
]
+[[package]]
+name = "atomic-waker"
+version = "1.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
+
[[package]]
name = "autocfg"
version = "1.3.0"
@@ -188,9 +194,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
[[package]]
name = "cc"
-version = "1.0.97"
+version = "1.0.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4"
+checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f"
[[package]]
name = "cfg-if"
@@ -238,7 +244,7 @@ dependencies = [
"anstream",
"anstyle",
"clap_lex",
- "strsim 0.11.1",
+ "strsim",
]
[[package]]
@@ -343,7 +349,7 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]]
name = "crunchy-cli"
-version = "3.6.2"
+version = "3.6.3"
dependencies = [
"chrono",
"clap",
@@ -356,7 +362,7 @@ dependencies = [
[[package]]
name = "crunchy-cli-core"
-version = "3.6.2"
+version = "3.6.3"
dependencies = [
"anyhow",
"async-speed-limit",
@@ -441,9 +447,9 @@ dependencies = [
[[package]]
name = "darling"
-version = "0.20.8"
+version = "0.20.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "54e36fcd13ed84ffdfda6f5be89b31287cbb80c439841fe69e04841435464391"
+checksum = "83b2eb4d90d12bdda5ed17de686c2acb4c57914f8f921b8da7e112b5a36f3fe1"
dependencies = [
"darling_core",
"darling_macro",
@@ -451,23 +457,23 @@ dependencies = [
[[package]]
name = "darling_core"
-version = "0.20.8"
+version = "0.20.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9c2cf1c23a687a1feeb728783b993c4e1ad83d99f351801977dd809b48d0a70f"
+checksum = "622687fe0bac72a04e5599029151f5796111b90f1baaa9b544d807a5e31cd120"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
- "strsim 0.10.0",
+ "strsim",
"syn",
]
[[package]]
name = "darling_macro"
-version = "0.20.8"
+version = "0.20.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f"
+checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178"
dependencies = [
"darling_core",
"quote",
@@ -555,9 +561,9 @@ dependencies = [
[[package]]
name = "either"
-version = "1.11.0"
+version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2"
+checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b"
[[package]]
name = "encode_unicode"
@@ -733,15 +739,15 @@ checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]]
name = "h2"
-version = "0.4.4"
+version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "816ec7294445779408f36fe57bc5b7fc1cf59664059096c65f905c1c61f58069"
+checksum = "fa82e28a107a8cc405f0839610bdc9b15f1e25ec7d696aa5cf173edbcb1486ab"
dependencies = [
+ "atomic-waker",
"bytes",
"fnv",
"futures-core",
"futures-sink",
- "futures-util",
"http",
"indexmap 2.2.6",
"slab",
@@ -979,9 +985,9 @@ dependencies = [
[[package]]
name = "instant"
-version = "0.1.12"
+version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
+checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222"
dependencies = [
"cfg-if",
]
@@ -1043,9 +1049,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
-version = "0.2.154"
+version = "0.2.155"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346"
+checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
[[package]]
name = "libredox"
@@ -1059,9 +1065,9 @@ dependencies = [
[[package]]
name = "linux-raw-sys"
-version = "0.4.13"
+version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c"
+checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
[[package]]
name = "log"
@@ -1099,9 +1105,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
-version = "0.7.2"
+version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7"
+checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae"
dependencies = [
"adler",
]
@@ -1120,7 +1126,7 @@ dependencies = [
[[package]]
name = "native-tls"
version = "0.2.11"
-source = "git+https://github.com/crunchy-labs/rust-not-so-native-tls.git?rev=fdba246#fdba246a79986607cbdf573733445498bb6da2a9"
+source = "git+https://github.com/crunchy-labs/rust-not-so-native-tls.git?rev=b7969a8#b7969a88210096e0570e29d42fb13533baf62aa6"
dependencies = [
"libc",
"log",
@@ -1346,9 +1352,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
-version = "1.0.82"
+version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b"
+checksum = "0b33eb56c327dec362a9e55b3ad14f9d2f0904fb5a5b03b513ab5465399e9f43"
dependencies = [
"unicode-ident",
]
@@ -1514,8 +1520,7 @@ checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316"
[[package]]
name = "rsubs-lib"
version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f43e1a7f184bc76407dbaa67bd2aeea8a15430d7e1e498070963336d03ebedee"
+source = "git+https://github.com/crunchy-labs/rsubs-lib.git?rev=1c51f60#1c51f60b8c48f1a8f7b261372b237d89bdc17dd4"
dependencies = [
"regex",
"serde",
@@ -1613,9 +1618,9 @@ checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d"
[[package]]
name = "rustls-webpki"
-version = "0.102.3"
+version = "0.102.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f3bce581c0dd41bce533ce695a1437fa16a7ab5ac3ccfa99fe1a620a7885eabf"
+checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e"
dependencies = [
"ring",
"rustls-pki-types",
@@ -1672,18 +1677,18 @@ dependencies = [
[[package]]
name = "serde"
-version = "1.0.201"
+version = "1.0.202"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c"
+checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
-version = "1.0.201"
+version = "1.0.202"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865"
+checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838"
dependencies = [
"proc-macro2",
"quote",
@@ -1822,12 +1827,6 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe895eb47f22e2ddd4dabc02bce419d2e643c8e3b585c78158b349195bc24d82"
-[[package]]
-name = "strsim"
-version = "0.10.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
-
[[package]]
name = "strsim"
version = "0.11.1"
@@ -1842,9 +1841,9 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
[[package]]
name = "syn"
-version = "2.0.63"
+version = "2.0.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704"
+checksum = "d2863d96a84c6439701d7a38f9de935ec562c8832cc55d1dde0f513b52fad106"
dependencies = [
"proc-macro2",
"quote",
@@ -1901,18 +1900,18 @@ dependencies = [
[[package]]
name = "thiserror"
-version = "1.0.60"
+version = "1.0.61"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18"
+checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
-version = "1.0.60"
+version = "1.0.61"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524"
+checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533"
dependencies = [
"proc-macro2",
"quote",
diff --git a/Cargo.toml b/Cargo.toml
index 1a1c76f..4021ebc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "crunchy-cli"
authors = ["Crunchy Labs Maintainers"]
-version = "3.6.2"
+version = "3.6.3"
edition = "2021"
license = "MIT"
@@ -34,7 +34,8 @@ members = ["crunchy-cli-core"]
[patch.crates-io]
# 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
-native-tls = { git = "https://github.com/crunchy-labs/rust-not-so-native-tls.git", rev = "fdba246" }
+native-tls = { git = "https://github.com/crunchy-labs/rust-not-so-native-tls.git", rev = "b7969a8" }
+rsubs-lib = { git = "https://github.com/crunchy-labs/rsubs-lib.git", rev = "1c51f60" }
[profile.release]
strip = true
diff --git a/crunchy-cli-core/Cargo.toml b/crunchy-cli-core/Cargo.toml
index f3388f7..4b4416b 100644
--- a/crunchy-cli-core/Cargo.toml
+++ b/crunchy-cli-core/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "crunchy-cli-core"
authors = ["Crunchy Labs Maintainers"]
-version = "3.6.2"
+version = "3.6.3"
edition = "2021"
license = "MIT"
From f7ce888329825470a42e13cf6c0dd35826783d6c Mon Sep 17 00:00:00 2001
From: bytedream
Date: Tue, 21 May 2024 21:33:08 +0200
Subject: [PATCH 50/65] Bypass stream limits
---
crunchy-cli-core/src/archive/command.rs | 4 ++-
crunchy-cli-core/src/download/command.rs | 2 ++
crunchy-cli-core/src/utils/format.rs | 32 +++++++++++++++---------
3 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/crunchy-cli-core/src/archive/command.rs b/crunchy-cli-core/src/archive/command.rs
index 113447f..d34c4b7 100644
--- a/crunchy-cli-core/src/archive/command.rs
+++ b/crunchy-cli-core/src/archive/command.rs
@@ -520,7 +520,9 @@ async fn get_format(
.collect();
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![];
diff --git a/crunchy-cli-core/src/download/command.rs b/crunchy-cli-core/src/download/command.rs
index a9c3acf..fcf069b 100644
--- a/crunchy-cli-core/src/download/command.rs
+++ b/crunchy-cli-core/src/download/command.rs
@@ -434,5 +434,7 @@ async fn get_format(
subs.push(download.subtitle.clone().unwrap())
}
+ stream.invalidate().await?;
+
Ok((download_format, format))
}
diff --git a/crunchy-cli-core/src/utils/format.rs b/crunchy-cli-core/src/utils/format.rs
index 0a71838..325c731 100644
--- a/crunchy-cli-core/src/utils/format.rs
+++ b/crunchy-cli-core/src/utils/format.rs
@@ -2,7 +2,7 @@ use crate::utils::filter::real_dedup_vec;
use crate::utils::locale::LanguageTagging;
use crate::utils::log::tab_info;
use crate::utils::os::{is_special_file, sanitize};
-use anyhow::{bail, Result};
+use anyhow::Result;
use chrono::{Datelike, Duration};
use crunchyroll_rs::media::{Resolution, SkipEvents, Stream, StreamData, Subtitle};
use crunchyroll_rs::{Concert, Episode, Locale, MediaCollection, Movie, MusicVideo};
@@ -166,19 +166,27 @@ impl SingleFormat {
}
pub async fn stream(&self) -> Result {
- let stream = match &self.source {
- MediaCollection::Episode(e) => e.stream_maybe_without_drm().await?,
- MediaCollection::Movie(m) => m.stream_maybe_without_drm().await?,
- MediaCollection::MusicVideo(mv) => mv.stream_maybe_without_drm().await?,
- MediaCollection::Concert(c) => c.stream_maybe_without_drm().await?,
- _ => unreachable!(),
- };
+ let mut i = 0;
+ loop {
+ let stream = match &self.source {
+ MediaCollection::Episode(e) => e.stream_maybe_without_drm().await,
+ MediaCollection::Movie(m) => m.stream_maybe_without_drm().await,
+ MediaCollection::MusicVideo(mv) => mv.stream_maybe_without_drm().await,
+ MediaCollection::Concert(c) => c.stream_maybe_without_drm().await,
+ _ => unreachable!(),
+ };
- if stream.session.uses_stream_limits {
- bail!("Found a stream which probably uses DRM. DRM downloads aren't supported")
+ // sometimes the request to get streams fails with an 403 and the message "JWT error",
+ // even if the jwt (i guess the auth bearer token is meant by that) is perfectly valid.
+ // it's retried the request 3 times if this specific error occurs
+ if let Err(crunchyroll_rs::error::Error::Request { message, .. }) = &stream {
+ if message == "JWT error" && i < 3 {
+ i += 1;
+ continue;
+ }
+ };
+ return Ok(stream?);
}
-
- Ok(stream)
}
pub async fn skip_events(&self) -> Result
> {
From cbe57e2b6e6262c5a94312a9646faea3a9f23ccb Mon Sep 17 00:00:00 2001
From: bytedream
Date: Tue, 21 May 2024 21:34:05 +0200
Subject: [PATCH 51/65] Update dependencies and version
---
Cargo.lock | 12 ++++++------
Cargo.toml | 2 +-
crunchy-cli-core/Cargo.toml | 2 +-
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 140125d..5ea720f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -349,7 +349,7 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]]
name = "crunchy-cli"
-version = "3.6.3"
+version = "3.6.4"
dependencies = [
"chrono",
"clap",
@@ -362,7 +362,7 @@ dependencies = [
[[package]]
name = "crunchy-cli-core"
-version = "3.6.3"
+version = "3.6.4"
dependencies = [
"anyhow",
"async-speed-limit",
@@ -482,9 +482,9 @@ dependencies = [
[[package]]
name = "dash-mpd"
-version = "0.16.2"
+version = "0.16.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "876a00c22923799ac46365eb528c10134f979bf58ced5e3113de5b98d9835290"
+checksum = "4618a5e165bf47b084963611bcf1d568c681f52d8a237e8862a0cd8c546ba255"
dependencies = [
"base64 0.22.1",
"base64-serde",
@@ -1259,9 +1259,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-src"
-version = "300.2.3+3.2.1"
+version = "300.3.0+3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5cff92b6f71555b61bb9315f7c64da3ca43d87531622120fea0195fc761b4843"
+checksum = "eba8804a1c5765b18c4b3f907e6897ebabeedebc9830e1a0046c4a4cf44663e1"
dependencies = [
"cc",
]
diff --git a/Cargo.toml b/Cargo.toml
index 4021ebc..98d2269 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "crunchy-cli"
authors = ["Crunchy Labs Maintainers"]
-version = "3.6.3"
+version = "3.6.4"
edition = "2021"
license = "MIT"
diff --git a/crunchy-cli-core/Cargo.toml b/crunchy-cli-core/Cargo.toml
index 4b4416b..8370fdc 100644
--- a/crunchy-cli-core/Cargo.toml
+++ b/crunchy-cli-core/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "crunchy-cli-core"
authors = ["Crunchy Labs Maintainers"]
-version = "3.6.3"
+version = "3.6.4"
edition = "2021"
license = "MIT"
From f8bd0929872f4c78a6d2b54eee7dacb4c94cfb9d Mon Sep 17 00:00:00 2001
From: bytedream
Date: Tue, 21 May 2024 21:51:18 +0200
Subject: [PATCH 52/65] Add custom error message if too many streams are active
---
crunchy-cli-core/src/utils/format.rs | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/crunchy-cli-core/src/utils/format.rs b/crunchy-cli-core/src/utils/format.rs
index 325c731..436be78 100644
--- a/crunchy-cli-core/src/utils/format.rs
+++ b/crunchy-cli-core/src/utils/format.rs
@@ -2,7 +2,7 @@ use crate::utils::filter::real_dedup_vec;
use crate::utils::locale::LanguageTagging;
use crate::utils::log::tab_info;
use crate::utils::os::{is_special_file, sanitize};
-use anyhow::Result;
+use anyhow::{bail, Result};
use chrono::{Datelike, Duration};
use crunchyroll_rs::media::{Resolution, SkipEvents, Stream, StreamData, Subtitle};
use crunchyroll_rs::{Concert, Episode, Locale, MediaCollection, Movie, MusicVideo};
@@ -176,13 +176,15 @@ impl SingleFormat {
_ => unreachable!(),
};
- // sometimes the request to get streams fails with an 403 and the message "JWT error",
- // even if the jwt (i guess the auth bearer token is meant by that) is perfectly valid.
- // it's retried the request 3 times if this specific error occurs
if let Err(crunchyroll_rs::error::Error::Request { message, .. }) = &stream {
+ // sometimes the request to get streams fails with an 403 and the message
+ // "JWT error", even if the jwt (i guess the auth bearer token is meant by that) is
+ // perfectly valid. it's retried the request 3 times if this specific error occurs
if message == "JWT error" && i < 3 {
i += 1;
continue;
+ } else if message.starts_with("TOO_MANY_ACTIVE_STREAMS") {
+ bail!("Too many active/parallel streams. Please close at least one stream you're watching and try again")
}
};
return Ok(stream?);
From 5593046aae4c399c1f0568c14ff35f3d75d96edc Mon Sep 17 00:00:00 2001
From: bytedream
Date: Wed, 22 May 2024 16:52:43 +0200
Subject: [PATCH 53/65] Update dependencies and version
---
Cargo.lock | 12 ++++++------
Cargo.toml | 2 +-
crunchy-cli-core/Cargo.toml | 4 ++--
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 5ea720f..b24bc20 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -349,7 +349,7 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]]
name = "crunchy-cli"
-version = "3.6.4"
+version = "3.6.5"
dependencies = [
"chrono",
"clap",
@@ -362,7 +362,7 @@ dependencies = [
[[package]]
name = "crunchy-cli-core"
-version = "3.6.4"
+version = "3.6.5"
dependencies = [
"anyhow",
"async-speed-limit",
@@ -400,9 +400,9 @@ dependencies = [
[[package]]
name = "crunchyroll-rs"
-version = "0.11.1"
+version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "58580acc9c0abf96a231ec8b1a4597ea55d9426ea17f684ce3582e2b26437bbb"
+checksum = "7a6754d10e1890089eb733b71aee6f4cbc18374040aedb04c4ca76020bcd9818"
dependencies = [
"async-trait",
"chrono",
@@ -426,9 +426,9 @@ dependencies = [
[[package]]
name = "crunchyroll-rs-internal"
-version = "0.11.1"
+version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ce3c844dec8a3390f8c9853b5cf1d65c3d38fd0657b8b5d0e008db8945dea326"
+checksum = "ca15fa827cca647852b091006f2b592f8727e1082f812b475b3f9ebe3f59d5bf"
dependencies = [
"darling",
"quote",
diff --git a/Cargo.toml b/Cargo.toml
index 98d2269..ccf80ec 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "crunchy-cli"
authors = ["Crunchy Labs Maintainers"]
-version = "3.6.4"
+version = "3.6.5"
edition = "2021"
license = "MIT"
diff --git a/crunchy-cli-core/Cargo.toml b/crunchy-cli-core/Cargo.toml
index 8370fdc..98ff9d7 100644
--- a/crunchy-cli-core/Cargo.toml
+++ b/crunchy-cli-core/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "crunchy-cli-core"
authors = ["Crunchy Labs Maintainers"]
-version = "3.6.4"
+version = "3.6.5"
edition = "2021"
license = "MIT"
@@ -16,7 +16,7 @@ anyhow = "1.0"
async-speed-limit = "0.4"
clap = { version = "4.5", features = ["derive", "string"] }
chrono = "0.4"
-crunchyroll-rs = { version = "0.11.1", features = ["experimental-stabilizations", "tower"] }
+crunchyroll-rs = { version = "0.11.2", features = ["experimental-stabilizations", "tower"] }
ctrlc = "3.4"
dialoguer = { version = "0.11", default-features = false }
dirs = "5.0"
From 7d2ae719c8fee83f2ba5041f214b87eb53d3c33c Mon Sep 17 00:00:00 2001
From: bytedream
Date: Wed, 22 May 2024 16:54:58 +0200
Subject: [PATCH 54/65] Remove internal jwt error retry
---
crunchy-cli-core/src/utils/format.rs | 35 +++++++++++-----------------
1 file changed, 13 insertions(+), 22 deletions(-)
diff --git a/crunchy-cli-core/src/utils/format.rs b/crunchy-cli-core/src/utils/format.rs
index 436be78..c5e8f3d 100644
--- a/crunchy-cli-core/src/utils/format.rs
+++ b/crunchy-cli-core/src/utils/format.rs
@@ -166,29 +166,20 @@ impl SingleFormat {
}
pub async fn stream(&self) -> Result {
- let mut i = 0;
- loop {
- let stream = match &self.source {
- MediaCollection::Episode(e) => e.stream_maybe_without_drm().await,
- MediaCollection::Movie(m) => m.stream_maybe_without_drm().await,
- MediaCollection::MusicVideo(mv) => mv.stream_maybe_without_drm().await,
- MediaCollection::Concert(c) => c.stream_maybe_without_drm().await,
- _ => unreachable!(),
- };
+ let stream = match &self.source {
+ MediaCollection::Episode(e) => e.stream_maybe_without_drm().await,
+ MediaCollection::Movie(m) => m.stream_maybe_without_drm().await,
+ MediaCollection::MusicVideo(mv) => mv.stream_maybe_without_drm().await,
+ MediaCollection::Concert(c) => c.stream_maybe_without_drm().await,
+ _ => unreachable!(),
+ };
- if let Err(crunchyroll_rs::error::Error::Request { message, .. }) = &stream {
- // sometimes the request to get streams fails with an 403 and the message
- // "JWT error", even if the jwt (i guess the auth bearer token is meant by that) is
- // perfectly valid. it's retried the request 3 times if this specific error occurs
- if message == "JWT error" && i < 3 {
- i += 1;
- continue;
- } else if message.starts_with("TOO_MANY_ACTIVE_STREAMS") {
- bail!("Too many active/parallel streams. Please close at least one stream you're watching and try again")
- }
- };
- return Ok(stream?);
- }
+ if let Err(crunchyroll_rs::error::Error::Request { message, .. }) = &stream {
+ if message.starts_with("TOO_MANY_ACTIVE_STREAMS") {
+ bail!("Too many active/parallel streams. Please close at least one stream you're watching and try again")
+ }
+ };
+ Ok(stream?)
}
pub async fn skip_events(&self) -> Result
> {
From 74e5e05b0f8b4cb83cd5708747fe81a0183b56f0 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Wed, 22 May 2024 23:59:12 +0200
Subject: [PATCH 55/65] Invalidate stream when using search command (#428)
---
crunchy-cli-core/src/search/format.rs | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/crunchy-cli-core/src/search/format.rs b/crunchy-cli-core/src/search/format.rs
index 7ea84d8..ee855b2 100644
--- a/crunchy-cli-core/src/search/format.rs
+++ b/crunchy-cli-core/src/search/format.rs
@@ -464,7 +464,9 @@ impl Format {
if !stream_empty {
for (_, episodes) in tree.iter_mut() {
for (episode, streams) in episodes {
- streams.push(episode.stream_maybe_without_drm().await?)
+ let stream = episode.stream_maybe_without_drm().await?;
+ stream.clone().invalidate().await?;
+ streams.push(stream)
}
}
} else {
From a1c7b2069d79ecc634e3ba216fb86e63135d9501 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Thu, 23 May 2024 00:01:42 +0200
Subject: [PATCH 56/65] Update dependencies and version
---
Cargo.lock | 17 +++++++++--------
Cargo.toml | 3 +--
crunchy-cli-core/Cargo.toml | 6 +++---
3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index b24bc20..8400022 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -349,7 +349,7 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]]
name = "crunchy-cli"
-version = "3.6.5"
+version = "3.6.6"
dependencies = [
"chrono",
"clap",
@@ -362,7 +362,7 @@ dependencies = [
[[package]]
name = "crunchy-cli-core"
-version = "3.6.5"
+version = "3.6.6"
dependencies = [
"anyhow",
"async-speed-limit",
@@ -400,9 +400,9 @@ dependencies = [
[[package]]
name = "crunchyroll-rs"
-version = "0.11.2"
+version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7a6754d10e1890089eb733b71aee6f4cbc18374040aedb04c4ca76020bcd9818"
+checksum = "1d33b8d77c80dea79e66993cb67963b2171dcf0b8fbc87591c58f2dadfea8da2"
dependencies = [
"async-trait",
"chrono",
@@ -426,9 +426,9 @@ dependencies = [
[[package]]
name = "crunchyroll-rs-internal"
-version = "0.11.2"
+version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ca15fa827cca647852b091006f2b592f8727e1082f812b475b3f9ebe3f59d5bf"
+checksum = "fa51945265f25c45f7d53bd70e5263dd023c0be45e38eaba886a971cb645d797"
dependencies = [
"darling",
"quote",
@@ -1519,8 +1519,9 @@ checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316"
[[package]]
name = "rsubs-lib"
-version = "0.3.0"
-source = "git+https://github.com/crunchy-labs/rsubs-lib.git?rev=1c51f60#1c51f60b8c48f1a8f7b261372b237d89bdc17dd4"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d01f7609f0b1bc4fe24b352e8d1792c7d71cc43aea797e14b87974cd009ab402"
dependencies = [
"regex",
"serde",
diff --git a/Cargo.toml b/Cargo.toml
index ccf80ec..f263e59 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "crunchy-cli"
authors = ["Crunchy Labs Maintainers"]
-version = "3.6.5"
+version = "3.6.6"
edition = "2021"
license = "MIT"
@@ -35,7 +35,6 @@ members = ["crunchy-cli-core"]
# 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
native-tls = { git = "https://github.com/crunchy-labs/rust-not-so-native-tls.git", rev = "b7969a8" }
-rsubs-lib = { git = "https://github.com/crunchy-labs/rsubs-lib.git", rev = "1c51f60" }
[profile.release]
strip = true
diff --git a/crunchy-cli-core/Cargo.toml b/crunchy-cli-core/Cargo.toml
index 98ff9d7..56964ec 100644
--- a/crunchy-cli-core/Cargo.toml
+++ b/crunchy-cli-core/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "crunchy-cli-core"
authors = ["Crunchy Labs Maintainers"]
-version = "3.6.5"
+version = "3.6.6"
edition = "2021"
license = "MIT"
@@ -16,7 +16,7 @@ anyhow = "1.0"
async-speed-limit = "0.4"
clap = { version = "4.5", features = ["derive", "string"] }
chrono = "0.4"
-crunchyroll-rs = { version = "0.11.2", features = ["experimental-stabilizations", "tower"] }
+crunchyroll-rs = { version = "0.11.3", features = ["experimental-stabilizations", "tower"] }
ctrlc = "3.4"
dialoguer = { version = "0.11", default-features = false }
dirs = "5.0"
@@ -30,7 +30,7 @@ log = { version = "0.4", features = ["std"] }
num_cpus = "1.16"
regex = "1.10"
reqwest = { version = "0.12", features = ["socks", "stream"] }
-rsubs-lib = "0.3"
+rsubs-lib = "~0.3.1"
rusty-chromaprint = "0.2"
serde = "1.0"
serde_json = "1.0"
From 67c267be2005d18d39c814087db905a801d41fc5 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Fri, 24 May 2024 22:05:04 +0200
Subject: [PATCH 57/65] Remove unused variable
---
crunchy-cli-core/src/utils/format.rs | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/crunchy-cli-core/src/utils/format.rs b/crunchy-cli-core/src/utils/format.rs
index c5e8f3d..f0a002c 100644
--- a/crunchy-cli-core/src/utils/format.rs
+++ b/crunchy-cli-core/src/utils/format.rs
@@ -4,7 +4,7 @@ use crate::utils::log::tab_info;
use crate::utils::os::{is_special_file, sanitize};
use anyhow::{bail, Result};
use chrono::{Datelike, Duration};
-use crunchyroll_rs::media::{Resolution, SkipEvents, Stream, StreamData, Subtitle};
+use crunchyroll_rs::media::{SkipEvents, Stream, StreamData, Subtitle};
use crunchyroll_rs::{Concert, Episode, Locale, MediaCollection, Movie, MusicVideo};
use log::{debug, info};
use std::cmp::Ordering;
@@ -354,8 +354,6 @@ pub struct Format {
pub locales: Vec<(Locale, Vec)>,
- // deprecated
- pub resolution: Resolution,
pub width: u64,
pub height: u64,
pub fps: f64,
@@ -401,7 +399,6 @@ impl Format {
title: first_format.title,
description: first_format.description,
locales,
- resolution: first_stream.resolution().unwrap(),
width: first_stream.resolution().unwrap().width,
height: first_stream.resolution().unwrap().height,
fps: first_stream.fps().unwrap(),
@@ -449,11 +446,11 @@ impl Format {
)
.replace(
"{width}",
- &sanitize(self.resolution.width.to_string(), true, universal),
+ &sanitize(self.width.to_string(), true, universal),
)
.replace(
"{height}",
- &sanitize(self.resolution.height.to_string(), true, universal),
+ &sanitize(self.height.to_string(), true, universal),
)
.replace("{series_id}", &sanitize(&self.series_id, true, universal))
.replace(
@@ -589,7 +586,7 @@ impl Format {
.collect::>()
.join(", ")
);
- tab_info!("Resolution: {}", self.resolution);
+ tab_info!("Resolution: {}x{}", self.height, self.width);
tab_info!("FPS: {:.2}", self.fps)
}
From fb8e53564442653bcaa972bf8143066b42cb49d3 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Fri, 24 May 2024 22:09:23 +0200
Subject: [PATCH 58/65] Fix subtitle title not being human-readable
---
crunchy-cli-core/src/utils/download.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/crunchy-cli-core/src/utils/download.rs b/crunchy-cli-core/src/utils/download.rs
index d54b0bc..accefce 100644
--- a/crunchy-cli-core/src/utils/download.rs
+++ b/crunchy-cli-core/src/utils/download.rs
@@ -654,7 +654,7 @@ impl Downloader {
metadata.extend([
format!("-metadata:s:s:{}", i),
format!("title={}", {
- let mut title = meta.locale.to_string();
+ let mut title = meta.locale.to_human_readable();
if meta.cc {
title += " (CC)"
}
From e7ac6d8874418c3311d433855f5991ea6f0be187 Mon Sep 17 00:00:00 2001
From: bytedream
Date: Fri, 24 May 2024 22:17:25 +0200
Subject: [PATCH 59/65] Deprecate search stream.is_drm option
---
crunchy-cli-core/src/search/command.rs | 4 ++++
crunchy-cli-core/src/search/format.rs | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/crunchy-cli-core/src/search/command.rs b/crunchy-cli-core/src/search/command.rs
index c29ce34..8032bed 100644
--- a/crunchy-cli-core/src/search/command.rs
+++ b/crunchy-cli-core/src/search/command.rs
@@ -111,6 +111,10 @@ impl Execute for Search {
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() {
match parse_url(&ctx.crunchy, self.input.clone(), true).await {
Ok(ok) => vec![ok],
diff --git a/crunchy-cli-core/src/search/format.rs b/crunchy-cli-core/src/search/format.rs
index ee855b2..10f4624 100644
--- a/crunchy-cli-core/src/search/format.rs
+++ b/crunchy-cli-core/src/search/format.rs
@@ -173,7 +173,7 @@ impl From<&Stream> for FormatStream {
Self {
locale: value.audio_locale.clone(),
dash_url: value.url.clone(),
- is_drm: value.session.uses_stream_limits,
+ is_drm: false,
}
}
}
From 287df843828e106d4fef2661c796ffaa69742caf Mon Sep 17 00:00:00 2001
From: bytedream
Date: Fri, 14 Jun 2024 00:17:08 +0200
Subject: [PATCH 60/65] Rework episode filtering
---
Cargo.lock | 16 +-
crunchy-cli-core/Cargo.toml | 2 +-
crunchy-cli-core/src/archive/command.rs | 47 ++-
crunchy-cli-core/src/archive/filter.rs | 466 -----------------------
crunchy-cli-core/src/archive/mod.rs | 1 -
crunchy-cli-core/src/download/command.rs | 53 ++-
crunchy-cli-core/src/download/filter.rs | 307 ---------------
crunchy-cli-core/src/download/mod.rs | 1 -
crunchy-cli-core/src/search/format.rs | 28 +-
crunchy-cli-core/src/utils/filter.rs | 425 +++++++++++++++++++--
crunchy-cli-core/src/utils/format.rs | 2 +
11 files changed, 515 insertions(+), 833 deletions(-)
delete mode 100644 crunchy-cli-core/src/archive/filter.rs
delete mode 100644 crunchy-cli-core/src/download/filter.rs
diff --git a/Cargo.lock b/Cargo.lock
index 8400022..7fdb3d9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -400,9 +400,9 @@ dependencies = [
[[package]]
name = "crunchyroll-rs"
-version = "0.11.3"
+version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1d33b8d77c80dea79e66993cb67963b2171dcf0b8fbc87591c58f2dadfea8da2"
+checksum = "d6e38c223aecf65c9c9bec50764beea5dc70b6c97cd7f767bf6860f2fc8e0a07"
dependencies = [
"async-trait",
"chrono",
@@ -426,9 +426,9 @@ dependencies = [
[[package]]
name = "crunchyroll-rs-internal"
-version = "0.11.3"
+version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fa51945265f25c45f7d53bd70e5263dd023c0be45e38eaba886a971cb645d797"
+checksum = "144a38040a21aaa456741a9f6749354527bb68ad3bb14210e0bbc40fbd95186c"
dependencies = [
"darling",
"quote",
@@ -1967,9 +1967,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
-version = "1.37.0"
+version = "1.38.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787"
+checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a"
dependencies = [
"backtrace",
"bytes",
@@ -1984,9 +1984,9 @@ dependencies = [
[[package]]
name = "tokio-macros"
-version = "2.2.0"
+version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
+checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a"
dependencies = [
"proc-macro2",
"quote",
diff --git a/crunchy-cli-core/Cargo.toml b/crunchy-cli-core/Cargo.toml
index 56964ec..5c7b901 100644
--- a/crunchy-cli-core/Cargo.toml
+++ b/crunchy-cli-core/Cargo.toml
@@ -16,7 +16,7 @@ anyhow = "1.0"
async-speed-limit = "0.4"
clap = { version = "4.5", features = ["derive", "string"] }
chrono = "0.4"
-crunchyroll-rs = { version = "0.11.3", features = ["experimental-stabilizations", "tower"] }
+crunchyroll-rs = { version = "0.11.4", features = ["experimental-stabilizations", "tower"] }
ctrlc = "3.4"
dialoguer = { version = "0.11", default-features = false }
dirs = "5.0"
diff --git a/crunchy-cli-core/src/archive/command.rs b/crunchy-cli-core/src/archive/command.rs
index d34c4b7..0d1b3a4 100644
--- a/crunchy-cli-core/src/archive/command.rs
+++ b/crunchy-cli-core/src/archive/command.rs
@@ -1,10 +1,9 @@
-use crate::archive::filter::ArchiveFilter;
use crate::utils::context::Context;
use crate::utils::download::{
DownloadBuilder, DownloadFormat, DownloadFormatMetadata, MergeBehavior,
};
use crate::utils::ffmpeg::FFmpegPreset;
-use crate::utils::filter::Filter;
+use crate::utils::filter::{Filter, FilterMediaScope};
use crate::utils::format::{Format, SingleFormat};
use crate::utils::locale::{all_locale_in_locales, resolve_locales, LanguageTagging};
use crate::utils::log::progress;
@@ -284,9 +283,49 @@ impl Execute for Archive {
for (i, (media_collection, url_filter)) in parsed_urls.into_iter().enumerate() {
let progress_handler = progress!("Fetching series details");
- let single_format_collection = ArchiveFilter::new(
+ let single_format_collection = Filter::new(
url_filter,
- self.clone(),
+ self.audio.clone(),
+ self.subtitle.clone(),
+ |scope, locales| {
+ let audios = locales.into_iter().map(|l| l.to_string()).collect::>().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::>().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.skip_specials,
ctx.crunchy.premium().await,
diff --git a/crunchy-cli-core/src/archive/filter.rs b/crunchy-cli-core/src/archive/filter.rs
deleted file mode 100644
index b08fb6c..0000000
--- a/crunchy-cli-core/src/archive/filter.rs
+++ /dev/null
@@ -1,466 +0,0 @@
-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>,
- season_subtitles_missing: Vec,
- seasons_with_premium: Option>,
- season_sorting: Vec,
- 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;
- type Output = SingleFormatCollection;
-
- async fn visit_series(&mut self, series: Series) -> Result> {
- // `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::>()
- .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::>()
- .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::>()
- .join(", ")
- )
- }
- }
-
- Ok(seasons)
- }
-
- async fn visit_season(&mut self, mut season: Season) -> Result> {
- 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 = 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::>()
- .join(", ")
- )
- }
-
- let subtitle_locales: Vec = 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::>()
- .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
> {
- 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 = 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::>()
- .join(", ")
- )
- }
-
- let mut subtitle_locales: Vec =
- 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::>()
- .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> {
- Ok(movie_listing.movies().await?)
- }
-
- async fn visit_movie(&mut self, movie: Movie) -> Result
> {
- Ok(Some(vec![SingleFormat::new_from_concert(concert)]))
- }
-
- async fn finish(self, input: Vec) -> Result {
- let flatten_input: Self::T = input.into_iter().flatten().collect();
-
- let mut single_format_collection = SingleFormatCollection::new();
-
- let mut pre_sorted: BTreeMap = 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()
-}
diff --git a/crunchy-cli-core/src/archive/mod.rs b/crunchy-cli-core/src/archive/mod.rs
index c3544a4..670d0c2 100644
--- a/crunchy-cli-core/src/archive/mod.rs
+++ b/crunchy-cli-core/src/archive/mod.rs
@@ -1,4 +1,3 @@
mod command;
-mod filter;
pub use command::Archive;
diff --git a/crunchy-cli-core/src/download/command.rs b/crunchy-cli-core/src/download/command.rs
index fcf069b..8e3794f 100644
--- a/crunchy-cli-core/src/download/command.rs
+++ b/crunchy-cli-core/src/download/command.rs
@@ -1,8 +1,7 @@
-use crate::download::filter::DownloadFilter;
use crate::utils::context::Context;
use crate::utils::download::{DownloadBuilder, DownloadFormat, DownloadFormatMetadata};
use crate::utils::ffmpeg::{FFmpegPreset, SOFTSUB_CONTAINERS};
-use crate::utils::filter::Filter;
+use crate::utils::filter::{Filter, FilterMediaScope};
use crate::utils::format::{Format, SingleFormat};
use crate::utils::locale::{resolve_locales, LanguageTagging};
use crate::utils::log::progress;
@@ -14,7 +13,7 @@ use anyhow::bail;
use anyhow::Result;
use crunchyroll_rs::media::Resolution;
use crunchyroll_rs::Locale;
-use log::{debug, warn};
+use log::{debug, error, warn};
use std::collections::HashMap;
use std::path::Path;
@@ -250,9 +249,53 @@ impl Execute for Download {
for (i, (media_collection, url_filter)) in parsed_urls.into_iter().enumerate() {
let progress_handler = progress!("Fetching series details");
- let single_format_collection = DownloadFilter::new(
+ let single_format_collection = Filter::new(
url_filter,
- self.clone(),
+ vec![self.audio.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.skip_specials,
ctx.crunchy.premium().await,
diff --git a/crunchy-cli-core/src/download/filter.rs b/crunchy-cli-core/src/download/filter.rs
deleted file mode 100644
index 1c62920..0000000
--- a/crunchy-cli-core/src/download/filter.rs
+++ /dev/null
@@ -1,307 +0,0 @@
-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>,
- season_subtitles_missing: Vec,
- seasons_with_premium: Option>,
- 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> {
- // `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::>()
- .join(", ")
- )
- }
- }
-
- Ok(seasons)
- }
-
- async fn visit_season(&mut self, season: Season) -> Result> {
- 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
> {
- 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> {
- Ok(movie_listing.movies().await?)
- }
-
- async fn visit_movie(&mut self, movie: Movie) -> Result