Switch to lyrics.ovh
This commit is contained in:
parent
79201f0975
commit
9b5e2947ed
83
README.txt
83
README.txt
|
@ -2,63 +2,33 @@
|
|||
WYRICS Git some lyrics
|
||||
===============================================================================
|
||||
|
||||
Fetch lyrics for a song from songlyrics.com with this script.
|
||||
You can fetch them by search queries, or by their URL.
|
||||
|
||||
This used to use lyrics.wikia.com, but that's defunct now. ;c
|
||||
Fetch lyrics for a song from lyrics.ovh with this script.
|
||||
|
||||
This used to use songlyrics.com-- and before that, lyrics.wikia.com.
|
||||
songlyrics.com has more flexible searching (you could make typos), but it
|
||||
is a pretty slow site.
|
||||
|
||||
lyrics.ovh is a good deal faster, but much more picky.
|
||||
|
||||
----------------------------------------
|
||||
PRE-REQUISITES
|
||||
----------------------------------------
|
||||
You'll need:
|
||||
* "gendl" in your $PATH
|
||||
* a POSIX-compatible shell (tested with `pdksh` and `bash`)
|
||||
* "curl", "wget", or "ftp" installed
|
||||
* "lynx" installed
|
||||
|
||||
|
||||
* curl
|
||||
* a shell
|
||||
|
||||
----------------------------------------
|
||||
USAGE
|
||||
----------------------------------------
|
||||
|
||||
WYRICS
|
||||
--------------------
|
||||
Just run "wyrics" like so:
|
||||
|
||||
wyrics -s "query"
|
||||
wyrics -u page_url
|
||||
|
||||
If you use the "-u" option, the lyrics will just be printed to stdout.
|
||||
|
||||
If you decide to use "-s", though, search results'll be displayed to your
|
||||
screen (via stderr)-- each numbered from 1-10.
|
||||
Just type a number, hit enter, and the lyrics'll pop up.
|
||||
|
||||
$ wyrics -s "boston"
|
||||
1 Boston
|
||||
2 Sonny:We're Better Than Boston
|
||||
3 Boston Manor:FY1
|
||||
4 Boston Manor:Halo
|
||||
5 Boston Manor:Wolf
|
||||
6 Boston Manor:Stick Up
|
||||
7 Boston Manor:If I Can't Have It No One Can
|
||||
8 Boston Manor:Square One
|
||||
9 Boston Manor:Driftwood
|
||||
10 Boston Manor:Forget Me Not
|
||||
>>
|
||||
|
||||
wyrics $ARTIST $SONG
|
||||
|
||||
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:
|
||||
output--
|
||||
$ wyrics "dream theater" "octavarium" > lyrics.txt
|
||||
|
||||
|
||||
WYDIR
|
||||
|
@ -68,39 +38,14 @@ 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.
|
||||
wydir $ARTIST $FILE_EXTENSION
|
||||
|
||||
Convenient if you wanna get the lyrics of an album in one go.
|
||||
|
||||
|
||||
----------------------------------------
|
||||
BORING STUFF
|
||||
----------------------------------------
|
||||
License is CC-0 (though, "gendl" is GPLv3)
|
||||
License is CC-0
|
||||
Author is Jaidyn Ann <jadedctrl@teknik.io>
|
||||
Sauce is at https://git.eunichx.us/wyrics.git
|
||||
Sauce is at https://git.feneas.org/detruota/wyrics.git
|
||||
|
|
27
wydir
27
wydir
|
@ -13,19 +13,19 @@
|
|||
# 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"
|
||||
local filename="$1"
|
||||
local suffix="$2"
|
||||
|
||||
basename "$filename" ".$suffix" \
|
||||
| sed 's/_/ /g'
|
||||
| sed 's/_/ /g' \
|
||||
| sed 's/ /%2a/g'
|
||||
}
|
||||
|
||||
# STRING --> STRING
|
||||
# Return the name of a file's lyrics text-file.
|
||||
# Will be the full-name + .txt
|
||||
function text_name {
|
||||
filename="$1"
|
||||
|
||||
local filename="$1"
|
||||
echo "${filename}.txt"
|
||||
}
|
||||
|
||||
|
@ -35,26 +35,25 @@ function text_name {
|
|||
# invocation
|
||||
|
||||
function usage {
|
||||
echo "usage: wydir file-ext [prefix]"
|
||||
echo "usage: wydir artist file-ext"
|
||||
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."
|
||||
|
||||
echo " 'artist' the songs' artist"
|
||||
exit 2
|
||||
}
|
||||
|
||||
# --------------------------------------
|
||||
|
||||
SUFFIX="$1"
|
||||
PREFIX="$2"
|
||||
ARTIST="$1"
|
||||
SUFFIX="$2"
|
||||
|
||||
if test -z "$SUFFIX"; then
|
||||
usage
|
||||
fi
|
||||
|
||||
for file in $(ls *.$1); do
|
||||
echo "... $file ..."
|
||||
lyrics="$(wyrics -s "$PREFIX $(query_name "$file" "$SUFFIX")")"
|
||||
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")"
|
||||
|
|
233
wyrics
233
wyrics
|
@ -1,237 +1,46 @@
|
|||
#!/bin/sh
|
||||
########################################
|
||||
# name: wyrics
|
||||
# desc: fetch lyrics by URL or query
|
||||
# from songlyrics.com
|
||||
# desc: fetch lyrics from lyrics.ovh
|
||||
# main: Jaidyn Ann
|
||||
# <jadedctrl@teknik.io>
|
||||
# lisc: CC 0
|
||||
########################################
|
||||
|
||||
# --------------------------------------
|
||||
# generic
|
||||
|
||||
# NIL --> STRING
|
||||
# read from stdin until eof hit; return all input
|
||||
# good for writing functions that take piped info
|
||||
function reade {
|
||||
local stack=""
|
||||
|
||||
while read input; do
|
||||
stack="$(printf '%s\n%s' "$stack" "$input")"
|
||||
done
|
||||
|
||||
echo "$stack"
|
||||
}
|
||||
|
||||
# NUMBER STRING --> [BOOLEAN]
|
||||
# have the user choose a number, up to a given max, with prompt.
|
||||
function number_choose {
|
||||
local max=$1
|
||||
local prompt="$2"
|
||||
|
||||
printf "$prompt" >&2
|
||||
read response
|
||||
|
||||
if test $response -lt $max; then
|
||||
return $response
|
||||
else
|
||||
number_choose $max "$prompt"
|
||||
fi
|
||||
}
|
||||
|
||||
# NUMBER NUMBER --> NUMBER
|
||||
# add two numbers together. pretty obvious.
|
||||
function add {
|
||||
local operator=$1
|
||||
local operatee=$2
|
||||
|
||||
echo "$1 + $2" \
|
||||
| bc
|
||||
}
|
||||
|
||||
# NUMBER NUMBER --> NUMBER
|
||||
# subtract two numbers. pretty obvious.
|
||||
function subtract {
|
||||
local operator=$1
|
||||
local operatee=$2
|
||||
|
||||
echo "$1 - $2" \
|
||||
| bc
|
||||
}
|
||||
|
||||
|
||||
|
||||
# --------------------------------------
|
||||
# searching
|
||||
|
||||
# STRING --> STRING
|
||||
# return a result-list from a search query
|
||||
# return lyrics for given query, if available
|
||||
function search {
|
||||
local query="$1"
|
||||
local query="$(echo "$query" | sed 's/ /+/g')"
|
||||
local artist="$(sanitize "$1")"
|
||||
local song="$(sanitize "$2")"
|
||||
|
||||
curl -Ls "https://songlyrics.com/index.php?section=search&searchW=${query}" \
|
||||
| sed '1,/serpresult/d' \
|
||||
| grep "title=" \
|
||||
| grep -v "<h3" \
|
||||
| search_parse
|
||||
curl -Ls "https://api.lyrics.ovh/v1/${artist}/${song}" \
|
||||
| sed 's%^{"lyrics":"%%' \
|
||||
| sed 's%"}$%%' \
|
||||
| sed 's%\\n\\n%\n%g' \
|
||||
| sed 's%\\n%\n%g'
|
||||
# | sed 's%\\r%%g'
|
||||
}
|
||||
|
||||
# |STRING --> STRING
|
||||
# take slightly-trimmed search HTML and turn it into result-list
|
||||
function search_parse {
|
||||
local html="$(reade)"
|
||||
# sanitize search strings
|
||||
function sanitize {
|
||||
local str="$(echo "$1" | sed 's/ /%2A/g')"
|
||||
|
||||
local stack=""
|
||||
local i=0
|
||||
IFS='
|
||||
'
|
||||
for line in $html; do
|
||||
i=$(add $i 1)
|
||||
local url="$(echo "$line" \
|
||||
| sed 's/.*href=\"//' \
|
||||
| sed 's/\".*//')"
|
||||
local title="$(echo "$line" \
|
||||
| sed 's%.*title="%%' \
|
||||
| sed 's%".*%%')"
|
||||
|
||||
if echo "$title" | grep "http" > /dev/null; then
|
||||
i=$(subtract $i 1)
|
||||
else
|
||||
stack="$(printf '%s\n%s@%s@%s' \
|
||||
"$stack" "$i" "$url" "$title")"
|
||||
if echo "$str" | grep ',the\.' >/dev/null; then
|
||||
str="the%2A${str}"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "$stack" \
|
||||
| head -11
|
||||
echo "$str"
|
||||
}
|
||||
|
||||
|
||||
|
||||
# --------------------------------------
|
||||
# result manipulation
|
||||
|
||||
# |STRING --> STRING
|
||||
# return the title of a result
|
||||
function result_title {
|
||||
local result="$(reade)"
|
||||
|
||||
echo "$result" \
|
||||
| awk -F "@" '{ print $3 }' \
|
||||
| tr -d '\n'
|
||||
}
|
||||
|
||||
# |STRING --> STRING
|
||||
# return the ID of a result
|
||||
function result_index {
|
||||
local result="$(reade)"
|
||||
|
||||
echo "$result" \
|
||||
| awk -F "@" '{ print $1 }' \
|
||||
| tr -d '\n'
|
||||
}
|
||||
|
||||
# |STRING --> STRING
|
||||
# return the URL of a result
|
||||
function result_url {
|
||||
local result="$(reade)"
|
||||
|
||||
echo "$result" \
|
||||
| awk -F "@" '{ print $2 }' \
|
||||
| tr -d '\n'
|
||||
}
|
||||
|
||||
# |STRING [STRING] --> STRING
|
||||
# display all results in a result-list to stderr.
|
||||
# if second argument is 'long', then URLs are printed, too.
|
||||
function results_display {
|
||||
local results="$(reade)"
|
||||
local long="$1"
|
||||
|
||||
IFS='
|
||||
'
|
||||
for result in $results; do
|
||||
local index="$(echo "$result" | result_index)"
|
||||
local title="$(echo "$result" | result_title)"
|
||||
local url="$(echo "$result" | result_url)"
|
||||
|
||||
echo "$index $title" >&2
|
||||
if test "$long" = "long"; then
|
||||
echo "$url" >&2
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# STRING --> STRING
|
||||
# have the user choose a single result from the result-list
|
||||
function result_choose {
|
||||
local results="$1"
|
||||
local max="$(echo "$results" | wc -l)"
|
||||
|
||||
number_choose $max ">> "
|
||||
local response=$?
|
||||
|
||||
echo "$results" \
|
||||
| grep "^$response@"
|
||||
}
|
||||
|
||||
|
||||
|
||||
# --------------------------------------
|
||||
|
||||
function blank_lines {
|
||||
local html="$(reade)"
|
||||
|
||||
echo "$html" \
|
||||
| sed 's%^<br />%<p></p>%' \
|
||||
| sed 's%^<br/>%<p></p>%'
|
||||
}
|
||||
|
||||
# STRING --> STRING
|
||||
# return the lyrics of a given URL
|
||||
function lyrics {
|
||||
local url="$1"
|
||||
|
||||
curl -Ls "$url" \
|
||||
| sed '1,/iComment-text">/d' \
|
||||
| sed '/<\/div>/,$d' \
|
||||
| blank_lines \
|
||||
| lynx -stdin -dump \
|
||||
| sed 's/^ //g'
|
||||
}
|
||||
|
||||
|
||||
|
||||
# --------------------------------------
|
||||
# invocation
|
||||
|
||||
# NIL --> STRING
|
||||
# print usage and abort
|
||||
function usage {
|
||||
echo "usage: wyrics -s query"
|
||||
echo " wyrics -u url"
|
||||
echo "usage: wyrics artist title"
|
||||
exit 2
|
||||
}
|
||||
|
||||
# --------------------------------------
|
||||
ARTIST="$1"
|
||||
SONG="$2"
|
||||
if test -z "$ARTIST" -o -z "$SONG"; then usage; fi
|
||||
|
||||
case "$1" in
|
||||
"-u")
|
||||
lyrics "$2"
|
||||
;;
|
||||
"-s")
|
||||
results="$(search "$2")"
|
||||
|
||||
echo "$results" | results_display
|
||||
url="$(result_choose "$results" | result_url)"
|
||||
|
||||
lyrics "$url"
|
||||
;;
|
||||
# # *)
|
||||
# # usage
|
||||
# # ;;
|
||||
|
||||
esac
|
||||
search "$ARTIST" "$SONG"
|
||||
|
|
Ŝarĝante…
Reference in New Issue