Skip to content

Commit 24cf09e

Browse files
authored
Merge pull request #895 from TheCaptain989/radarr-striptracks
radarr: striptracks release 2.6.1
2 parents 7804b50 + 21f3678 commit 24cf09e

File tree

6 files changed

+99
-11
lines changed

6 files changed

+99
-11
lines changed

.assets/striptracks-synology-2.png

16.8 KB
Loading

.assets/striptracks-synology.png

83 Bytes
Loading

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ RUN \
1818
## Single layer deployed image ##
1919
FROM scratch
2020

21-
LABEL maintainer="TheCaptain989"
21+
LABEL org.opencontainers.image.source=https://github.com/TheCaptain989/radarr-striptracks
22+
LABEL org.opencontainers.image.description="A Docker Mod to Radarr/Sonarr to automatically strip out unwanted audio and subtitle streams"
23+
LABEL org.opencontainers.image.licenses=GPL-3.0-only
24+
LABEL org.opencontainers.image.authors="TheCaptain989"
2225

2326
# Add files from buildstage
2427
COPY --from=buildstage /root-layer/ /

README.md

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ A [Docker Mod](https://github.com/linuxserver/docker-mods) for the LinuxServer.i
66
**This unified script works in both Radarr and Sonarr. Use this mod in either container!**
77
>**NOTE:** This mod supports Linux OSes only.
88
9-
Container info:
9+
Production Container info: ![Docker Image Size](https://img.shields.io/docker/image-size/linuxserver/mods/radarr-striptracks "Container Size")
10+
Development Container info:
1011
![Docker Image Size](https://img.shields.io/docker/image-size/thecaptain989/radarr-striptracks "Container Size")
1112
![Docker Pulls](https://img.shields.io/docker/pulls/thecaptain989/radarr-striptracks "Container Pulls")
1213
[![GitHub Super-Linter](https://github.com/TheCaptain989/radarr-striptracks/actions/workflows/linter.yml/badge.svg)](https://github.com/TheCaptain989/radarr-striptracks/actions/workflows/linter.yml "Linter Job")
13-
Production Container info: ![Docker Image Size](https://img.shields.io/docker/image-size/linuxserver/mods/radarr-striptracks "Container Size")
1414

1515
# Installation
1616
1. Pull your selected container ([linuxserver/radarr](https://hub.docker.com/r/linuxserver/radarr "LinuxServer.io's Radarr container") or [linuxserver/sonarr](https://hub.docker.com/r/linuxserver/sonarr "LinuxServer.io's Sonarr container")) from GitHub Container Registry or Docker Hub:
@@ -75,10 +75,10 @@ Production Container info: ![Docker Image Size](https://img.shields.io/docker/im
7575
![striptracks v3](.assets/striptracks-v3-custom-script.png "Radarr/Sonarr custom script settings")
7676

7777
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.
78-
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.
78+
Alternatively, a wrapper script or an environment variable may be used to more granularly define which tracks to keep. See [Wrapper Scripts](./README.md#wrapper-scripts) or [Environment Variable](./README.md#environment-variable) for more details.
7979

8080
# Usage
81-
The source video can be any mkvtoolnix supported video format. The output is an MKV file with the same name.
81+
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.
8282
Chapters, if they exist, are preserved. The Title attribute in the MKV is set to the movie title plus year
8383
(ex: `The Sting (1973)`) or the series title plus episode information (ex: `Happy! 01x01 - What Smiles Are For`).
8484
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.)
@@ -135,7 +135,7 @@ graph LR
135135
```
136136

137137
Descriptively, these steps are:
138-
1. Command-line options override all automatic language selection.
138+
1. Command-line options (or environment variable) override all automatic language selection.
139139
2. If there are no command-line options, the video's *Quality Profile* is examined for a language configuration (only supported in Radarr).
140140
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.
141141
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)
@@ -173,7 +173,7 @@ For example:
173173

174174
Multiple codes may be concatenated, such as `:eng:spa` for both English and Spanish. Order is unimportant.
175175

176-
>![warning] **NOTE:** If no subtitle language is detected in the profile or specified on the command-line, all subtitles are removed.
176+
>![warning] **NOTE:** If no subtitle language is detected via Radarr/Sonarr configuration or specified on the command-line, all subtitles are removed.
177177

178178
### Any language code
179179
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.
@@ -215,7 +215,7 @@ There is no way to force the script to remove audio tracks with these codes.
215215
```
216216

217217
## Wrapper Scripts
218-
To supply arguments to the script, one of the included wrapper scripts may be used or a custom wrapper script must be created.
218+
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](./README.md#environment-variable).
219219

220220
### Included Wrapper Scripts
221221
For your convenience, several wrapper scripts are included in the `/usr/local/bin/` directory.
@@ -258,8 +258,29 @@ Then put `/config/striptracks-custom.sh` in the **Path** field in place of `/usr
258258

259259
>**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.
260260

261+
## Environment Variable
262+
The `striptracks.sh` script also allows the use of arguments provided by the `STRIPTRACKS_ARGS` environment variable. This allows advanced use cases without having to provide a custom script.
263+
264+
For example, the following value in your `docker run` command would Keep English, Japanese, and Unknown audio and English subtitles:
265+
266+
```shell
267+
-e STRIPTRACKS_ARGS='--audio :eng:jpn:und --subs :eng'
268+
```
269+
270+
In Docker Compose this will look like this:
271+
272+
```yaml
273+
environment:
274+
- STRIPTRACKS_ARGS=--audio :eng:jpn:und --subs :eng
275+
```
276+
277+
*Example Synology Configuration*
278+
![striptracks](.assets/striptracks-synology-2.png "Synology container settings")
279+
280+
>**NOTE:** The environment variable settings are *only* used when **no** command-line arguments are present. **Any** command-line argument will disable the use of the environment variable.
281+
261282
## Triggers
262-
The only events/notification triggers that have been tested are **On Import** and **On Upgrade**
283+
The only events/notification triggers that are supported are **On Import** and **On Upgrade**
263284

264285
## Batch Mode
265286
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.

SECURITY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Only the latest major and minor version are supported.
66

77
| Version | Supported |
88
| ------- | ------------------ |
9-
| 2.5.x | :heavy_check_mark: |
10-
| < 2.5 | :x: |
9+
| 2.6.x | :heavy_check_mark: |
10+
| < 2.6 | :x: |
1111

1212
## Reporting a Vulnerability
1313

root/usr/local/bin/striptracks.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
# 11 - source video had no audio or subtitle tracks
4242
# 12 - log file is not writable
4343
# 13 - awk script exited abnormally
44+
# 15 - could not set permissions and/or owner on new file
4445
# 16 - could not delete the original file
4546
# 17 - Radarr/Sonarr API error
4647
# 18 - Radarr/Sonarr job timeout
@@ -71,6 +72,9 @@ Source: https://github.com/TheCaptain989/radarr-striptracks
7172
Usage:
7273
$0 [{-a|--audio} <audio_languages> [{-s|--subs} <subtitle_languages>] [{-f|--file} <video_file>]] [{-l|--log} <log_file>] [{-d|--debug} [<level>]]
7374
75+
Options can also be set via the STRIPTRACKS_ARGS environment variable.
76+
Command-line arguments override the environment variable.
77+
7478
Options and Arguments:
7579
-a, --audio <audio_languages> Audio languages to keep
7680
ISO639-2 code(s) prefixed with a colon \`:\`
@@ -125,6 +129,17 @@ Examples:
125129
echo "$usage" >&2
126130
}
127131

132+
# Check for environment variable arguments
133+
if [ -n "$STRIPTRACKS_ARGS" ]; then
134+
if [ $# -ne 0 ]; then
135+
striptracks_prelogmessage="Warning|STRIPTRACKS_ARGS environment variable set but will be ignored because command line arguments were also specified."
136+
else
137+
# Move the environment variable arguments to the command line for processing
138+
striptracks_prelogmessage="Info|Using settings from environment variable."
139+
eval set -- "$STRIPTRACKS_ARGS"
140+
fi
141+
fi
142+
128143
# Process arguments
129144
# Taken from Drew Strokes post 3/24/2015:
130145
# https://medium.com/@Drew_Stokes/bash-argument-parsing-54f3b81a6a8f
@@ -845,9 +860,24 @@ if [ $striptracks_debug -ge 1 ]; then
845860
echo "$striptracks_message" >&2
846861
fi
847862

863+
# Log STRIPTRACKS_ARGS usage
864+
if [ -n "$striptracks_prelogmessage" ]; then
865+
# striptracks_prelogmessage is set above, before argument processing
866+
echo "$striptracks_prelogmessage" | log
867+
[ $striptracks_debug -ge 1 ] && echo "Debug|STRIPTRACKS_ARGS: ${STRIPTRACKS_ARGS}" | log
868+
fi
869+
848870
# Log environment
849871
[ $striptracks_debug -ge 2 ] && printenv | sort | sed 's/^/Debug|/' | log
850872

873+
# Check for invalid _eventtypes
874+
if [[ "${!striptracks_eventtype}" =~ Grab|Rename|MovieAdded|MovieDelete|MovieFileDelete|SeriesAdd|SeriesDelete|EpisodeFileDelete|HealthIssue|ApplicationUpdate ]]; then
875+
striptracks_message="Error|${striptracks_type^} event ${!striptracks_eventtype} is not supported. Exiting."
876+
echo "$striptracks_message" | log
877+
echo "$striptracks_message" >&2
878+
end_script 20
879+
fi
880+
851881
# Handle Test event
852882
if [[ "${!striptracks_eventtype}" = "Test" ]]; then
853883
echo "Info|${striptracks_type^} event: ${!striptracks_eventtype}" | log
@@ -881,6 +911,16 @@ elif [ -f "$striptracks_arr_config" ]; then
881911
[[ $striptracks_xml_entity = "ApiKey" ]] && striptracks_apikey=$striptracks_xml_content
882912
done < $striptracks_arr_config
883913

914+
# Allow use of environment variables from https://github.com/Sonarr/Sonarr/pull/6746
915+
striptracks_port_var="${striptracks_type^^}__SERVER__PORT"
916+
[ -n "${!striptracks_port_var}" ] && striptracks_port="${!striptracks_port_var}"
917+
striptracks_urlbase_var="${striptracks_type^^}__SERVER__URLBASE"
918+
[ -n "${!striptracks_urlbase_var}" ] && striptracks_urlbase="${!striptracks_urlbase_var}"
919+
striptracks_bindaddress_var="${striptracks_type^^}__SERVER__BINDADDRESS"
920+
[ -n "${!striptracks_bindaddress_var}" ] && striptracks_bindaddress="${!striptracks_bindaddress_var}"
921+
striptracks_apikey_var="${striptracks_type^^}__AUTH__APIKEY"
922+
[ -n "${!striptracks_apikey_var}" ] && striptracks_apikey="${!striptracks_apikey_var}"
923+
884924
# Check for localhost
885925
[[ $striptracks_bindaddress = "*" ]] && striptracks_bindaddress=localhost
886926

@@ -1352,6 +1392,30 @@ if [ ! -s "$striptracks_tempvideo" ]; then
13521392
end_script 10
13531393
fi
13541394

1395+
# Checking that we're running as root
1396+
if [ "$(id -u)" -eq 0 ]; then
1397+
# Set owner
1398+
[ $striptracks_debug -ge 1 ] && echo "Debug|Changing owner of file \"$striptracks_tempvideo\"" | log
1399+
chown --reference="$striptracks_video" "$striptracks_tempvideo" >&2
1400+
striptracks_return=$?; [ $striptracks_return -ne 0 ] && {
1401+
striptracks_message="Error|[$striptracks_return] Error when changing owner of file: \"$striptracks_tempvideo\""
1402+
echo "$striptracks_message" | log
1403+
echo "$striptracks_message" >&2
1404+
striptracks_exitstatus=15
1405+
}
1406+
else
1407+
# Unable to change owner when not running as root
1408+
[ $striptracks_debug -ge 1 ] && echo "Debug|Unable to change owner of file when running as user '$(id -un)'" | log
1409+
fi
1410+
# Set permissions
1411+
chmod --reference="$striptracks_video" "$striptracks_tempvideo" >&2
1412+
striptracks_return=$?; [ $striptracks_return -ne 0 ] && {
1413+
striptracks_message="Error|[$striptracks_return] Error when changing permissions of file: \"$striptracks_tempvideo\""
1414+
echo "$striptracks_message" | log
1415+
echo "$striptracks_message" >&2
1416+
striptracks_exitstatus=15
1417+
}
1418+
13551419
# Just delete the original video if running in batch mode
13561420
if [ "$striptracks_type" = "batch" ]; then
13571421
[ $striptracks_debug -ge 1 ] && echo "Debug|Deleting: \"$striptracks_video\"" | log

0 commit comments

Comments
 (0)