wyrics/wydir

60 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
########################################
# name: wydir
# desc: run `wyrics` over every song in
# a directory of given file-ext
# main: Jaidyn Ann
# <jadedctrl@posteo.at>
# lisc: CC 0
########################################
# STRING STRING --> STRING
# Return a version of a filename suitable for making a
# query. Replace "_" with spaces, get rid of file-ext.
function query_name {
local filename="$1"
local suffix="$2"
basename "$filename" ".$suffix"
}
# STRING --> STRING
# Return the name of a file's lyrics text-file.
# Will be the full-name + .txt
function text_name {
local filename="$1"
echo "${filename}.txt"
}
# --------------------------------------
# invocation
function usage {
echo "usage: wydir artist file-ext"
echo " 'file-ext' should be the ext to songs in this dir"
echo " 'artist' the songs' artist"
exit 2
}
# --------------------------------------
ARTIST="$1"
SUFFIX="$2"
if test -z "$SUFFIX"; then
usage
fi
for file in ./*.$SUFFIX; do
echo "... $(query_name "$file" "$SUFFIX") ..."
name="$(query_name "$file" "$SUFFIX")"
lyrics="$(wyrics "$ARTIST" "$name")"
if test -n "$lyrics"; then
echo "$lyrics" > "$(text_name "$file")"
fi
done