Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/config
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@
#
#cyclic_scrolling = no
#
#lyrics_fetchers = tags, tekstowo, plyrics, justsomelyrics, jahlyrics, zeneszoveg, internet
#lyrics_fetchers = tags, tekstowo, plyrics, justsomelyrics, jahlyrics, zeneszoveg, azlyrics, darklyrics, internet
#
#follow_now_playing_lyrics = no
#
Expand Down
4 changes: 4 additions & 0 deletions src/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ bool configure(int argc, char **argv)
std::make_tuple("plyrics", "rihanna", "umbrella"),
std::make_tuple("tekstowo", "rihanna", "umbrella"),
std::make_tuple("zeneszoveg", "rihanna", "umbrella"),
std::make_tuple("azlyrics", "rihanna", "umbrella"),
std::make_tuple("darklyrics", "agalloch", "falling snow"),


};
for (auto &data : fetcher_data)
{
Expand Down
40 changes: 40 additions & 0 deletions src/lyrics_fetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ std::istream &operator>>(std::istream &is, LyricsFetcher_ &fetcher)
fetcher = std::make_unique<TekstowoFetcher>();
else if (s == "zeneszoveg")
fetcher = std::make_unique<ZeneszovegFetcher>();
else if (s == "azlyrics")
fetcher = std::make_unique<AzLyricsFetcher>();
else if (s == "darklyrics")
fetcher = std::make_unique<DarkLyricsFetcher>();
else if (s == "internet")
fetcher = std::make_unique<InternetLyricsFetcher>();
#ifdef HAVE_TAGLIB_H
Expand Down Expand Up @@ -206,6 +210,42 @@ bool GoogleLyricsFetcher::isURLOk(const std::string &url)
return url.find(siteKeyword()) != std::string::npos;
}

LyricsFetcher::Result DarkLyricsFetcher::fetch(const std::string &artist,
const std::string &title,
const MPD::Song &song)
{
current_title = title;
return GoogleLyricsFetcher::fetch(artist, title, song);
}
void DarkLyricsFetcher::postProcess(std::string &data) const
{
try {
// Escape any special regex characters in the song title
std::string escaped_title = boost::regex_replace(current_title, boost::regex("[.^$|()\\[\\]{}*+?\\\\]"), "\\\\$&");

// Match the <h3> tag with the title, and capture EVERYTHING after it
std::string pattern = "(?is)<h3>.*?" + escaped_title + ".*?</h3>(.*)";
boost::regex rx(pattern);
boost::smatch match;

if (boost::regex_search(data, match, rx)) {
std::string song_data = match[1].str();

// Cut off the text as soon as the next song's <h3> tag starts
size_t next_h3 = song_data.find("<h3>");
if (next_h3 != std::string::npos) {
song_data = song_data.substr(0, next_h3);
}

data = song_data;
}
} catch (...) {}

// Pass it back to the default postProcess to strip the remaining HTML tags
LyricsFetcher::postProcess(data);
}


/**********************************************************************/

LyricsFetcher::Result InternetLyricsFetcher::fetch(const std::string &artist,
Expand Down
22 changes: 22 additions & 0 deletions src/lyrics_fetcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,28 @@ struct ZeneszovegFetcher : public GoogleLyricsFetcher
virtual const char *regex() const override { return "<div class=\"lyrics-plain-text trans_original\">(.*?)</div>"; }
};

struct AzLyricsFetcher : public GoogleLyricsFetcher
{
virtual const char *name() const override { return "azlyrics.com"; }
protected:
virtual const char *regex() const override { return "(?s)<!-- Usage of azlyrics\\.com content.*?-->(.*?)</div>"; }
};

struct DarkLyricsFetcher : public GoogleLyricsFetcher
{
virtual const char *name() const override { return "darklyrics.com"; }
virtual Result fetch(const std::string &artist, const std::string &title, const MPD::Song &song) override;

protected:
virtual const char *regex() const override {
return "(?s)<div class=\"lyrics\">(.*?)(?:<div class=\"thanks\"|<div class=\"note\"|</div>)";
}
virtual void postProcess(std::string &data) const override;

private:
std::string current_title;
};

struct InternetLyricsFetcher : public GoogleLyricsFetcher
{
virtual const char *name() const override { return "the Internet"; }
Expand Down
2 changes: 1 addition & 1 deletion src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ bool Configuration::read(const std::vector<std::string> &config_paths, bool igno
#ifdef HAVE_TAGLIB_H
"tags, "
#endif
"tekstowo, plyrics, justsomelyrics, jahlyrics, zeneszoveg, internet", [this](std::string v) {
"tekstowo, plyrics, justsomelyrics, jahlyrics, zeneszoveg, azlyrics, darklyrics, internet", [this](std::string v) {
lyrics_fetchers = list_of<LyricsFetcher_>(v, [](std::string s) {
LyricsFetcher_ fetcher;
try {
Expand Down