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 {
|
2020-12-25 22:29:09 -06:00
|
|
|
local filename="$1"
|
|
|
|
local suffix="$2"
|
2019-01-21 13:09:15 -06:00
|
|
|
|
2021-01-31 10:11:39 -06:00
|
|
|
basename "$filename" ".$suffix"
|
2019-01-21 13:09:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
# STRING --> STRING
|
|
|
|
# Return the name of a file's lyrics text-file.
|
|
|
|
# Will be the full-name + .txt
|
|
|
|
function text_name {
|
2020-12-25 22:29:09 -06:00
|
|
|
local filename="$1"
|
2019-01-21 13:09:15 -06:00
|
|
|
echo "${filename}.txt"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------
|
|
|
|
# invocation
|
|
|
|
|
|
|
|
function usage {
|
2020-12-25 22:29:09 -06:00
|
|
|
echo "usage: wydir artist file-ext"
|
2019-01-21 13:09:15 -06:00
|
|
|
echo " 'file-ext' should be the ext to songs in this dir"
|
2020-12-25 22:29:09 -06:00
|
|
|
echo " 'artist' the songs' artist"
|
2019-01-21 13:09:15 -06:00
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
|
|
|
# --------------------------------------
|
|
|
|
|
2020-12-25 22:29:09 -06:00
|
|
|
ARTIST="$1"
|
|
|
|
SUFFIX="$2"
|
2019-01-21 13:09:15 -06:00
|
|
|
|
|
|
|
if test -z "$SUFFIX"; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
2020-12-25 22:29:09 -06:00
|
|
|
for file in ./*.$SUFFIX; do
|
|
|
|
echo "... $(query_name "$file" "$SUFFIX") ..."
|
|
|
|
name="$(query_name "$file" "$SUFFIX")"
|
|
|
|
lyrics="$(wyrics "$ARTIST" "$name")"
|
2019-01-21 13:09:15 -06:00
|
|
|
|
|
|
|
if test -n "$lyrics"; then
|
|
|
|
echo "$lyrics" > "$(text_name "$file")"
|
|
|
|
fi
|
|
|
|
done
|