add proper dry run, fix tag reading bugs, fix tracknum/total bug

This commit is contained in:
2021-02-05 21:24:59 +01:00
parent 3b88131bfa
commit 34ae15ad6f
2 changed files with 66 additions and 5 deletions

View File

@@ -1,13 +1,53 @@
#!/bin/bash
source bashcols
defcol orange 202
scr_dir=$(dirname "$0")
source "$scr_dir/music_tagmove_lib"
SPLIT='NO'
while true; do
case "$1" in
'-n'|'--dry-run')
DRY_RUN=1
shift
;;
'-s'|'--split')
SPLIT='YES'
shift
;;
'-y'|'--yes')
YES=1
shift
;;
*)
break
;;
esac
done
source_dir="$1"
dest_root="$2"
cuesplit_all
printf "======= MUSIC TAGMOVE =======\n> Source dir: %s\n> Dest root: %s\n> Split: %s\n\n" \
"$source_dir" "$dest_root" "$SPLIT"
if [[ -z $YES ]]; then
if [[ -z $DRY_RUN ]]; then
orange printf "REAL RUN - FS WILL BE MODIFIED. CONTINUE? [y/n] "
read -r user_choice
if ! [[ $user_choice =~ ^[yY] ]]; then
exit 0
fi
fi
fi
if [[ $SPLIT == YES ]]; then
cuesplit_all
fi
tagmove
cyan echo -e "\n------- EXECUTION COMPLETE -------\n"

View File

@@ -1,6 +1,11 @@
#!/bin/bash
source bashcols
defcol violet 135
set -e
set -o pipefail
if [[ -z $DIRECTORY_FORMAT ]]; then
DIRECTORY_FORMAT='$artist/$date $album'
fi
@@ -56,7 +61,7 @@ function read_tag_flac {
fi
local comment_line
comment_line=$(metaflac --list "$file" --block-type=VORBIS_COMMENT | grep -E ":\s$tag=")
comment_line=$(metaflac --list "$file" --block-type=VORBIS_COMMENT | grep -iE ":\s$tag=")
if [[ $? -ne 0 ]]; then
error "Reading tag \"$1\" from \"$file\" failed: metaflac error"
return
@@ -232,6 +237,20 @@ function mv_wrap {
echo
}
function cmd_wrap {
local cmd_prefix
if [[ -n $DRY_RUN ]]; then
cmd_prefix='noop'
else
cmd_prefix='exec'
fi
local cmd_text=$(violet printf "%s" "${@:1:1}"; printf ' "%s"' "${@:2}")
printf "%s %s\n" $(colthis grey "[$cmd_prefix]") "$cmd_text"
if [[ -z $DRY_RUN ]]; then
"$@"
fi
}
function tagmove_single {
file_name="$1"
artist=$(read_tag artist "$file_name")
@@ -260,14 +279,16 @@ function tagmove_single {
fi
# Set fixed width for track number
track=$(printf "%02d" "${track#0}")
track=$(printf "%02d" $(cut -d'/' -f1 <<<"${track#0}"))
eval "dest_directory=\"$DIRECTORY_FORMAT\""
eval "dest_file=\"$FILE_FORMAT\""
mkdir -p "$dest_root/$dest_directory"
mv_wrap "$file_name" "$dest_root/$dest_directory/$dest_file.$(get_file_extension "$file_name")"
if ! [[ -d "$dest_root/$dest_directory" ]]; then
cmd_wrap mkdir -p "$dest_root/$dest_directory"
fi
cmd_wrap mv "$file_name" "$dest_root/$dest_directory/$dest_file.$(get_file_extension "$file_name")"
}
function tagmove_get_media_type {