Skip to content

Commit a8fa131

Browse files
authored
Merge pull request #1038 from TheCaptain989/radarr-striptracks
radarr: striptracks release 2.16.0
2 parents 3ca60bb + 949a6fc commit a8fa131

File tree

6 files changed

+66
-23
lines changed

6 files changed

+66
-23
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
READMETEMPLATE.md
99
README.md
1010
SECURITY.md
11+
bash_unit

.github/workflows/BuildImage.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
workflow_dispatch:
77
inputs:
88
mod_version:
9+
description: 'Version of the mod (optional)'
910
type: string
1011
required: false
1112

@@ -31,7 +32,7 @@ jobs:
3132
echo "MULTI_ARCH=${{ env.MULTI_ARCH }}" >> $GITHUB_OUTPUT
3233
if [[ -z "${{ env.MOD_VERSION }}" ]]; then
3334
# **** If the mod needs to be versioned, set the versioning logic below. Otherwise leave as is. ****
34-
MOD_VERSION="2.15.0"
35+
MOD_VERSION="2.16.0"
3536
else
3637
MOD_VERSION=${{ env.MOD_VERSION }}
3738
echo "MOD_VERSION_OVERRIDE=true" >> $GITHUB_OUTPUT

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ $RECYCLE.BIN/
4141
Network Trash Folder
4242
Temporary Items
4343
.apdisk
44+
45+
# Miscellaneous
46+
bash_unit

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ All language conditions with positive scores *and* Negated conditions with negat
210210
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).
211211

212212
The syntax for the command-line is:
213-
`striptracks.sh [{-a|--audio} <audio_languages> [{-s|--subs} <subtitle_languages>] [{-f|--file} <video_file>]] [--reorder] [--disable-recycle] [{-l|--log} <log_file>] [{-c|--config} <config_file>] [{-d|--debug} [<level>]]`
213+
`striptracks.sh [{-a|--audio} <audio_languages> [{-s|--subs} <subtitle_languages>] [{-f|--file} <video_file>]] [--reorder] [--disable-recycle] [{-l|--log} <log_file>] [{-c|--config} <config_file>] [{-p|--priority} {idle|low|medium|high}] [{-d|--debug} [<level>]]`
214214

215215
<details>
216216
<summary>Table of Command-Line Arguments</summary>
@@ -224,6 +224,7 @@ Option|Argument|Description
224224
`--disable-recycle`| |Disable recycle bin use, even if configured in Radarr/Sonarr
225225
`-l`, `--log`|`<log_file>`|The log filename<br/>Default is `/config/log/striptracks.txt`
226226
`-c`, `--config`|`<config_file>`|Radarr/Sonarr XML configuration file<br/>Default is `/config/config.xml`
227+
`-p`, `--priority`|`idle`, `low`, `medium`, `high`|CPU and I/O process priority for mkvmerge<br/>Default is `medium`<br/>![notes] High priority can consume all system resources. When processing a large video file your system may become unresponsive!
227228
`-d`, `--debug`|`[<level>]`|Enables debug logging. Level is optional.<br/>Default is `1` (low)<br/>`2` includes JSON output<br/>`3` contains even more JSON output
228229
`--help`| |Display help and exit.
229230
`--version`| |Display version and exit.

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.15.x | :heavy_check_mark: |
10-
| < 2.15 | :x: |
9+
| 2.16.x | :heavy_check_mark: |
10+
| < 2.16 | :x: |
1111

1212
## Reporting a Vulnerability
1313

