Files
Server-scripts/audiobook_metadata/metadata_read_by_from_file.sh
T

88 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
DRY_RUN=false
DELETE=false
while [[ $# -gt 0 ]]; do
case "$1" in
--dry-run)
DRY_RUN=true
shift
;;
--delete)
DELETE=true
shift
;;
*)
break
;;
esac
done
if [[ $# -ne 1 ]]; then
echo "Usage: $0 [--dry-run] [--delete] file.txt"
exit 1
fi
list="$1"
while IFS= read -r file; do
book
[[ -z "$file" ]] && continue
if [[ ! -e "$file" ]]; then
echo "ERROR: Missing file: $file"
exit 1
fi
if [[ -d "$file" ]]; then
echo "WARNING: Is a directory, skipping: $file"
continue
fi
# Get comment from ID3v2
comment=$(kid3-cli "$file" \
-c "tag 2" \
-c "get comment" 2>/dev/null)
[[ -z "$comment" ]] && continue
echo
echo "File: $file"
echo "Comment: $comment"
composer=""
# Match: read by Name; text
if [[ "$comment" =~ ^[Rr]ead[[:space:]]+[Bb]y[[:space:]]+([^;]+)\; ]]; then
composer="${BASH_REMATCH[1]}"
composer="$(echo "$composer" | sed 's/[[:space:]]*$//')"
echo "Found narrator: $composer"
if $DRY_RUN; then
echo "DRY RUN: set composer '$composer', delete comment"
else
kid3-cli "$file" \
-c "tag 2" \
-c "set composer '$composer'" \
-c "set comment ''" \
-c save
fi
elif [[ ${#comment} -lt 40 ]]; then
echo "Short comment (${#comment} chars): $comment"
if $DELETE; then
if $DRY_RUN; then
echo "DRY RUN: delete comment"
else
kid3-cli "$file" \
-c "tag 2" \
-c "set comment ''" \
-c save
fi
fi
fi
done < "$list"