Skip to content

Commit 2f34128

Browse files
committed
Release 2.18.1
1 parent 013aeba commit 2f34128

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ Modifiers may be combined, such as `:any+fd` to keep all forced and all default
281281
Use the `--set-default` options to choose tracks that appear first when the video is played. Only one audio and one subtitles track may be set as default. The language code is the same colon (`:`) prepended ISO 639-2 language code used with the `--audio` and `--subs` options.
282282
The first track of the specified language will have its default flag set and all other tracks (of any language) will have their default flag disabled.
283283

284-
The language code can optionally be follow by an equals (`=`) and a string which is used to match against the track name. The first track that matches the specified language and with a name that matches the string will be set to default.
284+
The language code can optionally be followed by an equals (`=`) and a string which is used to match against the track name. The first track that matches the specified language and with a name that matches the string will be set to default.
285285
The string matching uses a substring and is case insensitive. You can use this to set the default subtitles track to hearing impared (SDH), or the audio track to your preferred language.
286286

287287
The setting of default track flags occurs after the track selection logic.

root/usr/local/bin/striptracks.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -646,14 +646,15 @@ function get_mediainfo {
646646

647647
local videofile="$1" # Video file to inspect
648648

649-
local mkvcommand="/usr/bin/mkvmerge -J \"$videofile\""
649+
local mkvcommand="/usr/bin/mkvmerge -J \"$(escape_string "$videofile")\""
650650
execute_mkv_command "$mkvcommand" "inspecting video"
651+
local return=$?
651652

652653
unset striptracks_json
653654
# This must be a declare statement to avoid the 'Argument list too long' error with some large returned JSON (see issue #104)
654655
declare -g striptracks_json
655656
striptracks_json="$striptracks_mkvresult"
656-
return
657+
return $return
657658
}
658659
# function import_video {
659660
# # Import new video into Radarr/Sonarr
@@ -1047,14 +1048,24 @@ function wait_if_locked {
10471048
fi
10481049
return $return
10491050
}
1051+
function escape_string {
1052+
# Escape special characters in string for use in mkvmerge/mkvpropedit commands
1053+
1054+
local input="$1" # Input string to escape
1055+
1056+
# Escape backslashes, double quotes, and dollar signs
1057+
# shellcheck disable=SC2001
1058+
local output="$(echo "$input" | sed -e 's/[`"\\$]/\\&/g')"
1059+
echo "$output"
1060+
}
10501061
function execute_mkv_command {
10511062
# Execute mkvmerge or mkvpropedit command
10521063

10531064
local command="$1" # Full mkvmerge or mkvpropedit command to execute
10541065
local action="$2" # Action being performed (for logging purposes)
10551066

10561067
[ $striptracks_debug -ge 1 ] && echo "Debug|Executing: $command" | log
1057-
local shortcommand="$(echo $command | sed -E 's/(nice )?([^ ]+).*$/\2/')"
1068+
local shortcommand="$(echo $command | sed -E 's/(.+ )?(\/[^ ]+) .*$/\2/')"
10581069
shortcommand=$(basename "$shortcommand")
10591070
unset striptracks_mkvresult
10601071
# This must be a declare statement to avoid the 'Argument list too long' error with some large returned JSON (see issue #104)
@@ -1620,7 +1631,7 @@ function set_default_tracks {
16201631

16211632
if [ -n "$striptracks_default_flags" ]; then
16221633
# Execute mkvpropedit to set default flags on tracks
1623-
local mkvcommand="/usr/bin/mkvpropedit -q $striptracks_default_flags \"$striptracks_video\""
1634+
local mkvcommand="/usr/bin/mkvpropedit -q $striptracks_default_flags \"$(escape_string "$striptracks_video")\""
16241635
execute_mkv_command "$mkvcommand" "setting default track flags"
16251636
fi
16261637
}
@@ -1637,7 +1648,7 @@ function set_title_and_exit_if_nothing_removed {
16371648
# Remuxing not performed
16381649
local message="Info|No tracks would be removed from video$( [ "$striptracks_reorder" = "true" ] && echo " or reordered"). Setting Title only and exiting."
16391650
echo "$message" | log
1640-
local mkvcommand="/usr/bin/mkvpropedit -q --edit info --set \"title=$striptracks_title\" \"$striptracks_video\""
1651+
local mkvcommand="/usr/bin/mkvpropedit -q --edit info --set \"title=$(escape_string "$striptracks_title")\" \"$(escape_string "$striptracks_video")\""
16411652
execute_mkv_command "$mkvcommand" "setting video title"
16421653
end_script
16431654
else
@@ -1672,7 +1683,7 @@ function remux_video {
16721683
fi
16731684

16741685
# Execute MKVmerge (remux then rename, see issue #46)
1675-
local mkvcommand="$striptracks_nice /usr/bin/mkvmerge --title \"$striptracks_title\" -q -o \"$striptracks_tempvideo\" $audioarg $subsarg $striptracks_neworder \"$striptracks_video\""
1686+
local mkvcommand="$striptracks_nice /usr/bin/mkvmerge --title \"$(escape_string "$striptracks_title")\" -q -o \"$(escape_string "$striptracks_tempvideo")\" $audioarg $subsarg $striptracks_neworder \"$(escape_string "$striptracks_video")\""
16761687
execute_mkv_command "$mkvcommand" "remuxing video"
16771688

16781689
# Check for non-empty file

0 commit comments

Comments
 (0)