root/usr/local/bin/striptracks.sh

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function initialize_variables {
6262
export striptracks_maxlogsize=512000
6363
export striptracks_maxlog=4
6464
export striptracks_debug=0
65+
export striptracks_nice="nice"
6566
# If this were defined directly in Radarr or Sonarr this would not be needed here
6667
# shellcheck disable=SC2089
6768
export striptracks_isocodemap='{"languages":[{"language":{"name":"Any","iso639-2":["any"]}},{"language":{"name":"Afrikaans","iso639-2":["afr"]}},{"language":{"name":"Albanian","iso639-2":["sqi","alb"]}},{"language":{"name":"Arabic","iso639-2":["ara"]}},{"language":{"name":"Bengali","iso639-2":["ben"]}},{"language":{"name":"Bosnian","iso639-2":["bos"]}},{"language":{"name":"Bulgarian","iso639-2":["bul"]}},{"language":{"name":"Catalan","iso639-2":["cat"]}},{"language":{"name":"Chinese","iso639-2":["zho","chi"]}},{"language":{"name":"Croatian","iso639-2":["hrv"]}},{"language":{"name":"Czech","iso639-2":["ces","cze"]}},{"language":{"name":"Danish","iso639-2":["dan"]}},{"language":{"name":"Dutch","iso639-2":["nld","dut"]}},{"language":{"name":"English","iso639-2":["eng"]}},{"language":{"name":"Estonian","iso639-2":["est"]}},{"language":{"name":"Finnish","iso639-2":["fin"]}},{"language":{"name":"Flemish","iso639-2":["nld","dut"]}},{"language":{"name":"French","iso639-2":["fra","fre"]}},{"language":{"name":"German","iso639-2":["deu","ger"]}},{"language":{"name":"Greek","iso639-2":["ell","gre"]}},{"language":{"name":"Hebrew","iso639-2":["heb"]}},{"language":{"name":"Hindi","iso639-2":["hin"]}},{"language":{"name":"Hungarian","iso639-2":["hun"]}},{"language":{"name":"Icelandic","iso639-2":["isl","ice"]}},{"language":{"name":"Indonesian","iso639-2":["ind"]}},{"language":{"name":"Italian","iso639-2":["ita"]}},{"language":{"name":"Japanese","iso639-2":["jpn"]}},{"language":{"name":"Kannada","iso639-2":["kan"]}},{"language":{"name":"Korean","iso639-2":["kor"]}},{"language":{"name":"Latvian","iso639-2":["lav"]}},{"language":{"name":"Lithuanian","iso639-2":["lit"]}},{"language":{"name":"Macedonian","iso639-2":["mac","mkd"]}},{"language":{"name":"Malayalam","iso639-2":["mal"]}},{"language":{"name":"Marathi","iso639-2":["mar"]}},{"language":{"name":"Mongolian","iso639-2":["mon"]}},{"language":{"name":"Norwegian","iso639-2":["nno","nob","nor"]}},{"language":{"name":"Persian","iso639-2":["fas","per"]}},{"language":{"name":"Polish","iso639-2":["pol"]}},{"language":{"name":"Portuguese","iso639-2":["por"]}},{"language":{"name":"Portuguese (Brazil)","iso639-2":["por"]}},{"language":{"name":"Romansh","iso639-2":["roh"]}},{"language":{"name":"Romanian","iso639-2":["rum","ron"]}},{"language":{"name":"Russian","iso639-2":["rus"]}},{"language":{"name":"Serbian","iso639-2":["srp"]}},{"language":{"name":"Slovak","iso639-2":["slk","slo"]}},{"language":{"name":"Slovenian","iso639-2":["slv"]}},{"language":{"name":"Spanish","iso639-2":["spa"]}},{"language":{"name":"Spanish (Latino)","iso639-2":["spa"]}},{"language":{"name":"Swedish","iso639-2":["swe"]}},{"language":{"name":"Tagalog","iso639-2":["tgl"]}},{"language":{"name":"Tamil","iso639-2":["tam"]}},{"language":{"name":"Telugu","iso639-2":["tel"]}},{"language":{"name":"Thai","iso639-2":["tha"]}},{"language":{"name":"Turkish","iso639-2":["tur"]}},{"language":{"name":"Ukrainian","iso639-2":["ukr"]}},{"language":{"name":"Urdu","iso639-2":["urd"]}},{"language":{"name":"Vietnamese","iso639-2":["vie"]}},{"language":{"name":"Unknown","iso639-2":["und"]}}]}'
@@ -116,7 +117,7 @@ mode.
116117
Source: https://github.com/TheCaptain989/radarr-striptracks
117118
118119
Usage:
119-
$0 [{-a|--audio} <audio_languages> [{-s|--subs} <subtitle_languages>] [{-f|--file} <video_file>]] [--reorder] [--disable-recycle] [{-l|--log} <log_file>] [{-c|--config} <config_file>] [{-d|--debug} [<level>]]
120+
$0 [{-a|--audio} <audio_languages> [{-s|--subs} <subtitle_languages>] [{-f|--file} <video_file>]] [--reorder] [--disable-recycle] [{-l|--log} <log_file>] [{-c|--config} <config_file>] [{-p|--priority} {idle|low|medium|high}] [{-d|--debug} [<level>]]
120121
121122
Options can also be set via the STRIPTRACKS_ARGS environment variable.
122123
Command-line arguments override the environment variable.
@@ -146,6 +147,9 @@ Options and Arguments:
146147
[default: /config/log/striptracks.txt]
147148
-c, --config <config_file> Radarr/Sonarr XML configuration file
148149
[default: ./config/config.xml]
150+
-p, --priority idle|low|medium|high
151+
CPU and I/O process priority for mkvmerge
152+
[default: medium]
149153
-d, --debug [<level>] Enable debug logging
150154
level is optional, between 1-3
151155
1 is lowest, 3 is highest
@@ -303,6 +307,25 @@ function process_command_line {
303307
exit 1
304308
fi
305309
;;
310+
-p|--priority )
311+
# Set process priority
312+
if [ -z "$2" ] || [ ${2:0:1} = "-" ]; then
313+
echo "Error|Invalid option: $1 requires an argument." >&2
314+
usage
315+
exit 20
316+
elif [[ ! "$2" =~ ^(idle|low|medium|high)$ ]]; then
317+
echo "Error|Invalid option: $1 argument must be idle, low, medium, or high." >&2
318+
usage
319+
exit 20
320+
fi
321+
case "$2" in
322+
idle) export striptracks_nice="ionice -c 3 nice -n 19" ;; # Idle priority
323+
low) export striptracks_nice="ionice -c 2 -n 7 nice -n 19" ;; # Low priority
324+
medium) export striptracks_nice="ionice -c 2 -n 4 nice -n 10" ;; # Normal priority
325+
high) export striptracks_nice="ionice -c 2 -n 0 nice -n 0" ;; # High priority
326+
esac
327+
shift 2
328+
;;
306329
--reorder )
307330
# Reorder audio and subtitles tracks
308331
export striptracks_reorder="true"
@@ -571,7 +594,7 @@ function delete_videofile {
571594
# # Adding a 'seriesId' to the Sonarr import causes the returned videos to have an 'Unknown' quality. Probably a bug.
572595
# striptracks_result=$(curl -s --fail-with-body -H "X-Api-Key: $striptracks_apikey" \
573596
# -H "Content-Type: application/json" \
574-
# -H "Accept: application/json" \
597+
# -H "Accept: application/json" \
575598
# --data-urlencode "${temp_id}" \
576599
# --data-urlencode "folder=$striptracks_video_folder" \
577600
# -d "filterExistingFiles=false" \
@@ -595,7 +618,7 @@ function set_metadata {
595618

596619
local i=0
597620
for ((i=1; i <= 5; i++)); do
598-
call_api 1 "Updating from quality '$(echo $striptracks_videofile_info | jq -crM .quality.quality.name)' to '$(echo $striptracks_original_metadata | jq -crM .quality.quality.name)' and release group '$(echo $striptracks_videofile_info | jq -crM '.releaseGroup | select(. != null)')' to '$(echo $striptracks_original_metadata | jq -crM '.releaseGroup | select(. != null)')'." "PUT" "$striptracks_videofile_api/bulk" "$(echo $striptracks_original_metadata | jq -crM "[{id:${striptracks_videofile_id}, quality, releaseGroup}]")"
621+
call_api 0 "Updating from quality '$(echo $striptracks_videofile_info | jq -crM .quality.quality.name)' to '$(echo $striptracks_original_metadata | jq -crM .quality.quality.name)' and release group '$(echo $striptracks_videofile_info | jq -crM '.releaseGroup | select(. != null)')' to '$(echo $striptracks_original_metadata | jq -crM '.releaseGroup | select(. != null)')'." "PUT" "$striptracks_videofile_api/bulk" "$(echo $striptracks_original_metadata | jq -crM "[{id:${striptracks_videofile_id}, quality, releaseGroup}]")"
599622

600623
# Exit loop if database is not locked, else wait
601624
if wait_if_locked; then
@@ -610,10 +633,12 @@ function get_mediainfo {
610633

611634
local videofile="$1"
612635

613-
local mkvcommand="nice /usr/bin/mkvmerge -J \"$videofile\""
636+
local mkvcommand="/usr/bin/mkvmerge -J \"$videofile\""
614637
[ $striptracks_debug -ge 1 ] && echo "Debug|Executing: $mkvcommand" | log
615638
unset striptracks_json
616-
export striptracks_json=$(eval $mkvcommand)
639+
# This must be a declare statement to avoid the 'Argument list too long' error with some large returned JSON
640+
declare -g striptracks_json
641+
striptracks_json=$(eval $mkvcommand)
617642
local return=$?
618643
[ $striptracks_debug -ge 1 ] && echo "Debug|mkvmerge returned ${#striptracks_json} bytes" | log
619644
[ $striptracks_debug -ge 2 ] && [ ${#striptracks_json} -ne 0 ] && echo "mkvmerge returned: $striptracks_json" | awk '{print "Debug|"$0}' | log
@@ -651,7 +676,7 @@ function get_mediainfo {
651676
function get_rename {
652677
# Get a list of video files from Radarr/Sonarr that need to be renamed
653678

654-
call_api 1 "Getting list of videos that could be renamed." "GET" "rename" "${striptracks_video_type}Id=$striptracks_rescan_id"
679+
call_api 0 "Getting list of videos that could be renamed." "GET" "rename" "${striptracks_video_type}Id=$striptracks_rescan_id"
655680
[ "$striptracks_result" != "null" ] && [ "$striptracks_result" != "" ]
656681
return
657682
}
@@ -809,8 +834,8 @@ function check_log {
809834
# Log file checks
810835

811836
# Check that log path exists
812-
if [ ! -d "$(dirname $striptracks_log)" ]; then
813-
[ $striptracks_debug -ge 1 ] && echo "Debug|Log file path does not exist: '$(dirname $striptracks_log)'. Using log file in current directory."
837+
if [ ! -d "$(dirname "$striptracks_log")" ]; then
838+
[ $striptracks_debug -ge 1 ] && echo "Debug|Log file path does not exist: '$(dirname "$striptracks_log")'. Using log file in current directory."
814839
export striptracks_log=./striptracks.txt
815840
fi
816841

@@ -981,13 +1006,19 @@ function call_api {
9811006

9821007
local url="$striptracks_api_url/$endpoint"
9831008
[ $striptracks_debug -ge 1 ] && echo "Debug|$message Calling ${striptracks_type^} API using $method and URL '$url'${data:+ with data $data}" | log
1009+
if [ "$method" = "GET" ]; then
1010+
method="-G"
1011+
else
1012+
method="-X $method"
1013+
fi
9841014
unset striptracks_result
985-
export striptracks_result=$(curl -s --fail-with-body \
1015+
declare -g striptracks_result
1016+
striptracks_result=$(curl -s --fail-with-body \
9861017
-H "X-Api-Key: $striptracks_apikey" \
9871018
-H "Content-Type: application/json" \
988-
-H "Accept: application/json" \
1019+
-H "Accept: application/json" \
9891020
${data:+ -d "$data"} \
990-
-X $method \
1021+
$method \
9911022
"$url")
9921023
local curl_return=$?; [ $curl_return -ne 0 ] && {
9931024
local message=$(echo -e "[$curl_return] curl error when calling: \"$url\"${data:+ with data $data}\nWeb server returned: $(echo $striptracks_result | jq -jcM '.message?')" | awk '{print "Error|"$0}')
@@ -1483,7 +1514,8 @@ function set_title_and_exit_if_nothing_removed {
14831514
echo "$message" | log
14841515
local mkvcommand="/usr/bin/mkvpropedit -q --edit info --set \"title=$striptracks_title\" \"$striptracks_video\""
14851516
[ $striptracks_debug -ge 1 ] && echo "Debug|Executing: $mkvcommand" | log
1486-
local result=$(eval $mkvcommand)
1517+
local result
1518+
result=$(eval $mkvcommand)
14871519
local return=$?
14881520
[ $striptracks_debug -ge 1 ] && echo "Debug|mkvpropedit returned ${#result} bytes" | log
14891521
[ $striptracks_debug -ge 2 ] && [ ${#result} -ne 0 ] && echo "mkvpropedit returned: $result" | awk '{print "Debug|"$0}' | log
@@ -1534,9 +1566,10 @@ function remux_video {
15341566
fi
15351567

15361568
# Execute MKVmerge (remux then rename, see issue #46)
1537-
local mkvcommand="nice /usr/bin/mkvmerge --title \"$striptracks_title\" -q -o \"$striptracks_tempvideo\" $audioarg $subsarg $striptracks_neworder \"$striptracks_video\""
1569+
local mkvcommand="$striptracks_nice /usr/bin/mkvmerge --title \"$striptracks_title\" -q -o \"$striptracks_tempvideo\" $audioarg $subsarg $striptracks_neworder \"$striptracks_video\""
15381570
[ $striptracks_debug -ge 1 ] && echo "Debug|Executing: $mkvcommand" | log
1539-
local result=$(eval $mkvcommand)
1571+
local result
1572+
result=$(eval $mkvcommand)
15401573
local return=$?
15411574
[ $striptracks_debug -ge 1 ] && echo "Debug|mkvmerge returned ${#result} bytes" | log
15421575
[ $striptracks_debug -ge 2 ] && [ ${#result} -ne 0 ] && echo "mkvmerge returned: $result" | awk '{print "Debug|"$0}' | log
@@ -1566,7 +1599,8 @@ function set_perms_and_owner {
15661599
if [ "$(id -u)" -eq 0 ]; then
15671600
# Set owner
15681601
[ $striptracks_debug -ge 1 ] && echo "Debug|Changing owner of file \"$striptracks_tempvideo\"" | log
1569-
local result=$(chown --reference="$striptracks_video" "$striptracks_tempvideo")
1602+
local result
1603+
result=$(chown --reference="$striptracks_video" "$striptracks_tempvideo")
15701604
local return=$?; [ $return -ne 0 ] && {
15711605
local message=$(echo -e "[$return] Error when changing owner of file: \"$striptracks_tempvideo\"\nchown returned: $result" | awk '{print "Error|"$0}')
15721606
echo "$message" | log
@@ -1578,7 +1612,8 @@ function set_perms_and_owner {
15781612
[ $striptracks_debug -ge 1 ] && echo "Debug|Unable to change owner of file when running as user '$(id -un)'" | log
15791613
fi
15801614
# Set permissions
1581-
local result=$(chmod --reference="$striptracks_video" "$striptracks_tempvideo")
1615+
local result
1616+
result=$(chmod --reference="$striptracks_video" "$striptracks_tempvideo")
15821617
local return=$?; [ $return -ne 0 ] && {
15831618
local message=$(echo -e "[$return] Error when changing permissions of file: \"$striptracks_tempvideo\"\nchmod returned: $result" | awk '{print "Error|"$0}')
15841619
echo "$message" | log
@@ -1592,7 +1627,8 @@ function replace_original_video {
15921627
# Just delete the original video if running in batch mode or if configured to do so (see issue #99)
15931628
if [ "$striptracks_type" = "batch" -o "$striptracks_recycle" = "false" ]; then
15941629
[ $striptracks_debug -ge 1 ] && echo "Debug|Deleting: \"$striptracks_video\"" | log
1595-
local result=$(rm "$striptracks_video")
1630+
local result
1631+
result=$(rm "$striptracks_video")
15961632
local return=$?; [ $return -ne 0 ] && {
15971633
local message=$(echo -e "[$return] Error when deleting video: \"$striptracks_video\"\nrm returned: $result" | awk '{print "Error|"$0}')
15981634
echo "$message" | log
@@ -1620,7 +1656,8 @@ function replace_original_video {
16201656

16211657
# Rename the temporary video file to MKV
16221658
[ $striptracks_debug -ge 1 ] && echo "Debug|Renaming \"$striptracks_tempvideo\" to \"$striptracks_newvideo\"" | log
1623-
local result=$(mv -f "$striptracks_tempvideo" "$striptracks_newvideo")
1659+
local result
1660+
result=$(mv -f "$striptracks_tempvideo" "$striptracks_newvideo")
16241661
local return=$?; [ $return -ne 0 ] && {
16251662
local message=$(echo -e "[$return] Unable to rename temp video: \"$striptracks_tempvideo\" to: \"$striptracks_newvideo\". Halting.\nmv returned: $result" | awk '{print "Error|"$0}')
16261663
echo "$message" | log
@@ -1810,7 +1847,7 @@ function rescan_and_cleanup {
18101847
}
18111848
# Check if new video is in list of files that can be renamed
18121849
if [ -n "$striptracks_result" -a "$striptracks_result" != "[]" ]; then
1813-
local renamedvideo="$(echo $striptracks_result | jq -crM ".[] | select(.${striptracks_json_quality_root}Id == $striptracks_videofile_id) | .newPath")"
1850+
local renamedvideo="$(echo "$striptracks_result" | jq -crM ".[] | select(.${striptracks_json_quality_root}Id == $striptracks_videofile_id) | .newPath")"
18141851
# Rename video if needed
18151852
if [ -n "$renamedvideo" ]; then
18161853
rename_videofile "$striptracks_videofile_id" "$renamedvideo"

0 commit comments

Comments
 (0)