summaryrefslogtreecommitdiff
path: root/src/lyrics_fetcher.h
diff options
context:
space:
mode:
authorAndrzej Rybczak <electricityispower@gmail.com>2013-07-09 00:20:04 +0200
committerAndrzej Rybczak <electricityispower@gmail.com>2013-07-09 00:42:23 +0200
commit6d6110a52b15335c1eb752ae6596b677b7ddc45c (patch)
treef352f2908d58307954af07b62610e55aa48e6ed7 /src/lyrics_fetcher.h
parentaf10ac883f366da082cf26e23fc55ed24bbefb9d (diff)
lyrics fetcher: throw away broken fetchers and fix/improve existing ones
Diffstat (limited to 'src/lyrics_fetcher.h')
-rw-r--r--src/lyrics_fetcher.h106
1 files changed, 13 insertions, 93 deletions
diff --git a/src/lyrics_fetcher.h b/src/lyrics_fetcher.h
index 0da57dcc..0f16e3e1 100644
--- a/src/lyrics_fetcher.h
+++ b/src/lyrics_fetcher.h
@@ -35,37 +35,25 @@ struct LyricsFetcher
virtual Result fetch(const std::string &artist, const std::string &title);
protected:
- virtual const char *getURL() = 0;
- virtual const char *getOpenTag() = 0;
- virtual const char *getCloseTag() = 0;
+ virtual const char *url() = 0;
+ virtual const char *regex() = 0;
virtual bool notLyrics(const std::string &) { return false; }
virtual void postProcess(std::string &data);
- bool getContent(const char *open_tag, const char *close_tag, std::string &data);
+ std::vector<std::string> getContent(const char *regex, const std::string &data);
static const char msgNotFound[];
};
-struct LyrcComArFetcher : public LyricsFetcher
-{
- virtual const char *name() { return "lyrc.com.ar"; }
-
-protected:
- virtual const char *getURL() { return "http://lyrc.com.ar/tema1es.php?artist=%artist%&songname=%title%"; }
- virtual const char *getOpenTag() { return "</table>"; }
- virtual const char *getCloseTag() { return "<p>"; }
-};
-
struct LyricwikiFetcher : public LyricsFetcher
{
virtual const char *name() { return "lyricwiki.com"; }
virtual Result fetch(const std::string &artist, const std::string &title);
protected:
- virtual const char *getURL() { return "http://lyrics.wikia.com/api.php?action=lyrics&fmt=xml&func=getSong&artist=%artist%&song=%title%"; }
- virtual const char *getOpenTag() { return "<url>"; }
- virtual const char *getCloseTag() { return "</url>"; }
+ virtual const char *url() { return "http://lyrics.wikia.com/api.php?action=lyrics&fmt=xml&func=getSong&artist=%artist%&song=%title%"; }
+ virtual const char *regex() { return "<url>(.*?)</url>"; }
virtual bool notLyrics(const std::string &data);
};
@@ -77,8 +65,8 @@ struct GoogleLyricsFetcher : public LyricsFetcher
virtual Result fetch(const std::string &artist, const std::string &title);
protected:
- virtual const char *getSiteKeyword() = 0;
- virtual const char *getURL() { return URL; }
+ virtual const char *url() { return URL; }
+ virtual const char *siteKeyword() { return name(); }
virtual bool isURLOk(const std::string &url);
@@ -86,31 +74,14 @@ private:
const char *URL;
};
-struct LyricstimeFetcher : public GoogleLyricsFetcher
-{
- virtual const char *name() { return "lyricstime.com"; }
-
-protected:
- virtual const char *getSiteKeyword() { return "lyricstime"; }
- virtual const char *getOpenTag() { return "<div id=\"songlyrics\" >"; }
- virtual const char *getCloseTag() { return "</div>"; }
-
- virtual bool isURLOk(const std::string &url);
-
- virtual void postProcess(std::string &data);
-};
-
struct MetrolyricsFetcher : public GoogleLyricsFetcher
{
virtual const char *name() { return "metrolyrics.com"; }
protected:
- virtual const char *getSiteKeyword() { return "metrolyrics"; }
- virtual const char *getOpenTag() { return "<div id=\"lyrics\">"; }
- virtual const char *getCloseTag() { return "</div>"; }
+ virtual const char *regex() { return "<div id=\"lyrics-body\">(.*?)</div>"; }
virtual bool isURLOk(const std::string &url);
-
virtual void postProcess(std::string &data);
};
@@ -119,55 +90,17 @@ struct LyricsmaniaFetcher : public GoogleLyricsFetcher
virtual const char *name() { return "lyricsmania.com"; }
protected:
- virtual const char *getSiteKeyword() { return "lyricsmania"; }
- virtual const char *getOpenTag() { return "</strong> :<br />"; }
- virtual const char *getCloseTag() { return "&#91; <a"; }
+ virtual const char *regex() { return "<div id='songlyrics_h' class='dn'>(.*?)</div>"; }
virtual void postProcess(std::string &data);
};
-struct SonglyricsFetcher : public GoogleLyricsFetcher
-{
- virtual const char *name() { return "songlyrics.com"; }
-
-protected:
- virtual const char *getSiteKeyword() { return "songlyrics"; }
- virtual const char *getOpenTag() { return "-6000px;\">"; }
- virtual const char *getCloseTag() { return "</p>"; }
-
- virtual void postProcess(std::string &data);
-};
-
-struct LyriczzFetcher : public GoogleLyricsFetcher
-{
- virtual const char *name() { return "lyriczz.com"; }
-
-protected:
- virtual const char *getSiteKeyword() { return "lyriczz"; }
- virtual const char *getOpenTag() { return "border=0 /></a>"; }
- virtual const char *getCloseTag() { return "<a href"; }
-};
-
struct Sing365Fetcher : public GoogleLyricsFetcher
{
virtual const char *name() { return "sing365.com"; }
protected:
- virtual const char *getSiteKeyword() { return "sing365"; }
- virtual const char *getOpenTag() { return "<br><br></div>"; }
- virtual const char *getCloseTag() { return "<div align"; }
-};
-
-struct LyricsvipFetcher : public GoogleLyricsFetcher
-{
- virtual const char *name() { return "lyricsvip.com"; }
-
-protected:
- virtual const char *getSiteKeyword() { return "lyricsvip"; }
- virtual const char *getOpenTag() { return "</h2>"; }
- virtual const char *getCloseTag() { return "</td>"; }
-
- virtual void postProcess(std::string &data);
+ virtual const char *regex() { return "<div style=\"font-size: 14px;\">(.*?)</div>"; }
};
struct JustSomeLyricsFetcher : public GoogleLyricsFetcher
@@ -175,19 +108,7 @@ struct JustSomeLyricsFetcher : public GoogleLyricsFetcher
virtual const char *name() { return "justsomelyrics.com"; }
protected:
- virtual const char *getSiteKeyword() { return "justsomelyrics"; }
- virtual const char *getOpenTag() { return "alt=\"phone\" />\n</div>"; }
- virtual const char *getCloseTag() { return "<div class=\"adsdiv\">"; }
-};
-
-struct LoloLyricsFetcher : public GoogleLyricsFetcher
-{
- virtual const char *name() { return "lololyrics.com"; }
-
-protected:
- virtual const char *getSiteKeyword() { return "lololyrics"; }
- virtual const char *getOpenTag() { return "<div class=\"lyrics_txt\" id=\"lyrics_txt\" style=\"font-size:12px; letter-spacing:0.2px; line-height:20px;\">"; }
- virtual const char *getCloseTag() { return "</div>"; }
+ virtual const char *regex() { return "<p class=\"lyrics\">(.*?)</p>"; }
};
struct InternetLyricsFetcher : public GoogleLyricsFetcher
@@ -196,9 +117,8 @@ struct InternetLyricsFetcher : public GoogleLyricsFetcher
virtual Result fetch(const std::string &artist, const std::string &title);
protected:
- virtual const char *getSiteKeyword() { return "lyrics"; }
- virtual const char *getOpenTag() { return ""; }
- virtual const char *getCloseTag() { return ""; }
+ virtual const char *siteKeyword() { return "lyrics"; }
+ virtual const char *regex() { return ""; }
virtual bool isURLOk(const std::string &url);