This repository has been archived by the owner on Nov 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
mkv-remove-language
executable file
·81 lines (68 loc) · 1.96 KB
/
mkv-remove-language
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
#
# Version 3
#
# (C) 2016 Daniel Faust <[email protected]>
#
# A BASH script that removes the audio track with the specified language from a matroska file.
#
# Requires mkvmerge
#
# Usage:
# chmod +x mkv-remove-language
# ./mkv-remove-language "My File.mkv" "eng"
#
# This will create a new file called "My File [without eng].mkv".
#
# For batch processing all .mkv files in the current directoy
# copy mkv-remove-language to a directory in your PATH and execute:
#
# find -iname "*.mkv" -exec mkv-remove-language '{}' "lang" \;
if [[ "$1" == "" ]] || [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]; then
echo
echo "Process single file:"
echo "mkv-remove-language file.mkv lang"
echo
echo "Process multiple files:"
echo "find -iname \"*.mkv\" -exec mkv-remove-language '{}' \"lang\" \;"
echo
exit
fi
hash mkvmerge 2>/dev/null || { echo >&2 "Error: Command mkvmerge not found"; exit 1; }
file_name=$1
remove_language=$2
IFS='
'
tracks=$(LANG=en_US.utf8 LANGUAGE=en_US.utf8 mkvmerge --identify-verbose "$file_name" | tail --lines=+2)
track_ids_string=""
found_languages=()
for track in $tracks; do
track_id=""
[[ "$track" =~ Track\ ID\ ([0-9]+) ]] &&
track_id=${BASH_REMATCH[1]}
[[ "$track" =~ language:([a-z]+) ]] &&
language=${BASH_REMATCH[1]}
[[ "$track" =~ Track\ ID\ [0-9]+:\ ([a-z]*) ]] &&
track_type=${BASH_REMATCH[1]}
if [[ "$track_id" == "" ]]; then
continue
fi
if [[ "$track_type" != "audio" ]]; then
continue
fi
if [[ "$language" == "$remove_language" ]]; then
track_ids_string="$track_ids_string,$track_id"
else
found_languages+=("$language")
fi
done
track_ids_string=${track_ids_string:1} # remove first comma
if [[ "$track_ids_string" != "" ]]; then
mkvmerge -o "${file_name%.*} [without $remove_language].mkv" --audio-tracks "!$track_ids_string" "$file_name"
else
echo "Can't find languge \"$remove_language\", doing nothing"
echo "Available languages are:"
for language in "${found_languages[@]}"; do
echo " $language"
done
fi