mirror of
https://github.com/TrezOne/docker-mods-uptime-kuma-timeout-fix.git
synced 2026-07-18 16:58:27 -04:00
Release 2.0
- Script can now be called with no arguments. Languages are pulled from the configured quality or language profile. Command line arguments are still supported and override what is detected. - Only Radarr and Sonarr version 3 and later are supported. Using API v3 for most functions. - Losing quality setting during rescan is 100% fixed in both Radarr and Sonarr - Now uses the API to detect RecycleBin (removing undocumented dependency on sqlite3) - Fixes formatting bug with submitted JSON in curl - Adding URL quoting to curl commands - Renamed more variables to avoid name collisions - Added additional debug logging
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 63 KiB |
@@ -1,7 +1,9 @@
|
|||||||
# About
|
# About
|
||||||
A [Docker Mod](https://github.com/linuxserver/docker-mods) for the LinuxServer.io Radarr/Sonarr 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 streams, keeping only the desired languages.
|
||||||
|
|
||||||
**One unified script works in both Radarr and Sonarr. Use this mod in either container!**
|
**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**
|
||||||
|
|
||||||
|
**This unified script works in both Radarr and Sonarr. Use this mod in either container!**
|
||||||
>**NOTE:** This mod supports Linux OSes only.
|
>**NOTE:** This mod supports Linux OSes only.
|
||||||
|
|
||||||
Container info:
|
Container info:
|
||||||
@@ -10,8 +12,6 @@ Container info:
|
|||||||
Production Container info: 
|
Production Container info: 
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
>**NOTE:** See the [Sonarr/Radarr v2 Builds](./README.md#sonarrradarr-v2-builds) section below for important differences to these instructions for v2 builds.
|
|
||||||
|
|
||||||
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 Docker Hub:
|
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 Docker Hub:
|
||||||
`docker pull linuxserver/radarr:latest` OR
|
`docker pull linuxserver/radarr:latest` OR
|
||||||
`docker pull linuxserver/sonarr:latest`
|
`docker pull linuxserver/sonarr:latest`
|
||||||
@@ -20,7 +20,7 @@ Production Container info: **
|
**[linuxserver/radarr](https://hub.docker.com/r/linuxserver/radarr "Radarr Docker container")**
|
||||||
**[linuxserver/sonarr](https://hub.docker.com/r/linuxserver/sonarr "Sonarr 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:
|
1. Add the **DOCKER_MODS** environment variable to the `docker run` command, as follows:
|
||||||
|
- Dev/test release: `-e DOCKER_MODS=thecaptain989/radarr-striptracks:latest`
|
||||||
- Stable release: `-e DOCKER_MODS=linuxserver/mods:radarr-striptracks`
|
- Stable release: `-e DOCKER_MODS=linuxserver/mods:radarr-striptracks`
|
||||||
|
|
||||||
*Example Docker CLI Configuration*
|
*Example Docker CLI Configuration*
|
||||||
@@ -44,17 +44,14 @@ Production Container info: 
|

|
||||||
|
|
||||||
<ins>This is a wrapper script that calls striptracks.sh with the following arguments, which keep English audio and subtitles only!</ins>
|
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.
|
||||||
`:eng:und :eng`
|
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.
|
||||||
|
|
||||||
*For any other combinations of audio and subtitles you **must** either use one of the [included wrapper scripts](./README.md#included-wrapper-scripts) or create a custom script with the codes for the languages you want to keep. See the [Syntax](./README.md#syntax) section below.*
|
|
||||||
*Do not put `striptracks.sh` in the **Path** field!*
|
|
||||||
|
|
||||||
## Usage
|
## 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.
|
||||||
@@ -65,14 +62,27 @@ If you've configured the Radarr/Sonarr **Recycle Bin** path correctly, the origi
|
|||||||
![danger] **NOTE:** If you have *not* configured the Recycle Bin, the original video file will be deleted/overwritten and permanently lost.
|
![danger] **NOTE:** If you have *not* configured the Recycle Bin, the original video file will be deleted/overwritten and permanently lost.
|
||||||
|
|
||||||
### Syntax
|
### Syntax
|
||||||
>**NOTE:** The **Arguments** field for Custom Scripts was removed in Radarr and Sonarr v3 due to security concerns. To support options with these versions and later,
|
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.
|
||||||
a wrapper script must be manually created that will call *striptracks.sh* with the required arguments.
|
|
||||||
|
#### Automatic Language Detection
|
||||||
|
Both audio and subtitles that match the selected language(s) are kept.
|
||||||
|
|
||||||
|
*Radarr Quality Profile Example*
|
||||||
|

|
||||||
|
|
||||||
|
*Sonarr Language Profile Example*
|
||||||
|

|
||||||
|
|
||||||
|
>**Note:** The intent of the Radarr language selection 'Original' is not well documented. For the purposes of this script, it has the same function as 'Any' and will preserve all languages in the video file.
|
||||||
|
|
||||||
|
#### Manual Override
|
||||||
|
The script still supports command line arguments that can override what is detected. More granular control can be therefore be exerted or extended using tagging and defining multiple Connect scripts (this is outside the scope of this documentation).
|
||||||
|
|
||||||
The script accepts two command line arguments and one option:
|
The script accepts two command line arguments and one option:
|
||||||
|
|
||||||
`[-d] <audio_languages> <subtitle_languages>`
|
`[-d] [<audio_languages> [<subtitle_languages>]]`
|
||||||
|
|
||||||
The `<audio_languages>` and `<subtitle_languages>` arguments are colon (:) prepended language codes in [ISO639-2](https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes "List of ISO 639-2 codes") format.
|
The `<audio_languages>` and `<subtitle_languages>` are optional arguments that are colon (:) prepended language codes in [ISO639-2](https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes "List of ISO 639-2 codes") format.
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
* :eng
|
* :eng
|
||||||
@@ -82,9 +92,7 @@ For example:
|
|||||||
...etc.
|
...etc.
|
||||||
|
|
||||||
Multiple codes may be concatenated, such as `:eng:spa` for both English and Spanish.
|
Multiple codes may be concatenated, such as `:eng:spa` for both English and Spanish.
|
||||||
**These codes are mandatory.** There are no defaults.
|
|
||||||
|
|
||||||
The wrapper script noted above uses `:eng:und :eng`, which will keep English and Undetermined audio and English subtitles.
|
|
||||||
>**NOTE:** The script is smart enough to not remove the last audio track. This way you don't have to specify every possible language if you are importing a
|
>**NOTE:** The script is smart enough to not remove the last audio track. This way you don't have to specify every possible language if you are importing a
|
||||||
foreign film, for example.
|
foreign film, for example.
|
||||||
|
|
||||||
@@ -98,11 +106,15 @@ The `-d` option enables debug logging.
|
|||||||
# Spanish subtitles
|
# Spanish subtitles
|
||||||
```
|
```
|
||||||
|
|
||||||
### Included 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
|
||||||
For your convenience, several wrapper scripts are included in the `/usr/local/bin/` directory.
|
For your convenience, several wrapper scripts are included in the `/usr/local/bin/` directory.
|
||||||
You may use any of these scripts in place of the `striptracks-eng.sh` mentioned in the [Installation](./README.md#installation) section above.
|
You may use any of these scripts in place of `striptracks.sh` mentioned in the [Installation](./README.md#installation) section above.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
striptracks-debug.sh # Use detected languages, but enable debug logging
|
||||||
striptracks-dut.sh # Keep Dutch audio and subtitles
|
striptracks-dut.sh # Keep Dutch audio and subtitles
|
||||||
striptracks-eng.sh # Keep English and Undetermined audio and English subtitles
|
striptracks-eng.sh # Keep English and Undetermined audio and English subtitles
|
||||||
striptracks-eng-debug.sh # Keep English and Undetermined audio and English subtitles, and enable debug logging
|
striptracks-eng-debug.sh # Keep English and Undetermined audio and English subtitles, and enable debug logging
|
||||||
@@ -114,7 +126,7 @@ striptracks-ger.sh # Keep German audio and subtitles
|
|||||||
striptracks-spa.sh # Keep Spanish audio and subtitles
|
striptracks-spa.sh # Keep Spanish audio and subtitles
|
||||||
```
|
```
|
||||||
|
|
||||||
### Example Wrapper Script
|
#### Example Wrapper Script
|
||||||
To configure the last entry from the [Examples](./README.md#examples) section above, create and save a file called `striptracks-custom.sh` to `/config` containing the following text:
|
To configure the last 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
|
```shell
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
@@ -126,7 +138,7 @@ Make it executable:
|
|||||||
chmod +x /config/striptracks-custom.sh
|
chmod +x /config/striptracks-custom.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
Then put `/config/striptracks-custom.sh` in the **Path** field in place of `/usr/local/bin/striptracks-eng.sh` mentioned in the [Installation](./README.md#installation) section above.
|
Then put `/config/striptracks-custom.sh` in the **Path** field in place of `/usr/local/bin/striptracks.sh` mentioned in the [Installation](./README.md#installation) section above.
|
||||||
|
|
||||||
>**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.
|
>**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.
|
||||||
|
|
||||||
@@ -147,31 +159,6 @@ Log rotation is performed with 5 log files of 512KB each being kept.
|
|||||||
|
|
||||||
___
|
___
|
||||||
|
|
||||||
## Sonarr/Radarr v2 Builds
|
|
||||||
>![warning] **Warning: Legacy Releases**
|
|
||||||
>The Sonarr/Radarr v2 Builds of Radarr and Sonarr are no longer being developed and are considered legacy. However, this mod works with all versions of the container.
|
|
||||||
|
|
||||||
<ins>Important differences for Sonarr/Radarr v2 Builds</ins>
|
|
||||||
### Legacy Installation
|
|
||||||
Substitute the following step for step #3 noted in the [Installation](./README.md#installation) section above.
|
|
||||||
3. After all of the above configuration is complete, to use mkvmerge:
|
|
||||||
1. Configure a custom script from the Radarr/Sonnar *Settings* > *Connect* screen and type the following in the **Path** field:
|
|
||||||
`/usr/local/bin/striptracks.sh`
|
|
||||||
|
|
||||||
2. Add the codes for the audio and subtitle languages you want to keep as **Arguments** (details in the [Syntax](./README.md#syntax) section above):
|
|
||||||
<ins>Suggested Example</ins>
|
|
||||||
`:eng:und :eng`
|
|
||||||
|
|
||||||
*Example*
|
|
||||||

|
|
||||||
|
|
||||||
### Legacy Triggers
|
|
||||||
The only events/notification triggers that have been tested are **On Download** and **On Upgrade**
|
|
||||||
|
|
||||||
### Legacy Logs
|
|
||||||
The log can be inspected or downloaded from Radarr/Sonarr under *System* > *Log Files*
|
|
||||||
|
|
||||||
___
|
|
||||||
# Credits
|
# Credits
|
||||||
|
|
||||||
This would not be possible without the following:
|
This would not be possible without the following:
|
||||||
|
|||||||
+1
-2
@@ -6,8 +6,7 @@ Only the latest major and minor version are supported.
|
|||||||
|
|
||||||
| Version | Supported |
|
| Version | Supported |
|
||||||
| ------- | ------------------ |
|
| ------- | ------------------ |
|
||||||
| 1.3.x | :heavy_check_mark: |
|
| 2.x | :heavy_check_mark: |
|
||||||
| < 1.3 | :x: |
|
|
||||||
|
|
||||||
## Reporting a Vulnerability
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
. /usr/local/bin/striptracks.sh -d
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
. /usr/local/bin/striptracks.sh :dut :dut
|
. /usr/local/bin/striptracks.sh :nld:dut :nld:dut
|
||||||
|
|||||||
+314
-175
@@ -10,6 +10,8 @@
|
|||||||
#
|
#
|
||||||
# Put a colon `:` in front of every language code. Expects ISO639-2 codes
|
# Put a colon `:` in front of every language code. Expects ISO639-2 codes
|
||||||
|
|
||||||
|
# NOTE: This has been updated to work with v3 API only. Far too many complications trying to keep multiple version compatible.
|
||||||
|
|
||||||
# Dependencies:
|
# Dependencies:
|
||||||
# mkvmerge
|
# mkvmerge
|
||||||
# awk
|
# awk
|
||||||
@@ -28,6 +30,7 @@
|
|||||||
# 5 - specified video file not found
|
# 5 - specified video file not found
|
||||||
# 6 - unable to rename video to temp video
|
# 6 - unable to rename video to temp video
|
||||||
# 7 - unknown environment
|
# 7 - unknown environment
|
||||||
|
# 8 - unsupported Radarr/Sonarr version (v2)
|
||||||
# 10 - remuxing completed, but no output file found
|
# 10 - remuxing completed, but no output file found
|
||||||
# 20 - general error
|
# 20 - general error
|
||||||
|
|
||||||
@@ -39,38 +42,40 @@ export striptracks_log=/config/logs/striptracks.txt
|
|||||||
export striptracks_maxlogsize=512000
|
export striptracks_maxlogsize=512000
|
||||||
export striptracks_maxlog=4
|
export striptracks_maxlog=4
|
||||||
export striptracks_debug=0
|
export striptracks_debug=0
|
||||||
|
export striptracks_langcodes=
|
||||||
export striptracks_type=$(printenv | sed -n 's/_eventtype *=.*$//p')
|
export striptracks_type=$(printenv | sed -n 's/_eventtype *=.*$//p')
|
||||||
if [[ "${striptracks_type,,}" = "radarr" ]]; then
|
if [[ "${striptracks_type,,}" = "radarr" ]]; then
|
||||||
export striptracks_video="$radarr_moviefile_path"
|
export striptracks_video="$radarr_moviefile_path"
|
||||||
export striptracks_api_endpoint="movie"
|
export striptracks_video_api="movie"
|
||||||
|
export striptracks_video_id="${radarr_movie_id}"
|
||||||
|
export striptracks_videofile_api="moviefile"
|
||||||
|
export striptracks_videofile_id="${radarr_moviefile_id}"
|
||||||
|
export striptracks_rescan_id="${radarr_movie_id}"
|
||||||
export striptracks_json_quality_root=".movieFile"
|
export striptracks_json_quality_root=".movieFile"
|
||||||
export striptracks_video_type="movie"
|
export striptracks_video_type="movie"
|
||||||
|
export striptracks_profile_type="quality"
|
||||||
export striptracks_title="$radarr_movie_title ($radarr_movie_year)"
|
export striptracks_title="$radarr_movie_title ($radarr_movie_year)"
|
||||||
elif [[ "${striptracks_type,,}" = "sonarr" ]]; then
|
elif [[ "${striptracks_type,,}" = "sonarr" ]]; then
|
||||||
export striptracks_video="$sonarr_episodefile_path"
|
export striptracks_video="$sonarr_episodefile_path"
|
||||||
export striptracks_api_endpoint="episodefile"
|
export striptracks_video_api="episode"
|
||||||
export striptracks_json_quality_root=""
|
export striptracks_video_id="${sonarr_episodefile_episodeids}"
|
||||||
|
export striptracks_videofile_api="episodefile"
|
||||||
|
export striptracks_videofile_id="${sonarr_episodefile_id}"
|
||||||
|
export striptracks_rescan_id="${sonarr_series_id}"
|
||||||
|
export striptracks_json_quality_root=".episodeFile"
|
||||||
export striptracks_video_type="series"
|
export striptracks_video_type="series"
|
||||||
|
export striptracks_profile_type="language"
|
||||||
export striptracks_title="$sonarr_series_title $(numfmt --format "%02f" ${sonarr_episodefile_seasonnumber:-0})x$(numfmt --format "%02f" ${sonarr_episodefile_episodenumbers:-0}) - $sonarr_episodefile_episodetitles"
|
export striptracks_title="$sonarr_series_title $(numfmt --format "%02f" ${sonarr_episodefile_seasonnumber:-0})x$(numfmt --format "%02f" ${sonarr_episodefile_episodenumbers:-0}) - $sonarr_episodefile_episodetitles"
|
||||||
else
|
else
|
||||||
echo "Unknown environment: ${striptracks_type}"
|
echo "Unknown environment: ${striptracks_type}"
|
||||||
exit 7
|
exit 7
|
||||||
fi
|
fi
|
||||||
export striptracks_api="Rescan${striptracks_video_type^}"
|
export striptracks_rescan_api="Rescan${striptracks_video_type^}"
|
||||||
export striptracks_json_key="${striptracks_video_type}Id"
|
export striptracks_json_key="${striptracks_video_type}Id"
|
||||||
export striptracks_api_endpoint_idname="${striptracks_type,,}_${striptracks_api_endpoint}_id"
|
|
||||||
export striptracks_api_endpoint_id="${!striptracks_api_endpoint_idname}"
|
|
||||||
export striptracks_video_idname="${striptracks_type,,}_${striptracks_video_type}_id"
|
|
||||||
export striptracks_video_id="${!striptracks_video_idname}"
|
|
||||||
export striptracks_eventtype="${striptracks_type,,}_eventtype"
|
export striptracks_eventtype="${striptracks_type,,}_eventtype"
|
||||||
export striptracks_tempvideo="${striptracks_video}.tmp"
|
export striptracks_tempvideo="${striptracks_video}.tmp"
|
||||||
export striptracks_newvideo="${striptracks_video%.*}.mkv"
|
export striptracks_newvideo="${striptracks_video%.*}.mkv"
|
||||||
export striptracks_db="/config/${striptracks_type,,}.db"
|
striptracks_isocodemap='{"languages":[{"language":{"id":-1,"name":"Any","iso639-2":["ara","bul","zho","chi","ces","cze","dan","nld","dut","eng","fin","fra","fre","deu","ger","ell","gre","heb","hin","hun","isl","ice","ita","jpn","kor","lit","nor","pol","por","ron","rom","rus","spa","swe","tha","tur","vie","und"]}},{"language":{"id":-2,"name":"Original","iso639-2":["ara","bul","zho","chi","ces","cze","dan","nld","dut","eng","fin","fra","fre","deu","ger","ell","gre","heb","hin","hun","isl","ice","ita","jpn","kor","lit","nor","pol","por","ron","rom","rus","spa","swe","tha","tur","vie","und"]}},{"language":{"id":27,"name":"Hindi","iso639-2":["hin"]}},{"language":{"id":26,"name":"Arabic","iso639-2":["ara"]}},{"language":{"id":0,"name":"Unknown","iso639-2":["und"]}},{"language":{"id":13,"name":"Vietnamese","iso639-2":["vie"]}},{"language":{"id":17,"name":"Turkish","iso639-2":["tur"]}},{"language":{"id":14,"name":"Swedish","iso639-2":["swe"]}},{"language":{"id":3,"name":"Spanish","iso639-2":["spa"]}},{"language":{"id":11,"name":"Russian","iso639-2":["rus"]}},{"language":{"id":18,"name":"Portuguese","iso639-2":["por"]}},{"language":{"id":12,"name":"Polish","iso639-2":["pol"]}},{"language":{"id":15,"name":"Norwegian","iso639-2":["nor"]}},{"language":{"id":24,"name":"Lithuanian","iso639-2":["lit"]}},{"language":{"id":21,"name":"Korean","iso639-2":["kor"]}},{"language":{"id":8,"name":"Japanese","iso639-2":["jpn"]}},{"language":{"id":5,"name":"Italian","iso639-2":["ita"]}},{"language":{"id":9,"name":"Icelandic","iso639-2":["isl","ice"]}},{"language":{"id":22,"name":"Hungarian","iso639-2":["hun"]}},{"language":{"id":23,"name":"Hebrew","iso639-2":["heb"]}},{"language":{"id":20,"name":"Greek","iso639-2":["ell","gre"]}},{"language":{"id":4,"name":"German","iso639-2":["deu","ger"]}},{"language":{"id":2,"name":"French","iso639-2":["fra","fre"]}},{"language":{"id":19,"name":"Flemish","iso639-2":["nld","dut"]}},{"language":{"id":16,"name":"Finnish","iso639-2":["fin"]}},{"language":{"id":1,"name":"English","iso639-2":["eng"]}},{"language":{"id":7,"name":"Dutch","iso639-2":["nld","dut"]}},{"language":{"id":6,"name":"Danish","iso639-2":["dan"]}},{"language":{"id":25,"name":"Czech","iso639-2":["ces","cze"]}},{"language":{"id":10,"name":"Chinese","iso639-2":["zho","chi"]}}]}'
|
||||||
if [ ! -f "$striptracks_db" ]; then
|
|
||||||
striptracks_db=/config/nzbdrone.db
|
|
||||||
fi
|
|
||||||
export striptracks_recyclebin=$(sqlite3 $striptracks_db 'SELECT Value FROM Config WHERE Key="recyclebin"')
|
|
||||||
RET=$?; [ "$RET" != 0 ] && >&2 echo "WARNING[$RET]: Unable to read recyclebin information from database \"$striptracks_db\""
|
|
||||||
|
|
||||||
### Functions
|
### Functions
|
||||||
function usage {
|
function usage {
|
||||||
@@ -81,7 +86,7 @@ Video remuxing script designed for use with Radarr and Sonarr
|
|||||||
Source: https://github.com/TheCaptain989/radarr-striptracks
|
Source: https://github.com/TheCaptain989/radarr-striptracks
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
$0 [-d] <audio_languages> <subtitle_languages>
|
$0 [-d] [<audio_languages> [<subtitle_languages>]]
|
||||||
|
|
||||||
Options and Arguments:
|
Options and Arguments:
|
||||||
-d enable debug logging
|
-d enable debug logging
|
||||||
@@ -106,8 +111,8 @@ function log {(
|
|||||||
while read
|
while read
|
||||||
do
|
do
|
||||||
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 FILESIZE=$(stat -c %s "$striptracks_log")
|
local striptracks_filesize=$(stat -c %s "$striptracks_log")
|
||||||
if [ $FILESIZE -gt $striptracks_maxlogsize ]
|
if [ $striptracks_filesize -gt $striptracks_maxlogsize ]
|
||||||
then
|
then
|
||||||
for i in $(seq $((striptracks_maxlog-1)) -1 0); do
|
for i in $(seq $((striptracks_maxlog-1)) -1 0); do
|
||||||
[ -f "${striptracks_log::-4}.$i.txt" ] && mv "${striptracks_log::-4}."{$i,$((i+1))}".txt"
|
[ -f "${striptracks_log::-4}.$i.txt" ] && mv "${striptracks_log::-4}."{$i,$((i+1))}".txt"
|
||||||
@@ -120,68 +125,98 @@ function log {(
|
|||||||
# Inspired by https://stackoverflow.com/questions/893585/how-to-parse-xml-in-bash
|
# Inspired by https://stackoverflow.com/questions/893585/how-to-parse-xml-in-bash
|
||||||
function read_xml {
|
function read_xml {
|
||||||
local IFS=\>
|
local IFS=\>
|
||||||
read -d \< ENTITY CONTENT
|
read -d \< striptracks_xml_entity striptracks_xml_content
|
||||||
}
|
}
|
||||||
# Get video information
|
# Get video information
|
||||||
function get_video_info {
|
function get_video_info {
|
||||||
[ $striptracks_debug -eq 1 ] && echo "Debug|Getting video information for $striptracks_api_endpoint '$striptracks_api_endpoint_id'. Calling ${striptracks_type^} API using GET and URL 'http://$striptracks_bindaddress:$striptracks_port$striptracks_urlbase/api/$striptracks_api_endpoint/$striptracks_api_endpoint_id?apikey=(removed)'" | log
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Getting video information for $striptracks_video_api '$striptracks_video_id'. Calling ${striptracks_type^} API using GET and URL '$striptracks_api_url/v3/$striptracks_video_api/$striptracks_video_id'" | log
|
||||||
RESULT=$(curl -s -H "Content-Type: application/json" \
|
striptracks_result=$(curl -s -H "X-Api-Key: $striptracks_apikey" \
|
||||||
-X GET http://$striptracks_bindaddress:$striptracks_port$striptracks_urlbase/api/$striptracks_api_endpoint/$striptracks_api_endpoint_id?apikey=$striptracks_apikey)
|
-X GET "$striptracks_api_url/v3/$striptracks_video_api/$striptracks_video_id")
|
||||||
[ $striptracks_debug -eq 1 ] && echo "API returned: $RESULT" | awk '{print "Debug|"$0}' | log
|
[ $striptracks_debug -eq 1 ] && echo "API returned: $striptracks_result" | awk '{print "Debug|"$0}' | log
|
||||||
if [ "$(echo $RESULT | jq -crM .path)" != "null" ]; then
|
if [ "$(echo $striptracks_result | jq -crM .hasFile)" = "true" ]; then
|
||||||
local RET=0
|
local striptracks_return=0
|
||||||
else
|
else
|
||||||
local RET=1
|
local striptracks_return=1
|
||||||
fi
|
fi
|
||||||
return $RET
|
return $striptracks_return
|
||||||
}
|
}
|
||||||
# Initiate API Rescan request
|
# Get video file information
|
||||||
function rescan {
|
function get_videofile_info {
|
||||||
MSG="Info|Calling ${striptracks_type^} API to rescan ${striptracks_video_type}, try #$i"
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Getting video file information for $striptracks_videofile_api id '$striptracks_videofile_id'. Calling ${striptracks_type^} API using GET and URL '$striptracks_api_url/v3/$striptracks_videofile_api/$striptracks_videofile_id'" | log
|
||||||
echo "$MSG" | log
|
striptracks_result=$(curl -s -H "X-Api-Key: $striptracks_apikey" \
|
||||||
[ $striptracks_debug -eq 1 ] && echo "Debug|Forcing rescan of $striptracks_json_key '$striptracks_video_id', try #$i. Calling ${striptracks_type^} API '$striptracks_api' using POST and URL 'http://$striptracks_bindaddress:$striptracks_port$striptracks_urlbase/api/command?apikey=(removed)'" | log
|
-X GET "$striptracks_api_url/v3/$striptracks_videofile_api/$striptracks_videofile_id")
|
||||||
RESULT=$(curl -s -d "{name: '$striptracks_api', $striptracks_json_key: $striptracks_video_id}" -H "Content-Type: application/json" \
|
[ $striptracks_debug -eq 1 ] && echo "API returned: $striptracks_result" | awk '{print "Debug|"$0}' | log
|
||||||
-X POST http://$striptracks_bindaddress:$striptracks_port$striptracks_urlbase/api/command?apikey=$striptracks_apikey)
|
if [ "$(echo $striptracks_result | jq -crM .path)" != "null" ]; then
|
||||||
[ $striptracks_debug -eq 1 ] && echo "API returned: $RESULT" | awk '{print "Debug|"$0}' | log
|
local striptracks_return=0
|
||||||
JOBID="$(echo $RESULT | jq -crM .id)"
|
|
||||||
if [ "$JOBID" != "null" ]; then
|
|
||||||
local RET=0
|
|
||||||
else
|
else
|
||||||
local RET=1
|
local striptracks_return=1
|
||||||
fi
|
fi
|
||||||
return $RET
|
return $striptracks_return
|
||||||
|
}
|
||||||
|
# Initiate Rescan request
|
||||||
|
function rescan {
|
||||||
|
striptracks_message="Info|Calling ${striptracks_type^} API to rescan ${striptracks_video_type}, try #$i"
|
||||||
|
echo "$striptracks_message" | log
|
||||||
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Forcing rescan of $striptracks_json_key '$striptracks_rescan_id', try #$i. Calling ${striptracks_type^} API '$striptracks_rescan_api' using POST and URL '$striptracks_api_url/v3/command'" | log
|
||||||
|
striptracks_result=$(curl -s -H "X-Api-Key: $striptracks_apikey" -H "Content-Type: application/json" \
|
||||||
|
-d "{\"name\": \"$striptracks_rescan_api\", \"$striptracks_json_key\": $striptracks_rescan_id}" \
|
||||||
|
-X POST "$striptracks_api_url/v3/command")
|
||||||
|
[ $striptracks_debug -eq 1 ] && echo "API returned: $striptracks_result" | awk '{print "Debug|"$0}' | log
|
||||||
|
striptracks_jobid="$(echo $striptracks_result | jq -crM .id)"
|
||||||
|
if [ "$striptracks_jobid" != "null" ]; then
|
||||||
|
local striptracks_return=0
|
||||||
|
else
|
||||||
|
local striptracks_return=1
|
||||||
|
fi
|
||||||
|
return $striptracks_return
|
||||||
}
|
}
|
||||||
# Check result of rescan job
|
# Check result of rescan job
|
||||||
function check_rescan {
|
function check_rescan {
|
||||||
local i=0
|
local i=0
|
||||||
for ((i=1; i <= 15; i++)); do
|
for ((i=1; i <= 15; i++)); do
|
||||||
[ $striptracks_debug -eq 1 ] && echo "Debug|Checking job $JOBID completion, try #$i. Calling ${striptracks_type^} API using GET and URL 'http://$striptracks_bindaddress:$striptracks_port$striptracks_urlbase/api/command/$JOBID?apikey=(removed)'" | log
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Checking job $striptracks_jobid completion, try #$i. Calling ${striptracks_type^} API using GET and URL '$striptracks_api_url/v3/command/$striptracks_jobid'" | log
|
||||||
RESULT=$(curl -s -H "Content-Type: application/json" \
|
striptracks_result=$(curl -s -H "X-Api-Key: $striptracks_apikey" \
|
||||||
-X GET http://$striptracks_bindaddress:$striptracks_port$striptracks_urlbase/api/command/$JOBID?apikey=$striptracks_apikey)
|
-X GET "$striptracks_api_url/v3/command/$striptracks_jobid")
|
||||||
[ $striptracks_debug -eq 1 ] && echo "API returned: $RESULT" | awk '{print "Debug|"$0}' | log
|
[ $striptracks_debug -eq 1 ] && echo "API returned: $striptracks_result" | awk '{print "Debug|"$0}' | log
|
||||||
if [ "$(echo $RESULT | jq -crM .status)" = "completed" ]; then
|
if [ "$(echo $striptracks_result | jq -crM .status)" = "completed" ]; then
|
||||||
local RET=0
|
local striptracks_return=0
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
if [ "$(echo $RESULT | jq -crM .status)" = "failed" ]; then
|
if [ "$(echo $striptracks_result | jq -crM .status)" = "failed" ]; then
|
||||||
local RET=2
|
local striptracks_return=2
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
local RET=1
|
# It may have timed out, so let's wait a second
|
||||||
|
local striptracks_return=1
|
||||||
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Job not done. Waiting 1 second." | log
|
||||||
sleep 1
|
sleep 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
return $RET
|
return $striptracks_return
|
||||||
|
}
|
||||||
|
# Get language/quality profiles
|
||||||
|
function get_profiles {
|
||||||
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Getting list of $striptracks_profile_type profiles. Calling ${striptracks_type^} API using GET and URL '$striptracks_api_url/v3/${striptracks_profile_type}Profile'" | log
|
||||||
|
striptracks_result=$(curl -s -H "X-Api-Key: $striptracks_apikey" \
|
||||||
|
-X GET "$striptracks_api_url/v3/${striptracks_profile_type}Profile")
|
||||||
|
# This returns A LOT of data, and it is normally not needed
|
||||||
|
# [ $striptracks_debug -eq 1 ] && echo "API returned: $striptracks_result" | awk '{print "Debug|"$0}' | log
|
||||||
|
if [ "$(echo $striptracks_result | jq -crM '.message?')" != "NotFound" ]; then
|
||||||
|
local striptracks_return=0
|
||||||
|
else
|
||||||
|
local striptracks_return=1
|
||||||
|
fi
|
||||||
|
return $striptracks_return
|
||||||
}
|
}
|
||||||
|
|
||||||
# Process options
|
# Process options
|
||||||
while getopts ":d" opt; do
|
while getopts ":d" opt; do
|
||||||
case ${opt} in
|
case ${opt} in
|
||||||
d ) # For debug purposes only
|
d ) # For debug purposes only
|
||||||
MSG="Debug|Enabling debug logging."
|
striptracks_message="Debug|Enabling debug logging."
|
||||||
echo "$MSG" | log
|
echo "$striptracks_message" | log
|
||||||
>&2 echo "$MSG"
|
>&2 echo "$striptracks_message"
|
||||||
striptracks_debug=1
|
striptracks_debug=1
|
||||||
printenv | sort | sed 's/^/Debug|/' | log
|
printenv | sort | sed 's/^/Debug|/' | log
|
||||||
;;
|
;;
|
||||||
@@ -189,31 +224,57 @@ while getopts ":d" opt; do
|
|||||||
done
|
done
|
||||||
shift $((OPTIND -1))
|
shift $((OPTIND -1))
|
||||||
|
|
||||||
# Check for required command line options
|
|
||||||
if [ -z "$1" ]; then
|
|
||||||
MSG="Error|No audio languages specified!"
|
|
||||||
echo "$MSG" | log
|
|
||||||
>&2 echo "$MSG"
|
|
||||||
usage
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$2" ]; then
|
|
||||||
MSG="Error|No subtitles languages specified!"
|
|
||||||
echo "$MSG" | log
|
|
||||||
>&2 echo "$MSG"
|
|
||||||
usage
|
|
||||||
exit 3
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check for required binaries
|
# Check for required binaries
|
||||||
if [ ! -f "/usr/bin/mkvmerge" ]; then
|
if [ ! -f "/usr/bin/mkvmerge" ]; then
|
||||||
MSG="Error|/usr/bin/mkvmerge is required by this script"
|
striptracks_message="Error|/usr/bin/mkvmerge is required by this script"
|
||||||
echo "$MSG" | log
|
echo "$striptracks_message" | log
|
||||||
>&2 echo "$MSG"
|
>&2 echo "$striptracks_message"
|
||||||
exit 4
|
exit 4
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check for config file
|
||||||
|
if [ -f "$striptracks_arr_config" ]; then
|
||||||
|
# Read *arr config.xml
|
||||||
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Reading from ${striptracks_type^} config file '$striptracks_arr_config'" | log
|
||||||
|
while read_xml; do
|
||||||
|
[[ $striptracks_xml_entity = "Port" ]] && striptracks_port=$striptracks_xml_content
|
||||||
|
[[ $striptracks_xml_entity = "UrlBase" ]] && striptracks_urlbase=$striptracks_xml_content
|
||||||
|
[[ $striptracks_xml_entity = "BindAddress" ]] && striptracks_bindaddress=$striptracks_xml_content
|
||||||
|
[[ $striptracks_xml_entity = "ApiKey" ]] && striptracks_apikey=$striptracks_xml_content
|
||||||
|
done < $striptracks_arr_config
|
||||||
|
|
||||||
|
[[ $striptracks_bindaddress = "*" ]] && striptracks_bindaddress=localhost
|
||||||
|
|
||||||
|
# Build URL to Radarr/Sonarr API
|
||||||
|
striptracks_api_url="http://$striptracks_bindaddress:$striptracks_port$striptracks_urlbase/api"
|
||||||
|
|
||||||
|
# Check Radarr/Sonarr version
|
||||||
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Getting ${striptracks_type^} version. Calling ${striptracks_type^} API using GET and URL '$striptracks_api_url/system/status'" | log
|
||||||
|
striptracks_arr_version=$(curl -s -H "X-Api-Key: $striptracks_apikey" \
|
||||||
|
-X GET "$striptracks_api_url/system/status" | jq -crM .version)
|
||||||
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Detected ${striptracks_type^} version $striptracks_arr_version" | log
|
||||||
|
|
||||||
|
# Requires API v3
|
||||||
|
if [ "${striptracks_arr_version/.*/}" = "2" ]; then
|
||||||
|
# Radarr/Sonarr version 2
|
||||||
|
striptracks_message="Error|This script does not support ${striptracks_type^} version ${striptracks_arr_version}. Please upgrade."
|
||||||
|
echo "$striptracks_message" | log
|
||||||
|
>&2 echo "$striptracks_message"
|
||||||
|
exit 8
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get RecycleBin
|
||||||
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Getting ${striptracks_type^} RecycleBin. Calling ${striptracks_type^} API using GET and URL '$striptracks_api_url/v3/config/mediamanagement'" | log
|
||||||
|
striptracks_recyclebin=$(curl -s -H "X-Api-Key: $striptracks_apikey" \
|
||||||
|
-X GET "$striptracks_api_url/v3/config/mediamanagement" | jq -crM .recycleBin)
|
||||||
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Detected ${striptracks_type^} RecycleBin '$striptracks_recyclebin'" | log
|
||||||
|
else
|
||||||
|
# No config file means we can't call the API. Best effort at this point.
|
||||||
|
striptracks_message="Warn|Unable to locate ${striptracks_type^} config file: '$striptracks_arr_config'"
|
||||||
|
echo "$striptracks_message" | log
|
||||||
|
>&2 echo "$striptracks_message"
|
||||||
|
fi
|
||||||
|
|
||||||
# Handle Test event
|
# Handle Test event
|
||||||
if [[ "${!striptracks_eventtype}" = "Test" ]]; then
|
if [[ "${!striptracks_eventtype}" = "Test" ]]; then
|
||||||
echo "Info|${striptracks_type^} event: ${!striptracks_eventtype}" | log
|
echo "Info|${striptracks_type^} event: ${!striptracks_eventtype}" | log
|
||||||
@@ -223,48 +284,121 @@ fi
|
|||||||
|
|
||||||
# Check if called from within Radarr/Sonarr
|
# Check if called from within Radarr/Sonarr
|
||||||
if [ -z "$striptracks_video" ]; then
|
if [ -z "$striptracks_video" ]; then
|
||||||
MSG="Error|No video file specified! Not called from Radarr/Sonarr?"
|
striptracks_message="Error|No video file specified! Not called from Radarr/Sonarr?"
|
||||||
echo "$MSG" | log
|
echo "$striptracks_message" | log
|
||||||
>&2 echo "$MSG"
|
>&2 echo "$striptracks_message"
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if source video exists
|
# Check if source video exists
|
||||||
if [ ! -f "$striptracks_video" ]; then
|
if [ ! -f "$striptracks_video" ]; then
|
||||||
MSG="Error|Input file not found: \"$striptracks_video\""
|
striptracks_message="Error|Input file not found: \"$striptracks_video\""
|
||||||
echo "$MSG" | log
|
echo "$striptracks_message" | log
|
||||||
>&2 echo "$MSG"
|
>&2 echo "$striptracks_message"
|
||||||
exit 5
|
exit 5
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#### Detect languages configured in Radarr/Sonarr
|
||||||
|
# Check for URL
|
||||||
|
if [ -n "$striptracks_api_url" ]; then
|
||||||
|
# Get quality/language profile info
|
||||||
|
if get_profiles; then
|
||||||
|
striptracks_profiles="$striptracks_result"
|
||||||
|
# Get video profile
|
||||||
|
if get_video_info; then
|
||||||
|
# Per environment logic
|
||||||
|
if [[ "${striptracks_type,,}" = "radarr" ]]; then
|
||||||
|
striptracks_profileid="$(echo $striptracks_result | jq -crM .qualityProfileId)"
|
||||||
|
striptracks_languages=$(echo $striptracks_profiles | jq -crM ".[] | select(.id == $striptracks_profileid) | .language.id")
|
||||||
|
elif [[ "${striptracks_type,,}" = "sonarr" ]]; then
|
||||||
|
striptracks_profileid="$(echo $striptracks_result | jq -crM .series.languageProfileId)"
|
||||||
|
striptracks_languages=$(echo $striptracks_profiles | jq -crM ".[] | select(.id == $striptracks_profileid) | .languages | .[] | select(.allowed).language.id")
|
||||||
|
else
|
||||||
|
# Should never fire due to previous check, but just in case
|
||||||
|
striptracks_message "Error|Unknown environment: ${striptracks_type}"
|
||||||
|
echo "$striptracks_message" | log
|
||||||
|
>&2 echo "$striptracks_message"
|
||||||
|
exit 7
|
||||||
|
fi
|
||||||
|
striptracks_profilename=$(echo $striptracks_profiles | jq -crM ".[] | select(.id == $striptracks_profileid).name")
|
||||||
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Detected $striptracks_profile_type profile '$striptracks_profilename' id '$striptracks_profileid'" | log
|
||||||
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Detected language ids of '$(echo ${striptracks_languages})'" | log
|
||||||
|
# Lookup ISO codes
|
||||||
|
for i in $striptracks_languages; do
|
||||||
|
striptracks_langcodes+=$(echo $striptracks_isocodemap | jq -jcrM ".languages | .[] | select(.language.id == $i) | .language | \":\(.\"iso639-2\"[])\"")
|
||||||
|
done
|
||||||
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Mapped language codes '$(echo ${striptracks_languages})' to ISO639-2 code string '$striptracks_langcodes'" | log
|
||||||
|
else
|
||||||
|
# 'hasFile' is False in returned JSON.
|
||||||
|
striptracks_message="Warn|The '$striptracks_video_api' API with id $striptracks_video_id returned a false hasFile."
|
||||||
|
echo "$striptracks_message" | log
|
||||||
|
>&2 echo "$striptracks_message"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Get Profiles API failed
|
||||||
|
striptracks_message="Warn|Unable to retrieve $striptracks_profile_type profiles from ${striptracks_type^} API"
|
||||||
|
echo "$striptracks_message" | log
|
||||||
|
>&2 echo "$striptracks_message"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# No URL means we can't call the API
|
||||||
|
striptracks_message="Warn|Unable to determine ${striptracks_type^} API URL."
|
||||||
|
echo "$striptracks_message" | log
|
||||||
|
>&2 echo "$striptracks_message"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check for command line options; will override the detected languages
|
||||||
|
if [ -z "$1" -a -z "$striptracks_langcodes" ]; then
|
||||||
|
striptracks_message="Error|No audio languages specified!"
|
||||||
|
echo "$striptracks_message" | log
|
||||||
|
>&2 echo "$striptracks_message"
|
||||||
|
usage
|
||||||
|
exit 2
|
||||||
|
elif [ -z "$1" ]; then
|
||||||
|
striptracks_audiokeep="$striptracks_langcodes"
|
||||||
|
else
|
||||||
|
striptracks_audiokeep="$1"
|
||||||
|
fi
|
||||||
|
if [ -z "$2" -a -z "$striptracks_langcodes" ]; then
|
||||||
|
striptracks_message="Error|No subtitles languages specified!"
|
||||||
|
echo "$striptracks_message" | log
|
||||||
|
>&2 echo "$striptracks_message"
|
||||||
|
usage
|
||||||
|
exit 3
|
||||||
|
elif [ -z "$2" ]; then
|
||||||
|
striptracks_subskeep="$striptracks_langcodes"
|
||||||
|
else
|
||||||
|
striptracks_subskeep="$2"
|
||||||
|
fi
|
||||||
|
|
||||||
#### BEGIN MAIN
|
#### BEGIN MAIN
|
||||||
FILESIZE=$(numfmt --to iec --format "%.3f" $(stat -c %s "$striptracks_video"))
|
striptracks_filesize=$(numfmt --to iec --format "%.3f" $(stat -c %s "$striptracks_video"))
|
||||||
MSG="Info|${striptracks_type^} event: ${!striptracks_eventtype}, Video: $striptracks_video, Size: $FILESIZE, AudioKeep: $1, SubsKeep: $2"
|
striptracks_message="Info|${striptracks_type^} event: ${!striptracks_eventtype}, Video: $striptracks_video, Size: $striptracks_filesize, AudioKeep: $striptracks_audiokeep, SubsKeep: $striptracks_subskeep"
|
||||||
echo "$MSG" | log
|
echo "$striptracks_message" | log
|
||||||
|
|
||||||
# Rename the original video file to a temporary name
|
# Rename the original video file to a temporary name
|
||||||
[ $striptracks_debug -eq 1 ] && echo "Debug|Renaming: \"$striptracks_video\" to \"$striptracks_tempvideo\"" | log
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Renaming: \"$striptracks_video\" to \"$striptracks_tempvideo\"" | log
|
||||||
mv -f "$striptracks_video" "$striptracks_tempvideo" | log
|
mv -f "$striptracks_video" "$striptracks_tempvideo" | log
|
||||||
RET=$?; [ "$RET" != 0 ] && {
|
striptracks_return=$?; [ "$striptracks_return" != 0 ] && {
|
||||||
MSG="ERROR[$RET]: Unable to rename video: \"$striptracks_video\" to temp video: \"$striptracks_tempvideo\". Halting."
|
striptracks_message="ERROR[$striptracks_return]: Unable to rename video: \"$striptracks_video\" to temp video: \"$striptracks_tempvideo\". Halting."
|
||||||
echo "$MSG" | log
|
echo "$striptracks_message" | log
|
||||||
>&2 echo "$MSG"
|
>&2 echo "$striptracks_message"
|
||||||
exit 6
|
exit 6
|
||||||
}
|
}
|
||||||
|
|
||||||
# Read in the output of mkvmerge info extraction
|
# Read in the output of mkvmerge info extraction
|
||||||
[ $striptracks_debug -eq 1 ] && echo "Debug|Executing: /usr/bin/mkvmerge -J \"$striptracks_tempvideo\"" | log
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Executing: /usr/bin/mkvmerge -J \"$striptracks_tempvideo\"" | log
|
||||||
JSON=$(/usr/bin/mkvmerge -J "$striptracks_tempvideo")
|
striptracks_json=$(/usr/bin/mkvmerge -J "$striptracks_tempvideo")
|
||||||
RET=$?; [ "$RET" != 0 ] && {
|
striptracks_return=$?; [ "$striptracks_return" != 0 ] && {
|
||||||
MSG="ERROR[$RET]: Error executing mkvmerge."
|
striptracks_message="ERROR[$striptracks_return]: Error executing mkvmerge."
|
||||||
echo "$MSG" | log
|
echo "$striptracks_message" | log
|
||||||
>&2 echo "$MSG"
|
>&2 echo "$striptracks_message"
|
||||||
}
|
}
|
||||||
|
|
||||||
# This and the modified AWK script are a hack, and I know it. JQ is crazy hard to learn, BTW.
|
# This and the modified AWK script are a hack, and I know it. JQ is crazy hard to learn, BTW.
|
||||||
# Mimic the mkvmerge --identify-verbose option that has been deprecated
|
# Mimic the mkvmerge --identify-verbose option that has been deprecated
|
||||||
JSON_PROCESSED=$(echo $JSON | jq -jcrM '
|
striptracks_json_processed=$(echo $striptracks_json | jq -jcrM '
|
||||||
( if (.chapters | .[] | .num_entries) then
|
( if (.chapters | .[] | .num_entries) then
|
||||||
"Chapters: \(.chapters | .[] | .num_entries) entries\n"
|
"Chapters: \(.chapters | .[] | .num_entries) entries\n"
|
||||||
else
|
else
|
||||||
@@ -274,19 +408,19 @@ JSON_PROCESSED=$(echo $JSON | jq -jcrM '
|
|||||||
( .tracks |
|
( .tracks |
|
||||||
.[] |
|
.[] |
|
||||||
( "Track ID \(.id): \(.type) (\(.codec)) [",
|
( "Track ID \(.id): \(.type) (\(.codec)) [",
|
||||||
( [.properties | to_entries |.[] | "\(.key):\(.value | tostring | gsub(" "; "\\s"))"] | join(" ")),
|
( [.properties | to_entries | .[] | "\(.key):\(.value | tostring | gsub(" "; "\\s"))"] | join(" ")),
|
||||||
"]\n" )
|
"]\n" )
|
||||||
)
|
)
|
||||||
')
|
')
|
||||||
[ $striptracks_debug -eq 1 ] && echo "$JSON_PROCESSED" | awk '{print "Debug|"$0}' | log
|
[ $striptracks_debug -eq 1 ] && echo "$striptracks_json_processed" | awk '{print "Debug|"$0}' | log
|
||||||
|
|
||||||
echo "$JSON_PROCESSED" | awk -v Debug=$striptracks_debug \
|
echo "$striptracks_json_processed" | awk -v Debug=$striptracks_debug \
|
||||||
-v OrgVideo="$striptracks_video" \
|
-v OrgVideo="$striptracks_video" \
|
||||||
-v TempVideo="$striptracks_tempvideo" \
|
-v TempVideo="$striptracks_tempvideo" \
|
||||||
-v MKVVideo="$striptracks_newvideo" \
|
-v MKVVideo="$striptracks_newvideo" \
|
||||||
-v Title="$striptracks_title" \
|
-v Title="$striptracks_title" \
|
||||||
-v AudioKeep="$1" \
|
-v AudioKeep="$striptracks_audiokeep" \
|
||||||
-v SubsKeep="$2" '
|
-v SubsKeep="$striptracks_subskeep" '
|
||||||
BEGIN {
|
BEGIN {
|
||||||
MKVMerge="/usr/bin/mkvmerge"
|
MKVMerge="/usr/bin/mkvmerge"
|
||||||
FS="[\t\n: ]"
|
FS="[\t\n: ]"
|
||||||
@@ -382,114 +516,119 @@ END {
|
|||||||
if [ -s "$striptracks_newvideo" ]; then
|
if [ -s "$striptracks_newvideo" ]; then
|
||||||
# Use Recycle Bin if configured
|
# Use Recycle Bin if configured
|
||||||
if [ "$striptracks_recyclebin" ]; then
|
if [ "$striptracks_recyclebin" ]; then
|
||||||
[ $striptracks_debug -eq 1 ] && echo "Debug|Moving: \"$striptracks_tempvideo\" to \"${striptracks_recyclebin%/}/$(basename "$striptracks_video")"\" | log
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Recycling: \"$striptracks_tempvideo\" to \"${striptracks_recyclebin%/}/$(basename "$striptracks_video")"\" | log
|
||||||
mv "$striptracks_tempvideo" "${striptracks_recyclebin%/}/$(basename "$striptracks_video")" | log
|
mv "$striptracks_tempvideo" "${striptracks_recyclebin%/}/$(basename "$striptracks_video")" | log
|
||||||
else
|
else
|
||||||
[ $striptracks_debug -eq 1 ] && echo "Debug|Deleting: \"$striptracks_tempvideo\"" | log
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Deleting: \"$striptracks_tempvideo\"" | log
|
||||||
rm "$striptracks_tempvideo" | log
|
rm "$striptracks_tempvideo" | log
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
MSG="Error|Unable to locate or invalid remuxed file: \"$striptracks_newvideo\". Undoing rename."
|
striptracks_message="Error|Unable to locate or invalid remuxed file: \"$striptracks_newvideo\". Undoing rename."
|
||||||
echo "$MSG" | log
|
echo "$striptracks_message" | log
|
||||||
>&2 echo "$MSG"
|
>&2 echo "$striptracks_message"
|
||||||
[ $striptracks_debug -eq 1 ] && echo "Debug|Renaming: \"$striptracks_tempvideo\" to \"$striptracks_video\"" | log
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Renaming: \"$striptracks_tempvideo\" to \"$striptracks_video\"" | log
|
||||||
mv -f "$striptracks_tempvideo" "$striptracks_video" | log
|
mv -f "$striptracks_tempvideo" "$striptracks_video" | log
|
||||||
exit 10
|
exit 10
|
||||||
fi
|
fi
|
||||||
|
|
||||||
FILESIZE=$(numfmt --to iec --format "%.3f" $(stat -c %s "$striptracks_newvideo"))
|
striptracks_filesize=$(numfmt --to iec --format "%.3f" $(stat -c %s "$striptracks_newvideo"))
|
||||||
MSG="Info|New size: $FILESIZE"
|
striptracks_message="Info|New size: $striptracks_filesize"
|
||||||
echo "$MSG" | log
|
echo "$striptracks_message" | log
|
||||||
|
|
||||||
# Call Radarr/Sonarr API to RescanMovie/RescanSeries
|
#### Call Radarr/Sonarr API to RescanMovie/RescanSeries
|
||||||
if [ -f "$striptracks_arr_config" ]; then
|
# Check for URL
|
||||||
# Read *arr config.xml
|
if [ -n "$striptracks_api_url" ]; then
|
||||||
while read_xml; do
|
# Check for video IDs
|
||||||
[[ $ENTITY = "Port" ]] && striptracks_port=$CONTENT
|
if [ "$striptracks_video_id" -a "$striptracks_videofile_id" ]; then
|
||||||
[[ $ENTITY = "UrlBase" ]] && striptracks_urlbase=$CONTENT
|
# Get video file info
|
||||||
[[ $ENTITY = "BindAddress" ]] && striptracks_bindaddress=$CONTENT
|
if get_videofile_info; then
|
||||||
[[ $ENTITY = "ApiKey" ]] && striptracks_apikey=$CONTENT
|
|
||||||
done < $striptracks_arr_config
|
|
||||||
|
|
||||||
[[ $striptracks_bindaddress = "*" ]] && striptracks_bindaddress=localhost
|
|
||||||
|
|
||||||
# Check for video ID
|
|
||||||
if [ "$striptracks_video_id" ]; then
|
|
||||||
# Call API
|
|
||||||
if [ "${striptracks_type,,}" = "radarr" ] && get_video_info; then
|
|
||||||
# Save original quality
|
# Save original quality
|
||||||
ORGQUALITY=$(echo $RESULT | jq -crM ${striptracks_json_quality_root}.quality)
|
striptracks_original_quality=$(echo $striptracks_result | jq -crM .quality)
|
||||||
fi
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Detected quality '$(echo $striptracks_original_quality | jq -crM .quality.name)'." | log
|
||||||
# Loop a maximum of twice
|
# Loop a maximum of twice
|
||||||
for ((i=1; $i <= 2; i++)); do
|
# Radarr needs to Rescan twice when the file extension changes
|
||||||
# Scan the disk for the new movie file
|
# (.avi -> .mkv for example)
|
||||||
if rescan; then
|
for ((i=1; $i <= 2; i++)); do
|
||||||
# Check that the Rescan completed
|
# Scan the disk for the new movie file
|
||||||
if check_rescan; then
|
if rescan; then
|
||||||
# This whole section doesn't work under Sonarr because the episodefile_id changes after the RescanSeries if the filename changes
|
# Give it a beat
|
||||||
# Should look into just using a PUT to change everything at once instead of a Rescan.
|
sleep 1
|
||||||
if [ "${striptracks_type,,}" = "radarr" ]; then
|
# Check that the Rescan completed
|
||||||
|
if check_rescan; then
|
||||||
|
# Get new video file id
|
||||||
if get_video_info; then
|
if get_video_info; then
|
||||||
# Check that the file didn't get lost in the Rescan.
|
# Get new video file ID
|
||||||
# Radarr sometimes needs to Rescan twice when the file extension changes
|
striptracks_videofile_id=$(echo $striptracks_result | jq -crM ${striptracks_json_quality_root}.id)
|
||||||
# (.avi -> .mkv for example)
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Set new video file id '$striptracks_videofile_id'." | log
|
||||||
if [ "$(echo $RESULT | jq -crM .hasFile)" = "true" ]; then
|
# Get new video file info
|
||||||
|
if get_videofile_info; then
|
||||||
|
# Check that the file didn't get lost in the Rescan.
|
||||||
# If we lost the quality information, put it back
|
# If we lost the quality information, put it back
|
||||||
# NOTE: This "works" with Radarr in that the change shows up in the GUI, but only until the page changes.
|
if [ "$(echo $striptracks_result | jq -crM .quality.quality.name)" != "$(echo $striptracks_original_quality | jq -crM .quality.name)" ]; then
|
||||||
# It doesn't seem to write the info permanently. Maybe an API bug?
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Updating from quality '$(echo $striptracks_result | jq -crM .quality.quality.name)' to '$(echo $striptracks_original_quality | jq -crM .quality.name)'. Calling ${striptracks_type^} API using PUT and URL '$striptracks_api_url/v3/$striptracks_videofile_api/editor'" | log
|
||||||
if [ "$(echo $RESULT | jq -crM ${striptracks_json_quality_root}.quality.quality.name)" = "Unknown" ]; then
|
striptracks_result=$(curl -s -H "X-Api-Key: $striptracks_apikey" -H "Content-Type: application/json" \
|
||||||
[ $striptracks_debug -eq 1 ] && echo "Debug|Updating quality to '$(echo $ORGQUALITY | jq -crM .quality.name)'. Calling ${striptracks_type^} API using PUT and URL 'http://$striptracks_bindaddress:$striptracks_port$striptracks_urlbase/api/$striptracks_api_endpoint/$striptracks_video_id?apikey=(removed)'" | log
|
-d "{\"${striptracks_videofile_api}Ids\":[${striptracks_videofile_id}],\"quality\":$striptracks_original_quality}" \
|
||||||
RESULT=$(curl -s -d "$(echo $RESULT | jq -crM "${striptracks_json_quality_root}.quality=$ORGQUALITY")" -H "Content-Type: application/json" \
|
-X PUT "$striptracks_api_url/v3/$striptracks_videofile_api/editor")
|
||||||
-X PUT http://$striptracks_bindaddress:$striptracks_port$striptracks_urlbase/api/$striptracks_api_endpoint/$striptracks_video_id?apikey=$striptracks_apikey)
|
[ $striptracks_debug -eq 1 ] && echo "API returned: $striptracks_result" | awk '{print "Debug|"$0}' | log
|
||||||
[ $striptracks_debug -eq 1 ] && echo "API returned: $RESULT" | awk '{print "Debug|"$0}' | log
|
# Check that the returned result shows the update
|
||||||
if [ "$(echo $RESULT | jq -crM ${striptracks_json_quality_root}.quality.quality.name)" = "Unknown" ]; then
|
if [ "$(echo $striptracks_result | jq -crM .[].quality.quality.name)" = "$(echo $striptracks_original_quality | jq -crM .quality.name)" ]; then
|
||||||
MSG="Warn|Unable to update ${striptracks_type^} $striptracks_api_endpoint '$striptracks_title' to quality '$(echo $ORGQUALITY | jq -crM .quality.name)'"
|
# Updated successfully
|
||||||
echo "$MSG" | log
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Successfully updated quality to '$(echo $striptracks_result | jq -crM .[].quality.quality.name)'." | log
|
||||||
>&2 echo "$MSG"
|
break
|
||||||
|
else
|
||||||
|
striptracks_message="Warn|Unable to update ${striptracks_type^} $striptracks_video_api '$striptracks_title' to quality '$(echo $striptracks_original_quality | jq -crM .quality.name)'"
|
||||||
|
echo "$striptracks_message" | log
|
||||||
|
>&2 echo "$striptracks_message"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
# The quality is already correct
|
||||||
|
[ $striptracks_debug -eq 1 ] && echo "Debug|Quality of '$(echo $striptracks_original_quality | jq -crM .quality.name)' remained unchanged." | log
|
||||||
|
break
|
||||||
fi
|
fi
|
||||||
# The video record is [now] good
|
|
||||||
break
|
|
||||||
else
|
else
|
||||||
# Loop again because there was no file
|
# No '.path' in returned JSON
|
||||||
continue
|
striptracks_message="Warn|The '$striptracks_videofile_api' API with ${striptracks_video_api}File id $striptracks_videofile_id returned no path."
|
||||||
|
echo "$striptracks_message" | log
|
||||||
|
>&2 echo "$striptracks_message"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# No 'path' in returned JSON.
|
# 'hasFile' is False in returned JSON.
|
||||||
MSG="Warn|The '$striptracks_api' API with $striptracks_api_endpoint $striptracks_api_endpoint_id returned no path."
|
striptracks_message="Warn|The '$striptracks_video_api' API with id $striptracks_video_id returned a false hasFile (Normal with Radarr on try #1)."
|
||||||
echo "$MSG" | log
|
echo "$striptracks_message" | log
|
||||||
>&2 echo "$MSG"
|
>&2 echo "$striptracks_message"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Didn't do anything because we're in Sonarr
|
# Timeout or failure
|
||||||
break
|
striptracks_message="Warn|${striptracks_type^} job ID $striptracks_jobid timed out or failed."
|
||||||
|
echo "$striptracks_message" | log
|
||||||
|
>&2 echo "$striptracks_message"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Timeout or failure
|
# Error from API
|
||||||
MSG="Warn|${striptracks_type^} job ID $JOBID timed out or failed."
|
striptracks_message="Error|The '$striptracks_rescan_api' API with $striptracks_json_key $striptracks_video_id failed."
|
||||||
echo "$MSG" | log
|
echo "$striptracks_message" | log
|
||||||
>&2 echo "$MSG"
|
>&2 echo "$striptracks_message"
|
||||||
fi
|
fi
|
||||||
else
|
done
|
||||||
# Error from API
|
else
|
||||||
MSG="Error|The '$striptracks_api' API with $striptracks_json_key $striptracks_video_id failed."
|
# No '.path' in returned JSON
|
||||||
echo "$MSG" | log
|
striptracks_message="Warn|The '$striptracks_videofile_api' API with ${striptracks_video_api}File id $striptracks_videofile_id returned no path."
|
||||||
>&2 echo "$MSG"
|
echo "$striptracks_message" | log
|
||||||
fi
|
>&2 echo "$striptracks_message"
|
||||||
done
|
fi
|
||||||
else
|
else
|
||||||
# No video ID means we can't call the API
|
# No video ID means we can't call the API
|
||||||
MSG="Warn|Missing environment variable: $striptracks_video_idname"
|
striptracks_message="Warn|Missing or empty environment variable: striptracks_video_id='$striptracks_video_id' or striptracks_videofile_id='$striptracks_videofile_id'"
|
||||||
echo "$MSG" | log
|
echo "$striptracks_message" | log
|
||||||
>&2 echo "$MSG"
|
>&2 echo "$striptracks_message"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# No config file means we can't call the API
|
# No URL means we can't call the API
|
||||||
MSG="Warn|Unable to locate ${striptracks_type^} config file: '$striptracks_arr_config'"
|
striptracks_message="Warn|Unable to determine ${striptracks_type^} API URL."
|
||||||
echo "$MSG" | log
|
echo "$striptracks_message" | log
|
||||||
>&2 echo "$MSG"
|
>&2 echo "$striptracks_message"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Cool bash feature
|
# Cool bash feature
|
||||||
MSG="Info|Completed in $(($SECONDS/60))m $(($SECONDS%60))s"
|
striptracks_message="Info|Completed in $(($SECONDS/60))m $(($SECONDS%60))s"
|
||||||
echo "$MSG" | log
|
echo "$striptracks_message" | log
|
||||||
|
|||||||
Reference in New Issue
Block a user