#!/bin/bash DEST="/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=false move=false evaluation=false while 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 ;; *) ;; esac done if [ $# -ne $((OPTIND)) ]; then echo -e "\nPlease specify one album" usage_exit fi $evaluation && DEST="$DEST/$EVAL_DIR" shift $((OPTIND-1)) dir=$1 arg=$(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=$tmp echo -n " Album: '$album': " read tmp [ -n "$tmp" ] && album=$tmp echo $move && echo -n Moving || echo -n Copying echo -n " \`$dir' to \`$DEST/$singer/$album', ok (y/N)? " read ansi if [ "$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" fi if [ $? -eq 0 ]; then echo Copy/move ok, updating db mpc update &>/dev/null & else echo "Copy/move failed..:" fi