scripts/delete_track_titles.sh

34 lines
1.6 KiB
Bash
Raw Normal View History

2022-07-09 19:18:04 +00:00
#!/usr/bin/env bash
set -euo pipefail
colorprint() {
echo -e "\e[31m${1}\e[0m"
}
2022-07-09 19:18:04 +00:00
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)')
echo -n "Processing "
colorprint "$FILE"
2022-07-09 19:18:04 +00:00
for TRACK in $TRACKS; do
TRACK_DATA=$(echo "$JSON_OUTPUT" | jq "select(.id == $TRACK)")
TRACK_NAME=$(echo "$TRACK_DATA" | jq ".properties.track_name")
TRACK_TYPE=$(echo "$TRACK_DATA" | jq ".type")
TRACK_CODEC=$(echo "$TRACK_DATA" | jq ".codec")
TRACK_LANGUAGE=$(echo "$TRACK_DATA" | jq ".properties.language")
echo -en "\tTrack no. ${TRACK} (${TRACK_TYPE}, ${TRACK_CODEC}, ${TRACK_LANGUAGE})... "
[[ $TRACK_NAME == "null" ]] && echo "has no title, skipping." && continue
echo -n "currently set to $TRACK_NAME... "
2022-07-09 19:18:04 +00:00
shopt -s nocasematch
[[ $TRACK_NAME =~ full|\stitles|comment|director|sdh|sign|forced ]] && echo "includes whitelisted word, not deleting." && continue
echo -n "deleting... "
2022-07-09 19:18:04 +00:00
# mkvmerge --identify indexes tracks from 0, while mkvpropedit indexes from 1
mkvpropedit "$FILE" --edit track:"$((TRACK+1))" --delete name &>/dev/null
echo "done."
2022-07-09 19:18:04 +00:00
done
echo -en "\tDeleting file title... "
mkvpropedit "$FILE" --edit info --delete title &>/dev/null
echo "done."