Skip to content

Commit c981623

Browse files
authored
Merge pull request #1099 from TheCaptain989/radarr-striptracks
radarr: striptracks release 2.19.0
2 parents da582cc + 47976f0 commit c981623

File tree

4 files changed

+78
-31
lines changed

4 files changed

+78
-31
lines changed

.github/workflows/BuildImage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
echo "MULTI_ARCH=${{ env.MULTI_ARCH }}" >> $GITHUB_OUTPUT
3333
if [[ -z "${{ env.MOD_VERSION }}" ]]; then
3434
# **** If the mod needs to be versioned, set the versioning logic below. Otherwise leave as is. ****
35-
MOD_VERSION="2.18.0"
35+
MOD_VERSION="2.19.0"
3636
else
3737
MOD_VERSION=${{ env.MOD_VERSION }}
3838
echo "MOD_VERSION_OVERRIDE=true" >> $GITHUB_OUTPUT

README.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ All language conditions with positive scores *and* Negated conditions with negat
213213
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).
214214

215215
The syntax for the command-line is:
216-
`striptracks.sh [{-a|--audio} <audio_languages[+modifier]> [{-s|--subs} <subtitle_languages[+modifier]>] [{-f|--file} <video_file>]] [--reorder] [--disable-recycle] [--skip-profile <profile_name>]... [--set-default-audio <language_code[=name]>] [--set-default-subs <language_code[=name]>]
216+
`striptracks.sh [{-a|--audio} <audio_languages[+modifier]> [{-s|--subs} <subtitle_languages[+modifier]>] [{-f|--file} <video_file>]] [--reorder] [--disable-recycle] [--skip-profile <profile_name>]... [--set-default-audio <language_code[=name][-f]>] [--set-default-subs <language_code[=name][-f]>]
217217
[{-l|--log} <log_file>] [{-c|--config} <config_file>] [{-p|--priority} {idle|low|medium|high}] [{-d|--debug} [<level>]]`
218218

219219
<details>
@@ -224,17 +224,17 @@ Option|Argument|Description
224224
`-a`, `--audio`|`<audio_languages[+modifier]>`|Audio languages to keep<br/>ISO 639-2 code(s) prefixed with a colon (`:`)<br/>Each code may optionally be followed by a plus (`+`) and one or more [modifiers](#language-code-modifiers).
225225
`-s`, `--subs`|`<subtitle_languages[+modifier]>`|Subtitle languages to keep<br/>ISO 639-2 code(s) prefixed with a colon (`:`)<br/>Each code may optionally be followed by a plus (`+`) and one or more modifiers.
226226
`-f`, `--file`|`<video_file>`|If included, the script enters **[Batch Mode](#batch-mode)** and converts the specified video file.<br/>Requires the `--audio` option.<br/>![notes] **Do not** use this argument when called from Radarr or Sonarr!
227-
`--reorder`| |Reorder audio and subtitles tracks to match the language code order specified in the `<audio_languages>` and `<subtitle_languages>` arguments.
228-
`--disable-recycle`| |Disable recycle bin use, even if configured in Radarr/Sonarr
227+
`--reorder`||Reorder audio and subtitles tracks to match the language code order specified in the `<audio_languages>` and `<subtitle_languages>` arguments.
228+
`--disable-recycle`||Disable recycle bin use, even if configured in Radarr/Sonarr
229229
`--skip-profile`|`<profile_name>`|Skip processing if the video was downloaded using the specified Quality Profile name. May be specified multiple times to skip multiple profiles.
230-
`--set-default-audio`|`<language_code[=name]>`|Set the default audio track to the first track of the specified language. Only one language code is allowed. If specified, all other tracks are marked as not default.<br/>The code may optionally be followed by an equals (`=`) and a [track name](#setting-default-track) matching string.
231-
`--set-default-subs`|`<language_code[=name]>`|Set the default subtitles track to the first track of the specified language. Only one language code is allowed. If specified, all other tracks are marked as not default.<br/>The code may optionally be followed by an equals (`=`) and a track name string.
230+
`--set-default-audio`|`<language_code[=name][-f]>`|Set the default audio track to the first track of the specified language. Only one language code is allowed. If specified, all other tracks are marked as not default.<br/>The code may optionally be followed by an equals (`=`) and a [track name](#setting-default-track) matching string.<br/>The code may optionally be followed by a minus f (`-f`) to indicate skipping Forced tracks.
231+
`--set-default-subs`|`<language_code[=name][-f]>`|Set the default subtitles track to the first track of the specified language. Only one language code is allowed. If specified, all other tracks are marked as not default.<br/>The code may optionally be followed by an equals (`=`) and a track name string.<br/>The code may optionally be followed by a minus f (`-f`) to indicate skipping Forced tracks.
232232
`-l`, `--log`|`<log_file>`|The log filename<br/>Default is `/config/log/striptracks.txt`
233233
`-c`, `--config`|`<config_file>`|Radarr/Sonarr XML configuration file<br/>Default is `/config/config.xml`
234234
`-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!
235235
`-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
236-
`--help`| |Display help and exit.
237-
`--version`| |Display version and exit.
236+
`--help`||Display help and exit.
237+
`--version`||Display version and exit.
238238

239239
</details>
240240

@@ -281,8 +281,12 @@ 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.
285-
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.
284+
The language code can optionally be followed by an equals (`=`) and a string which is matched 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.
285+
The string matching uses a substring and is case insensitive. You could use this to set the default subtitles track to hearing impared (SDH), for example.
286+
287+
The language code can optionally be followed by a minus f (`-f`) which indicates skipping tracks that have the forced flag set when choosing the default track.
288+
289+
The order of the `=name` and `-f` modifiers is not important.
286290

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

@@ -291,14 +295,17 @@ The setting of default track flags occurs after the track selection logic.
291295
> You may therefore not obtain consistent results.
292296

293297
<details>
294-
<summary>Track Name Examples</summary>
298+
<summary>Default Track Examples</summary>
295299

296300
If you want to set the default subtitles track to the first hearing impared English track, you would use:
297301
`--set-default-subs :eng=SDH`
298302

299303
To set the default audio track to Dutch:
300304
`--set-default-audio :dut`
301305

306+
To set the default subtitles track to the first non-forced English track:
307+
`--set-default-subs :eng-f`
308+
302309
</details>
303310

304311
### Any language code
@@ -379,6 +386,12 @@ There is no way to force the script to remove audio tracks with these codes.
379386
# (first audio track flagged as Default as it appears in the source file),
380387
# one English subtitles track and two forced subtitles regardless of
381388
# language (as they appear in the source file)
389+
--audio :org:eng:fre:fra --subs :org:eng:fre:fra --reorder --disable-recycle --set-default-audio :org --set-default-subs :eng-f
390+
# Keep the Original, English, and French audio and subtitles
391+
# Reorder the tracks to match the above order (audio first, then substitles)
392+
# Set the first Original language audio track as default
393+
# Set the first non-forced English subtitles tracks as default
394+
# Force delete the original video after remuxing
382395
```
383396

