dot

packages and services management
Log | Files | Refs | README

commit 8f89545ac116dcef622b38db246b60f131e96556
parent 42a5807a8965941ce05401aa1cbe3787dd112c93
Author: Josuah Demangeon <mail@josuah.net>
Date:   Fri, 23 Feb 2018 10:24:28 +0100

mv-flac: remove all unneeded /

Diffstat:
Mbin/mv-flac | 50+++++++++++++++++++++++++++++++++++---------------
1 file changed, 35 insertions(+), 15 deletions(-)

diff --git a/bin/mv-flac b/bin/mv-flac @@ -2,22 +2,42 @@ # usage: mv-flac <file> -# Rename a flac file according to its tags, extracted via the -# metaflac tool. The naming scheme is: -# "artist/year-album/[discno-]trackno-title.flac" +# Rename a file according to its tags, extracted. The naming scheme is: +# "artist/year-album/[disc_nb-]track_nb-title.flac" -al="$(metaflac --show-tag=ALBUM "$1" | sed 's/^[^=]*=//')" -ar="$(metaflac --show-tag=ARTIST "$1" | sed 's/^[^=]*=//')" -da="$(metaflac --show-tag=DATE "$1" | sed 's/^[^=]*=//')" -path="$(printf %s/%s-%s "$ar" "$da" "$al" | tr -s ' ' -)" +# Grab the year out of some string +y() { + sed 's/.*([0-9]{4}).*/\1/' +} -tr="$(metaflac --show-tag=TRACKNUMBER "$1" | sed 's/^[^=]*=//; s/\/*//')" -di="$(metaflac --show-tag=DISCNUMBER "$1" | sed 's/^[^=]*=//; s/\/*//')" -dt="$(metaflac --show-tag=DISCTOTAL "$1" | sed 's/^[^=]*=//; s/\/*//')" -ti="$(metaflac --show-tag=TITLE "$1" | sed 's/^[^=]*=//')" -name="$(printf %02d-%s.flac "$tr" "$ti" | tr -s '/ ' -)" +# Grab the value out of a key=value pair +v() { + sed 's/^[^=]*=//' +} -[ "$di" = "$dt" ] || name="$di-$name" +# Sanitize a string for use in a file name +s() { + tr -s ' \n\t$&*()[]<>\\/|";?'\' - | sed 's/^-//; s/-$//' +} -mkdir -p "$path" -ln "$1" "$path/$name" +# Grab the number 'n' out of a "n/m" format +n() { + sed 's/\/.*//' +} + +case "$1" in +(*.flac) + ar="$(metaflac --show-tag=ARTIST "$1" | v | s)" + da="$(metaflac --show-tag=DATE "$1" | y | s)" + al="$(metaflac --show-tag=ALBUM "$1" | v | s)" + dn="$(metaflac --show-tag=DISCNUMBER "$1" | v | n | s)" + dt="$(metaflac --show-tag=DISCTOTAL "$1" | v | s)" + tn="$(metaflac --show-tag=TRACKNUMBER "$1" | v | n | s)" + ti="$(metaflac --show-tag=TITLE "$1" | v | s)" + ;; +esac + +[ "$dn" = "$dt" ] && dn="" || dn="$dn-" + +mkdir -p "$ar/$al" +ln "$1" "$ar/$al/$dn$(printf %02d "${tn:-0}")-$ti.flac"