92 lines
2.7 KiB
Bash
Executable File
92 lines
2.7 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# metaflac-field2field.sh, Copyright © 2009 Matteo Cypriani
|
|
#
|
|
# This program is free software. It comes without any warranty, to
|
|
# the extent permitted by applicable law. You can redistribute it
|
|
# and/or modify it under the terms of the Do What The Fuck You Want
|
|
# To Public License, Version 2, as published by Sam Hocevar. See
|
|
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
|
#
|
|
# This script uses metaflac to process field to field copy/rename on
|
|
# FLAC file metadatas.
|
|
# Launch this script without arguments to display usage.
|
|
# ----
|
|
# Ce script utilise metaflac pour effectuer des actions de copie ou
|
|
# renommage de champ à champ sur les fichiers FLAC.
|
|
# Lancer ce script sans argument pour afficher son utilisation.
|
|
|
|
#set -x
|
|
|
|
USAGE=$(cat <<EOF
|
|
Usage:
|
|
$0 <ACTION> <SRC_FIELD> <DST_FIELD> <FILE.flac> [ <FILE2.flac> [...] ]
|
|
|
|
<ACTION> : copy | move | rmcopy | mvcopy
|
|
copy: each occurrence of SRC_FIELD is duplicated to create an occurrence of
|
|
DST_FIELD; all the existing occurrences of SRC_FIELD and DST_FIELD are
|
|
kept.
|
|
move: each occurrence of SRC_FIELD is renamed to create an occurrence of
|
|
DST_FIELD; the existing occurrences of DST_FIELD are kept.
|
|
rmcopy: the existing occurrences of DST_FIELD are deleted, then each
|
|
occurrence of SRC_FIELD is duplicated to create an occurrence
|
|
of DST_FIELD; the occurrences of SRC_FIELD are kept.
|
|
rmmove: the existing occurrences of DST_FIELD are deleted, then each
|
|
occurrence of SRC_FIELD is renamed to create an occurrence of
|
|
DST_FIELD.
|
|
EOF
|
|
)
|
|
|
|
# Right number of arguments?
|
|
if [ $# -lt 4 ] ; then
|
|
echo "Wrong number of arguments!" >&2
|
|
print_usage
|
|
fi
|
|
|
|
ACTION="$1"
|
|
shift
|
|
|
|
# Known action type?
|
|
case "$ACTION" in
|
|
copy) ;;
|
|
move) ;;
|
|
rmcopy) ;;
|
|
rmmove) ;;
|
|
*)
|
|
printf 'Action unknown "%s"!\n\n' "$ACTION" >&2
|
|
printf '%s\n' "$USAGE" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
SRC_FIELD=$1
|
|
shift
|
|
DST_FIELD=$1
|
|
shift
|
|
|
|
printf 'Source field: %s\n' "$SRC_FIELD"
|
|
printf 'Destination field: %s\n' "$DST_FIELD"
|
|
printf 'Action: %s\n' "$ACTION"
|
|
|
|
echo "Processing files..."
|
|
|
|
if echo "$ACTION" | grep '^rm' >/dev/null ; then
|
|
printf 'Deleting field "%s" on each file...\n' "$DST_FIELD"
|
|
metaflac --remove-tag="$DST_FIELD" "$@"
|
|
fi
|
|
|
|
for file in "$@" ; do
|
|
printf 'Setting field "%s" on file: "%s"\n' "$DST_FIELD" "$file"
|
|
metaflac --show-tag="$SRC_FIELD" "$file" | sed 's/^[A-Z]\+=//' | while read -r c1 ; do
|
|
printf 'Adding "%s"...\n' "$DST_FIELD=$c1"
|
|
metaflac --set-tag="$DST_FIELD"="$c1" "$file"
|
|
done
|
|
done
|
|
|
|
if echo "$ACTION" | grep 'move$' >/dev/null ; then
|
|
printf 'Deleting "%s" on each file...\n' "$SRC_FIELD"
|
|
metaflac --remove-tag="$SRC_FIELD" "$@"
|
|
fi
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|