rendered paste body#!/bin/bashDEST="/storage/era/music"EVAL_DIR="Evaluation"function parse_tag() { arg=$1 for delim in " - " "-" "/"; do s_unset=false a_unset=false if [ -z "$singer" ] ; then s_unset=true singer=${arg%%${delim}*} fi if [ -z "$album" ]; then a_unset=true album=${arg#*${delim}} # alright, since this is the delimiter we probably don't want more than the # first of this element.. album=${album%%${delim}*} fi if [ "$singer" != "$arg" ]; then # try to strip [2006-blablblbal] stuff album=${album%% [*} album=${album%%[*} break # return.. fi $a_unset && unset album $s_unset && unset singer done}function usage_exit() { echo echo "Usage: $0 [-c] [-m] [-s singer] [-a album] folder" echo " -c: copy (default)" echo " -m: move" echo " -e: evaluation" echo exit 1}force=falsemove=falseevaluation=falsewhile getopts a:s:fcme arg ; do #echo "$arg" $OPTIND $OPTARG case "$arg" in s) singer="$OPTARG" ;; a) album="$OPTARG" ;; f) force=true ;; m) move=true ;; c) move=false ;; e) evaluation=true ;; \?) usage_exit ;; *) ;; esacdoneif [ $# -ne $((OPTIND)) ]; then echo -e "\nPlease specify one album" usage_exitfi$evaluation && DEST="$DEST/$EVAL_DIR"shift $((OPTIND-1))dir=$1arg=$(basename "$1")arg=${arg//_/ }arg=$1 # ... pick one... $1 or basename#echo "arg: $arg"parse_tag "$arg"singer=$(echo "$singer" | tr _ \ )album=$(echo "$album" | tr _ \ )echo -n "Artist/Singer: '$singer': "read tmp[ -n "$tmp" ] && singer=$tmpecho -n " Album: '$album': "read tmp[ -n "$tmp" ] && album=$tmpecho $move && echo -n Moving || echo -n Copying echo -n " \`$dir' to \`$DEST/$singer/$album', ok (y/N)? "read ansiif [ "$ansi" != "y" ]; then echo "Okay, bailing out as you request" exit fi[ ! -d "$DEST/$singer" ] && echo "Creating dir '$DEST/$singer'" && mkdir "$DEST/$singer"if $move; then mv "$dir" "$DEST/$singer/$album"else cp -R "$dir" "$DEST/$singer/$album"fiif [ $? -eq 0 ]; then echo Copy/move ok, updating db mpc update &>/dev/null & else echo "Copy/move failed..:"fi