loskutov / deadbeef-lyricbar

A simple plugin for DeaDBeeF audio player that fetches and shows the song’s lyrics
MIT License
29 stars 8 forks source link

Darklyrics support #13

Closed dakeryas closed 5 years ago

dakeryas commented 5 years ago

Hello,

Is there any plan to support darklyrics as an additional source, after lyricsmania? Some lyrics are on the former but not on the later.

Perhaps I could help if I get some guidelines. I assume one needs to add a provider in utils.cpp and methods for parsing methods for darklyrics, but I am not familiar with that kind of parsing (does one parse HTML to extract the lyrics?). I assume darklyrics would come last in the queue of providers / fetching methods.

loskutov commented 5 years ago

I suppose the preferred way of adding lyrics sources is via a custom script, accessible through plugin settings.

dakeryas commented 5 years ago

Thanks for the reply!

Are you saying would one write in the Deadbeef config a value for: lyricbar.customcmd ./myprogram %artist% %title%

where one would have written his own independent myprogram to download and parse the lyrics from e.g. DarkLyrics and put them in ~/.cache/deadbeef/lyrics/ for the lyricbar plugin to find them as cached later on?

loskutov commented 5 years ago

myprogram should output lyrics to stdout, and the plugin will cache them in ~/.cache/deadbeef/lyrics/.

dakeryas commented 5 years ago

Thanks a lot for the explanations!

If other users are interested, it might be beneficial not to have everybody write its own copy of myprogram to parse DarkLyrics or other providers.

dakeryas commented 5 years ago

I have written a basic script which works perfectly from the command-line (where the lyrics are printed to stdout). And I have added the lyricbar.customcmd with its arguments in my DeaDBeeF configuration.

However, I still get "lyrics not found" in DeaDBeeF, am I supposed to do something additional?

The printing script print_darklyrics (which works and is in PATH):

#!/usr/bin/env zsh

declare -r BROWSER_EMULATION="Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"

function main(){

    (($# != 3)) && echo "Usage: print_darklyrics [artist] [album] [title]" && exit 1

    local artist=$1
    local album=$2
    local title=$3

    local link=www.darklyrics.com/lyrics/${artist:l:gs/ /}/${album:l:gs/ /}.html
    curl -s -A $BROWSER_EMULATION $link | awk -v title=$title '/^<h3>|<div/&&lyrics{lyrics=0}
                                                                lyrics{gsub(/(<\/?\w+)?(\s+\/)?>/,"");print}
                                                                $0~title&&/^<h3>/{lyrics=1}'

}

main $@

And the ~/.config/deadbeef/config bit:

lyricbar.customcmd print_darklyrics %artist% %album% %title%
loskutov commented 5 years ago

Perhaps the issue is whitespace? Try "%artist%" "%album%" "%title%".

dakeryas commented 5 years ago

You got it spot on, it is great that it works!