This is a development and test repository. Visit the production repository and branch for stable/production releases.
A Docker Mod for the LinuxServer.io Radarr/Sonarr v3 or higher Docker containers that adds a script to automatically strip out unwanted audio and subtitle tracks, keeping only the desired languages.
This unified script works in both Radarr and Sonarr. Use this mod in either container!
There is a now an installer for hotio containers! See the HOTIO.md file for more details.
NEW! The script can now be executed from Windows by using WSL! See the WSL.md file for more details.
This mod supports Linux OSes only.
Configure your selected Docker container with all the port, volume, and environment settings from the original container documentation here:
linuxserver/radarr OR linuxserver/sonarr
Add the DOCKER_MODS environment variable to your compose.yml
file or docker run
command, as follows:
DOCKER_MODS=linuxserver/mods:radarr-striptracks
DOCKER_MODS=thecaptain989/radarr-striptracks:latest
Example Docker Compose YAML Configuration
version: "2.1"
services:
radarr:
image: lscr.io/linuxserver/radarr
container_name: radarr
environment:
- PUID=1000
- PGID=1000
- TZ=America/Chicago
- DOCKER_MODS=linuxserver/mods:radarr-striptracks
volumes:
- /path/to/data:/config
- /path/to/movies:/movies
- /path/to/downloadclient-downloads:/downloads
ports:
- 7878:7878
restart: unless-stopped
Start the container.
Configure a custom script from Radarr's or Sonarr's Settings > Connect screen and type the following in the Path field:
/usr/local/bin/striptracks.sh
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 or an environment variable may be used to more granularly define which tracks to keep. See Wrapper Scripts or Environment Variable for more details.
You must configure language(s) in Radarr/Sonarr or pass command-line arguments for the script to do anything! See the next section for an example.
The following is a simplified example and steps to configure Radarr so the script will keep Original and English languages of an imported movie.
Create a new Custom Format called "My Languages":
Add two Language Conditions to the format, one for English, and one for Original:
Edit the 'Any' Quality Profile, changing the Language to "Any" and the Score to "10":
Now, when Radarr imports a movie with the 'Any' Quality Profile, the script will keep only Original and English languages. This is equivalent to calling the script with --audio :org:eng --subs :org:eng
command-line arguments.
See Automatic Language Detection for more details.
The source video can be any mkvtoolnix supported video format. The output is an MKV file with the same name and the same permissions. Owner is preserved if the script is executed as root.
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
).
The language of the video file will be updated in the Radarr or Sonarr database to reflect the actual languages preserved in the remuxed video, and the video will be renamed according to the Radarr/Sonarr rules if needed (for example, if a removed track would trigger a name change.)
If you've configured the Radarr/Sonarr Recycle Bin path correctly, the original video will be moved there.
WARNING: 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, and it's already an MKV, the remux step is skipped.
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 Custom Formats (in Radarr v3 and higher and Sonarr v4 and higher), Quality Profiles (only in Radarr), or Language Profiles (Sonarr v3).
Both audio and subtitle tracks that match the configured language(s) are kept.
The language selection 'Original' will use the language Radarr pulled from The Movie Database or that Sonarr pulled from The TVDB during its last refresh.
Selecting this language is functionally equivalent to calling the script with --audio :org --subs :org
command-line arguments. See 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 arguments.
See Unknown language code below for more details.
The language selection 'Any' has two purposes (Radarr only):
1) It will trigger a search of languages in Custom Formats
2) If none are found, it will preserve all languages in the video file. This is functionally equivalent to calling the script with --audio :any --subs :any
command-line arguments.
See Any language code below for more details.
When using Custom Format language conditions and scoring you may not get the results you expect. This can be non-intuitive configuration, especially when using negative scoring, the 'Negate' option, and the 'Except Language' option. The script does not care what custom format is detected 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.
It is highly recommended to review the TraSH Guides setup instructions for Language Custom Formats.
The following chart represents the order of precedence that the script uses 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.
graph LR
A[Command-Line]
B["Environment
Variable"]
C["Quality
Profile"]
D["Custom
Formats"]
E["Language Profile
(Sonarr only)"]
A-->B
B-->C
C-- 'Any' -->D
D-->E
Descriptively, these steps are:
For step 3 above, using Custom Formats when 'Any' is in the Quality Profile is consistent with the behavior described in TRaSH Guides.
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>] [{-c|--config} <config_file>] [{-d|--debug} [<level>]]
The <audio_languages>
and <subtitle_languages>
are optional arguments that are colon (:
) prepended language codes in ISO 639-2 format.
For example:
:eng
:fre
:spa
...etc.
Multiple codes may be concatenated, such as :eng:spa
for both English and Spanish. Order is unimportant.
WARNING: If no subtitle language is detected via Radarr/Sonarr configuration or specified on the command-line, all subtitles are removed.
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.
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 or The 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 use this special code.
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.
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.
WARNING: It is common for M2TS and AVI files to have tracks with unknown languages! It is strongly recommended to include
:und
in most instances unless you know exactly what you're doing.
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.
To supply arguments to the script, you must either use one of the included wrapper scripts, create a custom wrapper script, or set the STRIPTRACKS_ARGS
environment variable.
For your convenience, several wrapper scripts are included in the /usr/local/bin/
directory.
You may use any of these in place of striptracks.sh
mentioned in the Installation section above.
To configure an entry from the Examples section above, create and save a file called striptracks-custom.sh
to /config
containing the following text:
#!/bin/bash
. /usr/local/bin/striptracks.sh -d -a :eng:kor:jpn -s :eng:spa
Make it executable:
chmod +x /config/striptracks-custom.sh
Then put /config/striptracks-custom.sh
in the Path field in place of /usr/local/bin/striptracks.sh
mentioned in the Installation section above.
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.
The striptracks.sh
script can read command-line arguments from the STRIPTRACKS_ARGS
environment variable. This allows advanced use cases without having to provide a custom script.
For example, the following lines in your compose.yml
file would keep English, Japanese, and Unknown audio and English subtitles:
environment:
- STRIPTRACKS_ARGS=--audio :eng:jpn:und --subs :eng
In a docker run
command, it would be:
-e STRIPTRACKS_ARGS='--audio :eng:jpn:und --subs :eng'
The environment variable is only read when no command-line arguments are present. Any command-line argument will disable the use of the environment variable.
The only events/notification triggers that are supported are On Import and On Upgrade. The script will log an error if executed by any other trigger.
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 below.
Because the script is not called from within Radarr or Sonarr, their database is unavailable to the script. Therefore, expect the following behavior while in Batch Mode:
-f
option places the script in Batch Mode:org
language code is meaningless.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:
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
Here's another example to keep English, Danish, and Unknown languages on all video files in your ./videos
directory (requires the file
program; testable with file -v
):
find ./videos/ -type f | while read filename; do if file -i "$filename" | grep -q video; then /usr/local/bin/striptracks.sh -f "$filename" --audio :eng:dan:und --subs :eng:dan:und; fi; done
By default, a log file is created for the script activity called:
/config/logs/striptracks.txt
This log can be inspected or downloaded from Radarr/Sonarr under System > Logs > Files. The log filename can be modified with the --log
command-line option.
Script errors will show up in both the script log and the native Radarr/Sonarr log.
Log rotation is performed with 5 log files of 512KB each being kept.
WARNING: If debug logging is enabled with a level above 1, the log file can grow very large very quickly. Do not leave high-level debug logging enabled permanently.
To completely remove the mod:
compose.yaml
file or exclude it from the docker run
command when re-creating the Radarr/Sonarr container.This would not be possible without the following:
Radarr
Sonarr
LinuxServer.io Radarr container
LinuxServer.io Sonarr container
LinuxServer.io Docker Mods project
MKVToolNix by Moritz Bunkus
The AWK script parsing mkvmerge output is adapted from Endoro's post on VideoHelp.
Icons made by Freepik from Flaticon
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.