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
|
WYRICS Git some lyrics
|
||||||
===============================================================================
|
===============================================================================
|
||||||
|
|
||||||
Fetch lyrics for a song from songlyrics.com with this script.
|
Fetch lyrics for a song from lyrics.ovh 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
|
|
||||||
|
|
||||||
|
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
|
PRE-REQUISITES
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
You'll need:
|
You'll need:
|
||||||
* "gendl" in your $PATH
|
* curl
|
||||||
* a POSIX-compatible shell (tested with `pdksh` and `bash`)
|
* a shell
|
||||||
* "curl", "wget", or "ftp" installed
|
|
||||||
* "lynx" installed
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
USAGE
|
USAGE
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
|
|
||||||
WYRICS
|
WYRICS
|
||||||
--------------------
|
--------------------
|
||||||
Just run "wyrics" like so:
|
Just run "wyrics" like so:
|
||||||
|
|
||||||
wyrics -s "query"
|
wyrics $ARTIST $SONG
|
||||||
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
|
|
||||||
>>
|
|
||||||
|
|
||||||
|
|
||||||
If you want to save lyrics to a file, you'll need to redirect the
|
If you want to save lyrics to a file, you'll need to redirect the
|
||||||
output-- "wyrics -s 'bob' > BOB.txt"
|
output--
|
||||||
|
$ wyrics "dream theater" "octavarium" > lyrics.txt
|
||||||
--------------------
|
|
||||||
|
|
||||||
|
|
||||||
... however, I've also included some more scripts that'll help make wyrics
|
|
||||||
and listening to music with lyrics more convenient:
|
|
||||||
|
|
||||||
|
|
||||||
WYDIR
|
WYDIR
|
||||||
|
@ -68,39 +38,14 @@ The lyrics are output to "$song.txt"
|
||||||
|
|
||||||
Just run "wydir" like so:
|
Just run "wydir" like so:
|
||||||
|
|
||||||
wydir file-ext [prefix]
|
wydir $ARTIST $FILE_EXTENSION
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
|
Convenient if you wanna get the lyrics of an album in one go.
|
||||||
|
|
||||||
|
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
BORING STUFF
|
BORING STUFF
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
License is CC-0 (though, "gendl" is GPLv3)
|
License is CC-0
|
||||||
Author is Jaidyn Ann <jadedctrl@teknik.io>
|
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
|
# Return a version of a filename suitable for making a
|
||||||
# query. Replace "_" with spaces, get rid of file-ext.
|
# query. Replace "_" with spaces, get rid of file-ext.
|
||||||
function query_name {
|
function query_name {
|
||||||
filename="$1"
|
local filename="$1"
|
||||||
suffix="$2"
|
local suffix="$2"
|
||||||
|
|
||||||
basename "$filename" ".$suffix" \
|
basename "$filename" ".$suffix" \
|
||||||
| sed 's/_/ /g'
|
| sed 's/_/ /g' \
|
||||||
|
| sed 's/ /%2a/g'
|
||||||
}
|
}
|
||||||
|
|
||||||
# STRING --> STRING
|
# STRING --> STRING
|
||||||
# Return the name of a file's lyrics text-file.
|
# Return the name of a file's lyrics text-file.
|
||||||
# Will be the full-name + .txt
|
# Will be the full-name + .txt
|
||||||
function text_name {
|
function text_name {
|
||||||
filename="$1"
|
local filename="$1"
|
||||||
|
|
||||||
echo "${filename}.txt"
|
echo "${filename}.txt"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,26 +35,25 @@ function text_name {
|
||||||
# invocation
|
# invocation
|
||||||
|
|
||||||
function usage {
|
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 " 'file-ext' should be the ext to songs in this dir"
|
||||||
echo " 'prefix' should be a prefix (I.E., band-name) to"
|
echo " 'artist' the songs' artist"
|
||||||
echo " help make search-results more accurate."
|
|
||||||
|
|
||||||
exit 2
|
exit 2
|
||||||
}
|
}
|
||||||
|
|
||||||
# --------------------------------------
|
# --------------------------------------
|
||||||
|
|
||||||
SUFFIX="$1"
|
ARTIST="$1"
|
||||||
PREFIX="$2"
|
SUFFIX="$2"
|
||||||
|
|
||||||
if test -z "$SUFFIX"; then
|
if test -z "$SUFFIX"; then
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for file in $(ls *.$1); do
|
for file in ./*.$SUFFIX; do
|
||||||
echo "... $file ..."
|
echo "... $(query_name "$file" "$SUFFIX") ..."
|
||||||
lyrics="$(wyrics -s "$PREFIX $(query_name "$file" "$SUFFIX")")"
|
name="$(query_name "$file" "$SUFFIX")"
|
||||||
|
lyrics="$(wyrics "$ARTIST" "$name")"
|
||||||
|
|
||||||
if test -n "$lyrics"; then
|
if test -n "$lyrics"; then
|
||||||
echo "$lyrics" > "$(text_name "$file")"
|
echo "$lyrics" > "$(text_name "$file")"
|
||||||
|
|
233
wyrics
233
wyrics
|
@ -1,237 +1,46 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
########################################
|
########################################
|
||||||
# name: wyrics
|
# name: wyrics
|
||||||
# desc: fetch lyrics by URL or query
|
# desc: fetch lyrics from lyrics.ovh
|
||||||
# from songlyrics.com
|
|
||||||
# main: Jaidyn Ann
|
# main: Jaidyn Ann
|
||||||
# <jadedctrl@teknik.io>
|
# <jadedctrl@teknik.io>
|
||||||
# lisc: CC 0
|
# lisc: CC 0
|
||||||
########################################
|
########################################
|
||||||
|
|
||||||
# --------------------------------------
|
# return lyrics for given query, if available
|
||||||
# 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
|
|
||||||
function search {
|
function search {
|
||||||
local query="$1"
|
local artist="$(sanitize "$1")"
|
||||||
local query="$(echo "$query" | sed 's/ /+/g')"
|
local song="$(sanitize "$2")"
|
||||||
|
|
||||||
curl -Ls "https://songlyrics.com/index.php?section=search&searchW=${query}" \
|
curl -Ls "https://api.lyrics.ovh/v1/${artist}/${song}" \
|
||||||
| sed '1,/serpresult/d' \
|
| sed 's%^{"lyrics":"%%' \
|
||||||
| grep "title=" \
|
| sed 's%"}$%%' \
|
||||||
| grep -v "<h3" \
|
| sed 's%\\n\\n%\n%g' \
|
||||||
| search_parse
|
| sed 's%\\n%\n%g'
|
||||||
|
# | sed 's%\\r%%g'
|
||||||
}
|
}
|
||||||
|
|
||||||
# |STRING --> STRING
|
# sanitize search strings
|
||||||
# take slightly-trimmed search HTML and turn it into result-list
|
function sanitize {
|
||||||
function search_parse {
|
local str="$(echo "$1" | sed 's/ /%2A/g')"
|
||||||
local html="$(reade)"
|
|
||||||
|
|
||||||
local stack=""
|
if echo "$str" | grep ',the\.' >/dev/null; then
|
||||||
local i=0
|
str="the%2A${str}"
|
||||||
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")"
|
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
|
||||||
echo "$stack" \
|
echo "$str"
|
||||||
| head -11
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------
|
|
||||||
# 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
|
# print usage and abort
|
||||||
function usage {
|
function usage {
|
||||||
echo "usage: wyrics -s query"
|
echo "usage: wyrics artist title"
|
||||||
echo " wyrics -u url"
|
|
||||||
exit 2
|
exit 2
|
||||||
}
|
}
|
||||||
|
|
||||||
# --------------------------------------
|
ARTIST="$1"
|
||||||
|
SONG="$2"
|
||||||
|
if test -z "$ARTIST" -o -z "$SONG"; then usage; fi
|
||||||
|
|
||||||
case "$1" in
|
search "$ARTIST" "$SONG"
|
||||||
"-u")
|
|
||||||
lyrics "$2"
|
|
||||||
;;
|
|
||||||
"-s")
|
|
||||||
results="$(search "$2")"
|
|
||||||
|
|
||||||
echo "$results" | results_display
|
|
||||||
url="$(result_choose "$results" | result_url)"
|
|
||||||
|
|
||||||
lyrics "$url"
|
|
||||||
;;
|
|
||||||
# # *)
|
|
||||||
# # usage
|
|
||||||
# # ;;
|
|
||||||
|
|
||||||
esac
|
|
||||||
|
|
Ŝarĝante…
Reference in New Issue