21 lines
1.1 KiB
Bash
Executable File
21 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
SCRIPT_NAME=$(basename "$0")
|
|
test -z "${1}" && echo "File not specified or doesn't exist, aborting. Usage: $SCRIPT_NAME \$FILENAME" && exit 1
|
|
FILE=$1
|
|
# TODO: use -J and jq '.tracks[] | [.properties.number, .type, .codec, .properties.track_name]'
|
|
TRACKS=$(mkvmerge --identify "$FILE" | awk -F"[: ]" '$0 ~ /Track ID/{print $3}')
|
|
# capture JSON output and remove the excessively large code_private_data field
|
|
JSON_OUTPUT=$(mkvmerge -J "$FILE" | jq '.tracks[] | del(.properties.codec_private_data)')
|
|
for TRACK in $TRACKS; do
|
|
TRACK_NAME=$(echo "$JSON_OUTPUT" | jq "select(.id == $TRACK).properties.track_name")
|
|
echo -n "Track no. ${TRACK} currently set to $TRACK_NAME... "
|
|
shopt -s nocasematch
|
|
[[ $TRACK_NAME =~ full|\stitles|comment|director|sdh|sign ]] && echo "includes whitelisted word, not deleting." && continue
|
|
echo "deleting."
|
|
# mkvmerge --identify indexes tracks from 0, while mkvpropedit indexes from 1
|
|
mkvpropedit "$FILE" --edit track:"$((TRACK+1))" --delete name
|
|
done
|
|
echo "Deleting file title..."
|
|
mkvpropedit "$FILE" --edit info --delete title
|