dotfiles

<-- duh.
Log | Files | Refs | LICENSE

commit 8f7358cacb33a2229595c26954c65ace962d8f5e
parent f2f44b620cc01594873e1daf0e4f8c1c77416cf3
Author: hhvn <dev@hhvn.uk>
Date:   Mon, 19 Sep 2022 16:00:49 +0100

Add tag/dirformat and tag/dirformatmv scripts

Diffstat:
A.scripts/tag/dirformat | 33+++++++++++++++++++++++++++++++++
A.scripts/tag/dirformatmv | 11+++++++++++
2 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/.scripts/tag/dirformat b/.scripts/tag/dirformat @@ -0,0 +1,33 @@ +#!/bin/rc +# +# Format a directory name as an album/release +# + +if (!test -d $1) { + printf 'Not a directory: %s\n' $1 + exit 1 +} + +p = `$nl{dirname $1} +f = `$nl{find $1 -maxdepth 1 -type f -iname '*.opus' -o -iname '*.mp3' -o -iname '*.m4a' -o -iname '*.wav' -o -iname '*.flac' | head -n 1} + +if (~ $f ()) { + echo 'No audio files' +} + +fn sigexit { + rm $tmp +} + +tmp = /tmp/$pid.tags + +tag/get $f > $tmp +album = `$nl{grep -i '^album:' < $tmp | sed 's/^[^ ]*: //' | tr / _} +date = `$nl{grep -i '^date:' < $tmp | sed 's/^[^ ]*: //'} + +if (~ $album () || ~ $date ()) { + printf 'Insufficient metadata: %s\n' $f + exit 1 +} + +printf '%s/%s (%s)\n' $p $album $date diff --git a/.scripts/tag/dirformatmv b/.scripts/tag/dirformatmv @@ -0,0 +1,11 @@ +#!/bin/rc +# +# tag/dirformat, but it moves things +# + +for (old in $*) { + new = `$nl{tag/dirformat $old} + if (~ $bqstatus 0) { + mv -v $old $new + } +}