Release 2.5

- **New:** Added support for *Custom Formats* language selection
- **New:** Now fully supports Sonarr v4
  - 'Original' language support
  - Deprecated `languageprofile` API endpoint accounted for (Fixes TheCaptain989/radarr-striptracks#64)
  - *Still* backward compatible with Sonarr v3
- Fixes TheCaptain989/radarr-striptracks#66
- Added Radarr/Sonarr feature compatibility tests
- Added quick drop-out if unable to determine Radarr/Sonarr version
- Added a longer wait for rescan, delete, and update completion
- Improved Radarr/Sonarr database update logic
   - Editor API will no longer be called if there are no changes
   - No update with 'Unknown' language
- Improved automatic language detection logic
- Improved debug logging
- Incremented GitHub workflow actions, per the [Node.js 16 deprecation](https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/ "GitHub Actions: Transitioning from Node 16 to Node 20") announcement
- Updated README
This commit is contained in:
TheCaptain989
2024-02-11 21:44:28 -06:00
parent 39ad09af9c
commit 7f80e55fce
7 changed files with 376 additions and 165 deletions
+71 -33
View File
@@ -1,5 +1,5 @@
# About
A [Docker Mod](https://github.com/linuxserver/docker-mods) for the LinuxServer.io Radarr/Sonarr v3 Docker container that adds a script to automatically strip out unwanted audio and subtitle streams, keeping only the desired languages.
A [Docker Mod](https://github.com/linuxserver/docker-mods) for the LinuxServer.io Radarr/Sonarr v3 Docker container that adds a script to automatically strip out unwanted audio and subtitle tracks, keeping only the desired languages.
**Beginning with version 2.0 of this mod, it only supports v3 or later of Radarr/Sonarr. For legacy Radarr/Sonarr v2 please use mod release 1.3 or earlier**
@@ -74,10 +74,10 @@ Production Container info: ![Docker Image Size](https://img.shields.io/docker/im
*Example*
![striptracks v3](.assets/striptracks-v3-custom-script.png "Radarr/Sonarr custom script settings")
The script will detect the language defined in the video profile for the movie or TV show and only keep the audio and subtitles selected.
The script will detect the language(s) defined in Radarr/Sonarr for the movie or TV show and only keep the audio and subtitles selected.
Alternatively, a wrapper script may be used to more granularly define which tracks to keep. See [Wrapper Scripts](./README.md#wrapper-scripts) for more details.
## Usage Details
# Usage
The source video can be any mkvtoolnix supported video format. The output is an MKV file with the same name.
Chapters, if they exist, are preserved. The Title attribute in the MKV is set to the movie title plus year
(ex: `The Sting (1973)`) or the series title plus episode information (ex: `Happy! 01x01 - What Smiles Are For`).
@@ -86,28 +86,66 @@ The language of the video file will be updated in the Radarr or Sonarr database
If you've configured the Radarr/Sonarr **Recycle Bin** path correctly, the original video will be moved there.
![danger] **NOTE:** If you have *not* configured the Recycle Bin, the original video file will be deleted/overwritten and permanently lost.
If the resulting video file would contain the same tracks as the original, the remux step is skipped *unless* the source file is not an MKV.
If the resulting video file would contain the same tracks as the original, and it's already an MKV, the remux step is skipped.
### Syntax
Beginning with version 2.0 of this mod, the script may be called with no arguments. In this configuration it will detect the language(s) defined in the profile (*Quality Profile* for Radarr, *Language Profile* for Sonarr) configured on the particular movie or TV show.
## Automatic Language Detection
Beginning with version 2.0 of this mod, the script may be called with no arguments. It will detect the language(s) configured within Radarr/Sonarr on the particular movie or TV show.
Language selection(s) may be configured in ***Quality Profiles*** (only in Radarr), ***Custom Formats*** (in Radarr v3 and higher and Sonarr v4 and higher), or ***Language Profiles*** (Sonarr v3). Example screenshots are below.
#### Automatic Language Detection
Both audio and subtitles that match the selected language(s) are kept.
Both audio **and** subtitle tracks that match the configured language(s) are kept.
>**Note:** The Radarr language selection 'Any' will preserve all languages in the video file. Selecting this profile language is functionally equivalent to calling the script with `--audio :any --subs :any` command-line options. See [Any language code](./README.md#any-language-code) below for more details.
The language selection **'Original'** will use the language Radarr pulled from [The Movie Database](https://www.themoviedb.org/ "TMDB") or that Sonarr pulled from [The TVDB](https://www.thetvdb.com/ "TVDB") during its last refresh.
Selecting this language is functionally equivalent to calling the script with `--audio :org --subs :org` command-line options. See [Original language code](./README.md#original-language-code) below for more details.
>**Note:** The Radarr language selection 'Original' will use the language Radarr pulled from [The Movie Database](https://www.themoviedb.org/ "TMDB") during its last refresh. Selecting this profile language is functionally equivalent to calling the script with `--audio :org --subs :org` command-line options. See [Original language code](./README.md#original-language-code) below for more details.
The language selection **'Unknown'** will match tracks with **no configured language** in the video file. Selecting this language is functionally equivalent to calling the script with `--audio :und --subs :und` command-line options. See [Unknown language code](./README.md#unknown-language-code) below for more details.
>**Note:** The Sonarr language selection 'Unknown' will match tracks with no configured language in the video file. Selecting this profile language is functionally equivalent to calling the script with `--audio :und --subs :und` command-line options. See [Unknown language code](./README.md#unknown-language-code) below for more details.
The Radarr language selection **'Any'** has two purposes:
1) It will trigger a search of languages in ***Custom Formats***
2) If none are found, it will will preserve **all languages** in the video file. This is functionally equivalent to calling the script with `--audio :any --subs :any` command-line options. See [Any language code](./README.md#any-language-code) below for more details.
>**Note:** When using the *Custom Format* conditions and scoring to select languages you may not get the results you expect.
>This can be non-intuitive configuration, especially when using negative scoring and the 'Negate' option.
>The script does not care what custom format is *detected* (aka applied) by Radarr/Sonarr on the video file, only what the *scores* are in the *Quality Profile*.
>If you choose to use Custom Formats, it is **highly recommended** to first run the script with the debug option `-d`, perform some test downloads and script runs, and then examine your results and the script logs closely to be sure things are working the way you want them to.
*Radarr Quality Profile Example*
![radarr profile](.assets/radarr-quality-profile.png "Radarr Quality Profile settings")
*Sonarr Language Profile Example*
![sonarr profile](.assets/sonarr-language-profile.png "Sonarr Language Profile settings")
*Custom Format Condition Example*
![custom format](.assets/custom-format-condition.png "Custom Format Language setting")
#### Command-Line Options and Arguments
The script also supports command-line arguments that will override the automatic language detection. More granular control can therefore be exerted or extended using tagging and defining multiple Connect scripts (this is native Radarr/Sonarr functionality outside the scope of this documentation).
*Radarr Custom Format Language Score Example*
![custom format score](.assets/custom-format-score.png "Custom Format Language scoring")
### Language Detection Precedence
The following chart represents the order of precedence that the script follows to decide which language(s) to select when there are multiple settings configured. Moving left to right, it will stop when it finds a configured language.
```mermaid
graph LR
A[Command-Line]
B["Quality
Profile"]
C["Custom
Formats"]
D["Language Profile
(Sonarr only)"]
A-->B
B-- 'Any' -->C
C-->D
```
Descriptively, these steps are:
1. Command-line options override all automatic language selection.
2. If there are no command-line options, the video's *Quality Profile* is examined for a language configuration (only supported in Radarr).
3. If there is no *Quality Profile* language **or** it is set to 'Any', then examine the *Custom Formats* and scores associated with the quality profile. All language conditions with positive scores *and* negated conditions with negative score are selected.
4. If the *Custom Format* scores are zero (0) or there are none with configured language conditions, examine the *Language Profile* (only supported in Sonarr v3)
>**Note:** For step 3 above, using *Custom Formats* when 'Any' is in the *Quality Profile* is consistent with the behavior described in [TRaSH Guides](https://trash-guides.info/Sonarr/Tips/How-to-setup-language-custom-formats/ "TraSH Guides: How to setup Language Custom Formats").
## Command-Line Syntax
### Options and Arguments
The script also supports command-line arguments that will override the automatic language detection. More granular control can therefore be exerted or extended using tagging and defining multiple *Connect* scripts (this is native Radarr/Sonarr functionality outside the scope of this documentation).
The syntax for the command-line is:
`striptracks.sh [{-a|--audio} <audio_languages> [{-s|--subs} <subtitle_languages>] [{-f|--file} <video_file>]] [{-l,--log} <log_file>] [{-d|--debug} [<level>]]`
@@ -137,29 +175,29 @@ Multiple codes may be concatenated, such as `:eng:spa` for both English and Span
>![warning] **NOTE:** If no subtitle language is detected in the profile or specified on the command-line, all subtitles are removed.
#### Any language code
### Any language code
The `:any` language code is a special code. When used, the script will preserve all language tracks, regardless of how they are tagged in the source video.
#### Original language code
The `:org` language code is a special code. When used, instead of retaining a specific language, the script substitutes the original movie language as specified in its [The Movie Database](https://www.themoviedb.org/ "TMDB") entry.
### Original language code
The `:org` language code is a special code. When used, instead of retaining a specific language, the script substitutes the original movie or TV show language as specified in its [The Movie Database](https://www.themoviedb.org/ "TMDB") or [The TVDB](https://www.thetvdb.com/ "TVDB") entry.
As an example, when importing "*Amores Perros (2000)*" with options `--audio :org:eng`, the Spanish and English audio tracks are preserved.
Several [Included Wrapper Scripts](./README.md#included-wrapper-scripts) use this special code.
>![danger] **NOTE:** This feature relies on the 'originalLanguage' field in the Radarr database. It is not known to exist in Sonarr, and the `:org` code will therefore be ignored. It is also invalid when used in Batch Mode.
>![danger] **NOTE:** This feature relies on the 'originalLanguage' field in the Radarr/Sonarr database. The `:org` code is therefore invalid when used in Batch Mode.
> The script will log a warning if it detects the use of `:org` in an invalid way, though it will continue to execute.
#### Unknown language code
The `:und` language code is a special code. When used, the script will match on any track that has a null or blank language entry. If not included, tracks with a blank language value will be removed.
### Unknown language code
The `:und` language code is a special code. When used, the script will match on any track that has a null or blank language attribute. If not included, tracks with no language attribute will be removed.
>![danger] **NOTE:** It is common for M2TS and AVI containers to have tracks with unknown languages! It is strongly recommended to include `:und` in most instances unless you know exactly what you're doing.
### Special Handling of Audio
## Special Handling of Audio
The script is smart enough to not remove the last audio track. There is in fact no way to force the script to remove all audio. This way you don't have to specify every possible language if you are importing a foreign film, for example.
Additionally, two ISO 639-2 language codes are handled specially: the "*Uncoded languages*" code of `mis` and the "*No linguistic content*" code of `zxx`.
Tracks with either of these codes are always retained as they are often used for instrumental tracks in silent films.
There is no way to force the script to remove audio tracks with these codes.
### Examples
## Examples
```shell
-d 2 # Enable debugging level 2, audio and subtitles
@@ -176,10 +214,10 @@ There is no way to force the script to remove audio tracks with these codes.
-a :any -s "" # Keep all audio and remove all subtitles
```
### Wrapper Scripts
## Wrapper Scripts
To supply arguments to the script, one of the included wrapper scripts may be used or a custom wrapper script must be created.
#### Included Wrapper Scripts
### Included Wrapper Scripts
For your convenience, several wrapper scripts are included in the `/usr/local/bin/` directory.
You may use any of these scripts in place of `striptracks.sh` mentioned in the [Installation](./README.md#installation) section above.
@@ -201,7 +239,7 @@ striptracks-org-ger.sh # Keep Original and German audio, and Original and Ge
striptracks-org-spa.sh # Keep Original and Spanish audio, and Original and Spanish subtitles
```
#### Example Wrapper Script
### Example Wrapper Script
To configure an entry from the [Examples](./README.md#examples) section above, create and save a file called `striptracks-custom.sh` to `/config` containing the following text:
```shell
@@ -220,31 +258,31 @@ Then put `/config/striptracks-custom.sh` in the **Path** field in place of `/usr
>**Note:** If you followed the Linuxserver.io recommendations when configuring your container, the `/config` directory will be mapped to an external storage location. It is therefore recommended to place custom scripts in the `/config` directory so they will survive container updates, but they may be placed anywhere that is accessible by Radarr or Sonarr.
### Triggers
## Triggers
The only events/notification triggers that have been tested are **On Import** and **On Upgrade**
### Batch Mode
## Batch Mode
Batch mode allows the script to be executed independently of Radarr or Sonarr. It converts the file specified on the command-line and ignores any environment variables that are normally expected to be set by the video management program.
Using this function, you can easily process all of your video files in any subdirectory at once. See the [Batch Example](./README.md#batch-example) below.
#### Script Execution Differences in Batch Mode
### Script Execution Differences in Batch Mode
Because the script is not called from within Radarr or Sonarr, expect the following behavior while in Batch Mode:
* *The filename must be specified on the command-line.*<br/>(The `-f` option places the script in Batch Mode)
* *No audio or subtitles language detection occurs.*<br/>Both the audio and subtitles languages must be specified on the command-line.
* *The `:org` language code is meaningless.*<br/>The original video language cannot be determined without the Radarr database.
* *The `:org` language code is meaningless.*<br/>The original video language cannot be determined without the Radarr/Sonarr database.
* *The resultant MKV embedded title attribute is set to the basename of the file minus the extension.*<br/>The canonical name of the movie/TV show cannot otherwise be determined.
* *Radarr or Sonarr APIs are not called and their database is not updated.*<br/>This may require a manual rescan of converted videos.
* *Original video files are deleted.*<br/>The Recycle Bin function is not available.
#### Batch Example
### Batch Example
To keep English and Unknown audio and English subtitles on all video files ending in .MKV, .AVI, or .MP4 in the `/movies` directory, enter the following at the Linux command-line:
```shell
find /movies/ -type f \( -name "*.mkv" -o -name "*.avi" -o -name "*.mp4" \) | while read file; do /usr/local/bin/striptracks.sh -f "$file" -a :eng:und -s :eng; done
```
### Logs
## Logs
By default, a log file is created for the script activity called:
`/config/logs/striptracks.txt`
@@ -260,7 +298,7 @@ Log rotation is performed with 5 log files of 512KB each being kept.
To completely remove the mod:
1. Delete the custom script from Radarr's or Sonarr's *Settings* > *Connect* screen that you created in the [Installation](./README.md#installation) section above.
2. Stop and delete the Radarr/Sonarr container.
3. Exclude the **DOCKER_MODS** environment variable from your `compose.yaml` file or the `docker run` command when re-creating the Radarr/Sonarr container.
3. Remove the **DOCKER_MODS** environment variable from your `compose.yaml` file or exclude it from the `docker run` command when re-creating the Radarr/Sonarr container.
___