Merge pull request #800 from TheCaptain989/radarr-striptracks

radarr: striptracks release 2.4.3
This commit is contained in:
aptalca 2023-12-17 11:54:04 -05:00 committed by GitHub
commit 97f6660648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 117 additions and 38 deletions

View File

@ -8,9 +8,9 @@ A [Docker Mod](https://github.com/linuxserver/docker-mods) for the LinuxServer.i
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")
![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")
[![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)
# 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:
@ -20,11 +20,33 @@ Production Container info: ![Docker Image Size](https://img.shields.io/docker/im
2. Configure the Docker container with all the port, volume, and environment settings from the *original container documentation* here:
**[linuxserver/radarr](https://hub.docker.com/r/linuxserver/radarr "Radarr Docker container")**
**[linuxserver/sonarr](https://hub.docker.com/r/linuxserver/sonarr "Sonarr Docker container")**
1. Add the **DOCKER_MODS** environment variable to the `docker run` command, as follows:
- Stable release: `-e DOCKER_MODS=linuxserver/mods:radarr-striptracks`
- Dev/test release: `-e DOCKER_MODS=thecaptain989/radarr-striptracks:latest`
1. Add the **DOCKER_MODS** environment variable to your `compose.yml` file or `docker run` command, as follows:
- Stable release: `DOCKER_MODS=linuxserver/mods:radarr-striptracks`
- Dev/test release: `DOCKER_MODS=thecaptain989/radarr-striptracks:latest`
*Example Docker CLI Configuration*
*Example Docker Compose YAML Configuration*
```yaml
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
```
*Example Docker Run Command*
```shell
docker run -d \
@ -88,16 +110,17 @@ Both audio and subtitles that match the selected language(s) are kept.
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 [{-d|--debug} [<level>]] [[{-f|--file} <video_file>] {-a|--audio} <audio_languages> [{-s|--subs} <subtitle_languages>]]`
`striptracks.sh [{-a|--audio} <audio_languages> [{-s|--subs} <subtitle_languages>] [{-f|--file} <video_file>]] [{-l,--log} <log_file>] [{-d|--debug} [<level>]]`
Where:
Option|Argument|Description
---|---|---
-d, --debug|\[\<level\>\]|Enables debug logging. Level is optional.<br/>Default of 1 (low)<br/>2 includes JSON output<br/>3 contains even more JSON output
-a, --audio|<audio_languages>|Audio languages to keep<br/>ISO639-2 code(s) prefixed with a colon (`:`)
-s, --subs|<subtitle_languages>|Subtitle languages to keep<br/>IISO639-2 code(s) prefixed with a colon (`:`)
-f, --file|<video_file>|If included, the script enters **[Batch Mode](./README.md#batch-mode)** and converts the specified video file.<br/>Requires the `-a` option.<br/>![danger] **WARNING:** Do not use this argument when called from Radarr or Sonarr!
-l, --log|\<log_file\>|The log filename<br/>Default of /config/log/striptracks.txt
-d, --debug|\[\<level\>\]|Enables debug logging. Level is optional.<br/>Default of 1 (low)<br/>2 includes JSON output<br/>3 contains even more JSON output
--help| |Display help and exit.
--version| |Display version and exit.
@ -122,10 +145,11 @@ The `:org` language code is a special code. When used, instead of retaining a sp
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 to in Batch Mode.
>![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.
> 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 blank language entry. If not included, tracks with a blank language value will be removed.
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.
>![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
@ -138,18 +162,18 @@ There is no way to force the script to remove audio tracks with these codes.
### Examples
```shell
-d 2 # Enable debugging level 2, audio and subtitles
# languages detected from Radarr/Sonarr
-a :eng:und -s :eng # Keep English and Unknown audio, and English subtitles
-a :org:eng -s :eng # Keep English and Original audio, and English subtitles
:eng "" # Keep English audio and remove all subtitles
-d :eng:kor:jpn :eng:spa # Enable debugging level 1, keeping English, Korean, and Japanese audio, and
# English and Spanish subtitles
-d 2 # Enable debugging level 2, audio and subtitles
# languages detected from Radarr/Sonarr
-a :eng:und -s :eng # Keep English and Unknown audio, and English subtitles
-a :org:eng -s :eng # Keep English and Original audio, and English subtitles
:eng "" # Keep English audio and remove all subtitles
-d -a :eng:kor:jpn -s :eng:spa # Enable debugging level 1, keeping English, Korean, and Japanese audio, and
# English and Spanish subtitles
-f "/path/to/movies/Finding Nemo (2003).mkv" -a :eng:und -s :eng
# Batch Mode
# Keep English and Unknown audio and English subtitles, converting
# video specified
-a :any -s "" # Keep all audio and remove all subtitles
# Batch Mode
# Keep English and Unknown audio and English subtitles, converting
# video specified
-a :any -s "" # Keep all audio and remove all subtitles
```
### Wrapper Scripts
@ -183,7 +207,7 @@ To configure an entry from the [Examples](./README.md#examples) section above, c
```shell
#!/bin/bash
. /usr/local/bin/striptracks.sh -d :eng:kor:jpn :eng:spa
. /usr/local/bin/striptracks.sh -d -a :eng:kor:jpn -s :eng:spa
```
Make it executable:
@ -221,17 +245,23 @@ find /movies/ -type f \( -name "*.mkv" -o -name "*.avi" -o -name "*.mp4" \) | wh
```
### Logs
A log file is created for the script activity called:
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*
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.
>![danger] **NOTE:** 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.*
# Uninstall
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.
___
# Credits

View File

@ -22,6 +22,8 @@
# stat
# nice
# basename
# dirname
# mktemp
# Exit codes:
# 0 - success; or test
@ -36,6 +38,7 @@
# 9 - mkvmerge get media info failed
# 10 - remuxing completed, but no output file found
# 11 - source video had no audio or subtitle tracks
# 12 - log file is not writable
# 13 - awk script exited abnormally
# 16 - could not delete the original file
# 17 - Radarr/Sonarr API error
@ -65,23 +68,27 @@ mode.
Source: https://github.com/TheCaptain989/radarr-striptracks
Usage:
$0 [{-d|--debug} [<level>]] [[{-f|--file} <video_file>] {-a|--audio} <audio_languages> [{-s|--subs} <subtitle_languages>]]
$0 [{-a|--audio} <audio_languages> [{-s|--subs} <subtitle_languages>] [{-f|--file} <video_file>]] [{-l|--log} <log_file>] [{-d|--debug} [<level>]]
Options and Arguments:
-d, --debug [<level>] enable debug logging
Level is optional, default of 1 (low)
-a, --audio <audio_languages> audio languages to keep
-a, --audio <audio_languages> Audio languages to keep
ISO639-2 code(s) prefixed with a colon \`:\`
Multiple codes may be concatenated.
-s, --subs <subtitle_languages> subtitles languages to keep
multiple codes may be concatenated.
-s, --subs <subtitle_languages> Subtitles languages to keep
ISO639-2 code(s) prefixed with a colon \`:\`
Multiple codes may be concatenated.
-f, --file <video_file> if included, the script enters batch mode
multiple codes may be concatenated.
-f, --file <video_file> If included, the script enters batch mode
and converts the specified video file.
WARNING: Do not use this argument when called
from Radarr or Sonarr!
--help display this help and exit
--version display script version and exit
-l, --log <log_file> Log filename
[default: /config/log/striptracks.txt]
-d, --debug [<level>] Enable debug logging
level is optional, between 1-3
1 is lowest, 3 is highest
[default: 1]
--help Display this help and exit
--version Display script version and exit
When audio_languages and subtitle_languages are omitted the script detects the
audio or subtitle languages configured in the Radarr or Sonarr profile. When
@ -133,6 +140,16 @@ while (( "$#" )); do
shift
fi
;;
-l|--log ) # Log file
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
export striptracks_log="$2"
shift 2
else
echo "Error|Invalid option: $1 requires an argument." >&2
usage
exit 1
fi
;;
--help ) # Display usage
usage
exit 0
@ -263,7 +280,6 @@ else
fi
export striptracks_rescan_api="Rescan${striptracks_video_type^}"
export striptracks_eventtype="${striptracks_type,,}_eventtype"
export striptracks_tempvideo="${striptracks_video%.*}.tmp"
export striptracks_newvideo="${striptracks_video%.*}.mkv"
# If this were defined directly in Radarr or Sonarr this would not be needed here
# shellcheck disable=SC2089
@ -277,7 +293,7 @@ function log {(
while read -r
do
# shellcheck disable=2046
echo $(date +"%Y-%-m-%-d %H:%M:%S.%1N")\|"[$striptracks_pid]$REPLY" >>"$striptracks_log"
echo $(date +"%Y-%-m-%-d %H:%M:%S.%1N")"|[$striptracks_pid]$REPLY" >>"$striptracks_log"
local striptracks_filesize=$(stat -c %s "$striptracks_log")
if [ $striptracks_filesize -gt $striptracks_maxlogsize ]
then
@ -734,6 +750,25 @@ function end_script {
}
### End Functions
# Check that log path exists
if [ ! -d "$(dirname $striptracks_log)" ]; then
[ $striptracks_debug -ge 1 ] && echo "Debug|Log file path does not exist: '$(dirname $striptracks_log)'. Using log file in current directory."
striptracks_log=./striptracks.txt
fi
# Check that the log file exists
if [ ! -f "$striptracks_log" ]; then
echo "Info|Creating a new log file: $striptracks_log"
touch "$striptracks_log" 2>&1
fi
# Check that the log file is writable
if [ ! -w "$striptracks_log" ]; then
echo "Error|Log file '$striptracks_log' is not writable or does not exist." >&2
striptracks_log=/dev/null
striptracks_exitstatus=12
fi
# Check for required binaries
if [ ! -f "/usr/bin/mkvmerge" ]; then
striptracks_message="Error|/usr/bin/mkvmerge is required by this script"
@ -829,6 +864,12 @@ if [ ! -f "$striptracks_video" ]; then
end_script 5
fi
# Create temporary filename
striptracks_basename="$(basename -- "${striptracks_video}")"
striptracks_fileroot="${striptracks_basename%.*}"
export striptracks_tempvideo="$(dirname -- "${striptracks_video}")/$(mktemp -u -- "${striptracks_fileroot:0:5}.tmp.XXXXXX")"
[ $striptracks_debug -ge 1 ] && echo "Debug|Using temporary file \"$striptracks_tempvideo\"" | log
#### Prep work. Includes detect languages configured in Radarr/Sonarr, quality of video, etc.
# Bypass if using batch mode
if [ "$striptracks_type" = "batch" ]; then
@ -963,7 +1004,7 @@ fi
#### BEGIN MAIN
# shellcheck disable=SC2046
striptracks_filesize=$(numfmt --to iec --format "%.3f" $(stat -c %s "$striptracks_video"))
striptracks_filesize=$(stat -c %s "${striptracks_video}" | numfmt --to iec --format "%.3f")
striptracks_message="Info|${striptracks_type^} event: ${!striptracks_eventtype}, Video: $striptracks_video, Size: $striptracks_filesize, AudioKeep: $striptracks_audiokeep, SubsKeep: $striptracks_subskeep"
echo "$striptracks_message" | log
@ -1172,6 +1213,14 @@ else
}
fi
# Another check for the temporary file, to make sure it wasn't deleted
if [ ! -f "$striptracks_tempvideo" ]; then
striptracks_message="Error|${striptracks_type^} deleted the temporary remuxed file: \"$striptracks_tempvideo\". Halting."
echo "$striptracks_message" | log
echo "$striptracks_message" >&2
end_script 10
fi
# Rename the temporary video file to MKV
[ $striptracks_debug -ge 1 ] && echo "Debug|Renaming: \"$striptracks_tempvideo\" to \"$striptracks_newvideo\"" | log
mv -f "$striptracks_tempvideo" "$striptracks_newvideo" 2>&1 | log
@ -1183,7 +1232,7 @@ striptracks_return=$?; [ $striptracks_return -ne 0 ] && {
}
# shellcheck disable=SC2046
striptracks_filesize=$(numfmt --to iec --format "%.3f" $(stat -c %s "$striptracks_newvideo"))
striptracks_filesize=$(stat -c %s "${striptracks_newvideo}" | numfmt --to iec --format "%.3f")
striptracks_message="Info|New size: $striptracks_filesize"
echo "$striptracks_message" | log