384397
</details>

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.18.x | :heavy_check_mark: |
10-
| < 2.18 | :x: |
9+
| 2.19.x | :heavy_check_mark: |
10+
| < 2.19 | :x: |
1111

1212
## Reporting a Vulnerability
1313

root/usr/local/bin/striptracks.sh

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ mode.
122122
Source: https://github.com/TheCaptain989/radarr-striptracks
123123
124124
Usage:
125-
$0 [{-a|--audio} <audio_languages> [{-s|--subs} <subtitle_languages>] [{-f|--file} <video_file>]] [--reorder] [--disable-recycle] [--skip-profile <profile_name>]... [--set-default-audio <language_code[=name]>] [--set-default-subs <language_code[=name]>] [{-l|--log} <log_file>] [{-c|--config} <config_file>] [{-p|--priority} {idle|low|medium|high}] [{-d|--debug} [<level>]]
125+
$0 [{-a|--audio} <audio_languages> [{-s|--subs} <subtitle_languages>] [{-f|--file} <video_file>]] [--reorder] [--disable-recycle] [--skip-profile <profile_name>]... [--set-default-audio <language_code[=name][-f]>] [--set-default-subs <language_code[=name][-f]>] [{-l|--log} <log_file>] [{-c|--config} <config_file>] [{-p|--priority} {idle|low|medium|high}] [{-d|--debug} [<level>]]
126126
127127
Options can also be set via the STRIPTRACKS_ARGS environment variable.
128128
Command-line arguments override the environment variable.
@@ -155,16 +155,22 @@ Options and Arguments:
155155
using the specified quality profile name.
156156
May be specified multiple times to skip
157157
multiple profiles.
158-
--set-default-audio <language_code[=name]>
158+
--set-default-audio <language_code[=name][-f]>
159159
Set the default audio track to the first
160160
track of the specified language.
161161
The code may optionally be followed by an
162162
equals \`=\` and a track name.
163-
--set-default-subs <language_code[=name]>
163+
The code may optionally be followed by a
164+
minus \`-f\` to indicate skipping Forced
165+
tracks.
166+
--set-default-subs <language_code[=name][-f]>
164167
Set the default subtitles track to the first
165168
track of the specified language.
166169
The code may optionally be followed by an
167-
equals \`+\` and a track name.
170+
equals \`=\` and a track name.
171+
The code may optionally be followed by a
172+
minus \`-f\` to indicate skipping Forced
173+
tracks.
168174
-l, --log <log_file> Log filename
169175
[default: /config/log/striptracks.txt]
170176
-c, --config <config_file> Radarr/Sonarr XML configuration file
@@ -646,14 +652,15 @@ function get_mediainfo {
646652

647653
local videofile="$1" # Video file to inspect
648654

649-
local mkvcommand="/usr/bin/mkvmerge -J \"$videofile\""
655+
local mkvcommand="/usr/bin/mkvmerge -J \"$(escape_string "$videofile")\""
650656
execute_mkv_command "$mkvcommand" "inspecting video"
657+
local return=$?
651658

652659
unset striptracks_json
653660
# This must be a declare statement to avoid the 'Argument list too long' error with some large returned JSON (see issue #104)
654661
declare -g striptracks_json
655662
striptracks_json="$striptracks_mkvresult"
656-
return
663+
return $return
657664
}
658665
# function import_video {
659666
# # Import new video into Radarr/Sonarr
@@ -1047,14 +1054,24 @@ function wait_if_locked {
10471054
fi
10481055
return $return
10491056
}
1057+
function escape_string {
1058+
# Escape special characters in string for use in mkvmerge/mkvpropedit commands
1059+
1060+
local input="$1" # Input string to escape
1061+
1062+
# Escape backslashes, double quotes, and dollar signs
1063+
# shellcheck disable=SC2001
1064+
local output="$(echo "$input" | sed -e 's/[`"\\$]/\\&/g')"
1065+
echo "$output"
1066+
}
10501067
function execute_mkv_command {
10511068
# Execute mkvmerge or mkvpropedit command
10521069

10531070
local command="$1" # Full mkvmerge or mkvpropedit command to execute
10541071
local action="$2" # Action being performed (for logging purposes)
10551072

10561073
[ $striptracks_debug -ge 1 ] && echo "Debug|Executing: $command" | log
1057-
local shortcommand="$(echo $command | sed -E 's/(nice )?([^ ]+).*$/\2/')"
1074+
local shortcommand="$(echo $command | sed -E 's/(.+ )?(\/[^ ]+) .*$/\2/')"
10581075
shortcommand=$(basename "$shortcommand")
10591076
unset striptracks_mkvresult
10601077
# This must be a declare statement to avoid the 'Argument list too long' error with some large returned JSON (see issue #104)
@@ -1571,7 +1588,7 @@ function determine_track_order {
15711588
fi
15721589
}
15731590
function set_default_tracks {
1574-
# Build mkvpropedit paramaters to set default flags on audio and subtitle tracks.
1591+
# Build mkvpropedit parameters to set default flags on audio and subtitle tracks.
15751592

15761593
# Process audio and subtitle --set-default track settings
15771594
for tracktype in audio subtitles; do
@@ -1586,15 +1603,32 @@ function set_default_tracks {
15861603
# Use jq to find the track ID using case-insensitive substring match on track name
15871604
local track_id=$(echo "$striptracks_json_processed" | jq -crM --arg type "$tracktype" --arg currentcfg "$currentcfg" '
15881605
def parse_cfg(cfg):
1589-
cfg | ltrimstr(":") | split("=") | {lang: .[0], name: .[1]};
1590-
1591-
(parse_cfg($currentcfg)).lang as $lang |
1592-
(parse_cfg($currentcfg)).name as $name |
1606+
# Remove leading ":" then split on "=" (if present)
1607+
# Supports f as a modifier (see issue #113)
1608+
(cfg | ltrimstr(":") | split("=")) as $eq |
1609+
($eq[0]) as $left |
1610+
(if ($eq | length > 1) then $eq[1] else "" end) as $right |
1611+
1612+
# Detect trailing "-f" on left or right and strip it; only "f" is a valid modifier
1613+
(if ($left | test("-f$")) then {lang: ($left | sub("-f$"; "")), skip: true} else {lang: $left, skip: false} end) as $leftinfo |
1614+
1615+
(if $right == "" then
1616+
$leftinfo + {name: ""}
1617+
else
1618+
(if ($right | test("-f$")) then
1619+
$leftinfo + {name: ($right | sub("-f$"; "")), skip: true}
1620+
else
1621+
$leftinfo + {name: $right}
1622+
end)
1623+
end);
1624+
1625+
parse_cfg($currentcfg) as $rule |
15931626
.tracks |
15941627
map(. as $track |
1595-
(($lang == "any" or $lang == $track.language) as $lang_match |
1596-
($name == "" or (($track.name // "") | ascii_downcase | contains(($name // "") | ascii_downcase))) as $name_match |
1597-
select($track.type == $type and $lang_match and $name_match and .striptracks_keep)
1628+
(($rule.lang == "any" or $rule.lang == $track.language) as $lang_match |
1629+
($rule.name == "" or (($track.name // "") | ascii_downcase | contains(($rule.name // "") | ascii_downcase))) as $name_match |
1630+
($rule.skip and $track.forced) as $skipped |
1631+
select($track.type == $type and $lang_match and $name_match and ($skipped | not) and .striptracks_keep)
15981632
)
15991633
) |
16001634
.[0].id // ""
@@ -1620,7 +1654,7 @@ function set_default_tracks {
16201654

16211655
if [ -n "$striptracks_default_flags" ]; then
16221656
# Execute mkvpropedit to set default flags on tracks
1623-
local mkvcommand="/usr/bin/mkvpropedit -q $striptracks_default_flags \"$striptracks_video\""
1657+
local mkvcommand="/usr/bin/mkvpropedit -q $striptracks_default_flags \"$(escape_string "$striptracks_video")\""
16241658
execute_mkv_command "$mkvcommand" "setting default track flags"
16251659
fi
16261660
}
@@ -1637,7 +1671,7 @@ function set_title_and_exit_if_nothing_removed {
16371671
# Remuxing not performed
16381672
local message="Info|No tracks would be removed from video$( [ "$striptracks_reorder" = "true" ] && echo " or reordered"). Setting Title only and exiting."
16391673
echo "$message" | log
1640-
local mkvcommand="/usr/bin/mkvpropedit -q --edit info --set \"title=$striptracks_title\" \"$striptracks_video\""
1674+
local mkvcommand="/usr/bin/mkvpropedit -q --edit info --set \"title=$(escape_string "$striptracks_title")\" \"$(escape_string "$striptracks_video")\""
16411675
execute_mkv_command "$mkvcommand" "setting video title"
16421676
end_script
16431677
else
@@ -1672,7 +1706,7 @@ function remux_video {
16721706
fi
16731707

16741708
# 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\""
1709+
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")\""
16761710
execute_mkv_command "$mkvcommand" "remuxing video"
16771711

16781712
# Check for non-empty file

0 commit comments

Comments
 (0)