wyrics/wydir

63 lines
1.2 KiB
Plaintext
Raw Normal View History

2019-01-21 13:09:15 -06:00
#!/bin/sh
########################################
# name: wydir
# desc: run `wyrics` over every song in
# a directory of given file-ext
2019-12-09 11:48:22 -06:00
# main: Jaidyn Ann
2019-01-21 13:09:15 -06:00
# <jadedctrl@teknik.io>
# 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 {
filename="$1"
suffix="$2"
basename "$filename" ".$suffix" \
| sed 's/_/ /g'
}
# STRING --> STRING
# Return the name of a file's lyrics text-file.
# Will be the full-name + .txt
function text_name {
filename="$1"
echo "${filename}.txt"
}
# --------------------------------------
# invocation
function usage {
echo "usage: wydir file-ext [prefix]"
echo " 'file-ext' should be the ext to songs in this dir"
echo " 'prefix' should be a prefix (I.E., band-name) to"
echo " help make search-results more accurate."
exit 2
}
# --------------------------------------
SUFFIX="$1"
PREFIX="$2"
if test -z "$SUFFIX"; then
usage
fi
for file in $(ls *.$1); do
echo "... $file ..."
lyrics="$(wyrics -s "$PREFIX $(query_name "$file" "$SUFFIX")")"
if test -n "$lyrics"; then
echo "$lyrics" > "$(text_name "$file")"
fi
done