Skip to content

Commit

Permalink
Merge pull request #895 from TheCaptain989/radarr-striptracks
Browse files Browse the repository at this point in the history
radarr: striptracks release 2.6.1
  • Loading branch information
aptalca authored May 30, 2024
2 parents 7804b50 + 21f3678 commit 24cf09e
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 11 deletions.
Binary file added .assets/striptracks-synology-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .assets/striptracks-synology.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ RUN \
## Single layer deployed image ##
FROM scratch

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

# Add files from buildstage
COPY --from=buildstage /root-layer/ /
37 changes: 29 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ A [Docker Mod](https://github.com/linuxserver/docker-mods) for the LinuxServer.i
**This unified script works in both Radarr and Sonarr. Use this mod in either container!**
>**NOTE:** This mod supports Linux OSes only.
Container info:
Production Container info: ![Docker Image Size](https://img.shields.io/docker/image-size/linuxserver/mods/radarr-striptracks "Container Size")
Development Container info:
![Docker Image Size](https://img.shields.io/docker/image-size/thecaptain989/radarr-striptracks "Container Size")
![Docker Pulls](https://img.shields.io/docker/pulls/thecaptain989/radarr-striptracks "Container Pulls")
[![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")
Production Container info: ![Docker Image Size](https://img.shields.io/docker/image-size/linuxserver/mods/radarr-striptracks "Container Size")

# Installation
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:
Expand Down Expand Up @@ -75,10 +75,10 @@ Production Container info: ![Docker Image Size](https://img.shields.io/docker/im
![striptracks v3](.assets/striptracks-v3-custom-script.png "Radarr/Sonarr custom script settings")

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.
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.

# Usage
The source video can be any mkvtoolnix supported video format. The output is an MKV file with the same name.
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.)
Expand Down Expand Up @@ -135,7 +135,7 @@ graph LR
```

Descriptively, these steps are:
1. Command-line options override all automatic language selection.
1. Command-line options (or environment variable) 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)
Expand Down Expand Up @@ -173,7 +173,7 @@ For example:

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

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

### 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.
Expand Down Expand Up @@ -215,7 +215,7 @@ There is no way to force the script to remove audio tracks with these codes.
```

## 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.
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).

### Included Wrapper Scripts
For your convenience, several wrapper scripts are included in the `/usr/local/bin/` directory.
Expand Down Expand Up @@ -258,8 +258,29 @@ 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.

## Environment Variable
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.

For example, the following value in your `docker run` command would Keep English, Japanese, and Unknown audio and English subtitles:

```shell
-e STRIPTRACKS_ARGS='--audio :eng:jpn:und --subs :eng'
```

In Docker Compose this will look like this:

```yaml
environment:
- STRIPTRACKS_ARGS=--audio :eng:jpn:und --subs :eng
```

*Example Synology Configuration*
![striptracks](.assets/striptracks-synology-2.png "Synology container settings")

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

## Triggers
The only events/notification triggers that have been tested are **On Import** and **On Upgrade**
The only events/notification triggers that are supported are **On Import** and **On Upgrade**

## 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.
Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Only the latest major and minor version are supported.

| Version | Supported |
| ------- | ------------------ |
| 2.5.x | :heavy_check_mark: |
| < 2.5 | :x: |
| 2.6.x | :heavy_check_mark: |
| < 2.6 | :x: |

## Reporting a Vulnerability

Expand Down
64 changes: 64 additions & 0 deletions root/usr/local/bin/striptracks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
# 11 - source video had no audio or subtitle tracks
# 12 - log file is not writable
# 13 - awk script exited abnormally
# 15 - could not set permissions and/or owner on new file
# 16 - could not delete the original file
# 17 - Radarr/Sonarr API error
# 18 - Radarr/Sonarr job timeout
Expand Down Expand Up @@ -71,6 +72,9 @@ Source: https://github.com/TheCaptain989/radarr-striptracks
Usage:
$0 [{-a|--audio} <audio_languages> [{-s|--subs} <subtitle_languages>] [{-f|--file} <video_file>]] [{-l|--log} <log_file>] [{-d|--debug} [<level>]]
Options can also be set via the STRIPTRACKS_ARGS environment variable.
Command-line arguments override the environment variable.
Options and Arguments:
-a, --audio <audio_languages> Audio languages to keep
ISO639-2 code(s) prefixed with a colon \`:\`
Expand Down Expand Up @@ -125,6 +129,17 @@ Examples:
echo "$usage" >&2
}

# Check for environment variable arguments
if [ -n "$STRIPTRACKS_ARGS" ]; then
if [ $# -ne 0 ]; then
striptracks_prelogmessage="Warning|STRIPTRACKS_ARGS environment variable set but will be ignored because command line arguments were also specified."
else
# Move the environment variable arguments to the command line for processing
striptracks_prelogmessage="Info|Using settings from environment variable."
eval set -- "$STRIPTRACKS_ARGS"
fi
fi

# Process arguments
# Taken from Drew Strokes post 3/24/2015:
# https://medium.com/@Drew_Stokes/bash-argument-parsing-54f3b81a6a8f
Expand Down Expand Up @@ -845,9 +860,24 @@ if [ $striptracks_debug -ge 1 ]; then
echo "$striptracks_message" >&2
fi

# Log STRIPTRACKS_ARGS usage
if [ -n "$striptracks_prelogmessage" ]; then
# striptracks_prelogmessage is set above, before argument processing
echo "$striptracks_prelogmessage" | log
[ $striptracks_debug -ge 1 ] && echo "Debug|STRIPTRACKS_ARGS: ${STRIPTRACKS_ARGS}" | log
fi

# Log environment
[ $striptracks_debug -ge 2 ] && printenv | sort | sed 's/^/Debug|/' | log

# Check for invalid _eventtypes
if [[ "${!striptracks_eventtype}" =~ Grab|Rename|MovieAdded|MovieDelete|MovieFileDelete|SeriesAdd|SeriesDelete|EpisodeFileDelete|HealthIssue|ApplicationUpdate ]]; then
striptracks_message="Error|${striptracks_type^} event ${!striptracks_eventtype} is not supported. Exiting."
echo "$striptracks_message" | log
echo "$striptracks_message" >&2
end_script 20
fi

# Handle Test event
if [[ "${!striptracks_eventtype}" = "Test" ]]; then
echo "Info|${striptracks_type^} event: ${!striptracks_eventtype}" | log
Expand Down Expand Up @@ -881,6 +911,16 @@ elif [ -f "$striptracks_arr_config" ]; then
[[ $striptracks_xml_entity = "ApiKey" ]] && striptracks_apikey=$striptracks_xml_content
done < $striptracks_arr_config

# Allow use of environment variables from https://github.com/Sonarr/Sonarr/pull/6746
striptracks_port_var="${striptracks_type^^}__SERVER__PORT"
[ -n "${!striptracks_port_var}" ] && striptracks_port="${!striptracks_port_var}"
striptracks_urlbase_var="${striptracks_type^^}__SERVER__URLBASE"
[ -n "${!striptracks_urlbase_var}" ] && striptracks_urlbase="${!striptracks_urlbase_var}"
striptracks_bindaddress_var="${striptracks_type^^}__SERVER__BINDADDRESS"
[ -n "${!striptracks_bindaddress_var}" ] && striptracks_bindaddress="${!striptracks_bindaddress_var}"
striptracks_apikey_var="${striptracks_type^^}__AUTH__APIKEY"
[ -n "${!striptracks_apikey_var}" ] && striptracks_apikey="${!striptracks_apikey_var}"

# Check for localhost
[[ $striptracks_bindaddress = "*" ]] && striptracks_bindaddress=localhost

Expand Down Expand Up @@ -1352,6 +1392,30 @@ if [ ! -s "$striptracks_tempvideo" ]; then
end_script 10
fi

# Checking that we're running as root
if [ "$(id -u)" -eq 0 ]; then
# Set owner
[ $striptracks_debug -ge 1 ] && echo "Debug|Changing owner of file \"$striptracks_tempvideo\"" | log
chown --reference="$striptracks_video" "$striptracks_tempvideo" >&2
striptracks_return=$?; [ $striptracks_return -ne 0 ] && {
striptracks_message="Error|[$striptracks_return] Error when changing owner of file: \"$striptracks_tempvideo\""
echo "$striptracks_message" | log
echo "$striptracks_message" >&2
striptracks_exitstatus=15
}
else
# Unable to change owner when not running as root
[ $striptracks_debug -ge 1 ] && echo "Debug|Unable to change owner of file when running as user '$(id -un)'" | log
fi
# Set permissions
chmod --reference="$striptracks_video" "$striptracks_tempvideo" >&2
striptracks_return=$?; [ $striptracks_return -ne 0 ] && {
striptracks_message="Error|[$striptracks_return] Error when changing permissions of file: \"$striptracks_tempvideo\""
echo "$striptracks_message" | log
echo "$striptracks_message" >&2
striptracks_exitstatus=15
}

# Just delete the original video if running in batch mode
if [ "$striptracks_type" = "batch" ]; then
[ $striptracks_debug -ge 1 ] && echo "Debug|Deleting: \"$striptracks_video\"" | log
Expand Down

0 comments on commit 24cf09e

Please sign in to comment.