Added 'mp' and 'wydir'

This commit is contained in:
Jaidyn Lev 2019-01-21 13:09:15 -06:00
parent 8a258f44e0
commit d04de789d1
3 changed files with 230 additions and 0 deletions

View File

@ -21,6 +21,9 @@ You'll need:
----------------------------------------
USAGE
----------------------------------------
WYRICS
--------------------
Just run "wyrics" like so:
wyrics -s "query"
@ -49,6 +52,48 @@ Just type a number, hit enter, and the lyrics'll pop up.
If you want to save lyrics to a file, you'll need to redirect the
output-- "wyrics -s 'bob' > BOB.txt"
--------------------
... however, I've also included some more scripts that'll help make wyrics
and listening to music with lyrics more convenient:
WYDIR
--------------------
Runs "wyrics" over every song in a directory of a given file-extension.
The lyrics are output to "$song.txt"
Just run "wydir" like so:
wydir file-ext [prefix]
file-ext should be the file-extension of songs in the current dir.
prefix should be a prefix to search results to help make them
more accurate-- like, for example, the band-name, the
album, etc.
This is really convenient if you wanna get the lyrics of an album in
one go. =w=
MP
--------------------
MP is a font-end to the music-player MPV.
What MP does, is that before a song is played, it tries to "cat" it's
lyrics file (assumed to be like "song.ogg.txt"), then executes MPV.
Since it executes MPV once for every song passed, you're probably wondering
how you could seek back or forward a song.
Normally you'd use "<" or ">", but with MP, just use CTRL-C and "Q".
The escape-code of CTRL-C (4) is caught by MP, and interpreted to mean you
wanna go back a song.
The regular escape-code of "Q" (0) is caught, and interpreted to mean you
want to skip to the next song.
----------------------------------------

123
mp Executable file
View File

@ -0,0 +1,123 @@
#!/bin/sh
########################################
# name: mp
# desc: front-end to MPV that displays
# lyrics text-files before playing
# a song.
# main: Jenga Phoenix
# <jadedctrl@teknik.io>
# lisc: CC 0
########################################
trap "" 2
#---------------------------------------
# generic
# STRING --> STRING
# Return the first 'word' (space-delimiter) of a string.
function car {
local string="$1"
echo "$string" \
| awk '{ print $1 }'
}
# STRING --> STRING
# Return all words after the first word of a string.
function cdr {
local string="$1"
local car="$(car "$string")"
if test $(length "$string") -eq 1; then
echo ""
else
echo "$string" \
| sed 's/^'"$car"' //'
fi
}
# STRING --> NUMBER
# Return the length of a string.
function length {
local string="$1"
echo "$string" \
| wc -w \
| tr -d ' '
}
# NUMBER NUMBER --> NUMBER
# Add two numbers together.
function add {
operator="$1"
operatee="$2"
echo "$1 + $2" \
| bc
}
# --------------------------------------
# NIL --> NUMBER
# Return the amount of total items.
function total_items {
add "$(length "$DISCARD")" "$(length "$ITEMS")"
}
# NIL --> NUMBER
# Return the amount of discarded items.
function discarded_items {
echo "$(length "$DISCARD")"
}
# --------------------------------------
# NUMBER --> NIL
# Handle the return code of `mpv` properly, according
# to the cause.
function handle_return {
local return=$1
case $return in
4) # ^C
# rewind one file <<
ITEMS="$(car "$DISCARD") $ITEMS"
DISCARD="$(cdr "$DISCARD")"
;;
0) # normal
# put current file to discard
DISCARD="$(car "$ITEMS") $DISCARD"
ITEMS="$(cdr "$ITEMS")"
;;
2) # no file
# don't even discard it-- BURN IT
ITEMS="$(cdr "$ITEMS")"
;;
esac
}
# --------------------------------------
# invocation
DISCARD=""
ITEMS="$@"
while test -n "$ITEMS"; do
local item="$(car "$ITEMS")"
cat "${item}.txt" 2> /dev/null
echo "===$(discarded_items)/$(total_items)==="
mpv "$item"
return=$?
handle_return "$return"
done

62
wydir Executable file
View File

@ -0,0 +1,62 @@
#!/bin/sh
########################################
# name: wydir
# desc: run `wyrics` over every song in
# a directory of given file-ext
# main: Jenga Phoenix
# <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