Lyrics fetcher: fix lyricsmania.com and sing365.com fetchers
[ncmpcpp.git] / src / lyrics_fetcher.h
blob94850a74a65c135c5158c3cd10ff6927cd68cd16
1 /***************************************************************************
2 * Copyright (C) 2008-2017 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #ifndef NCMPCPP_LYRICS_FETCHER_H
22 #define NCMPCPP_LYRICS_FETCHER_H
24 #include "config.h"
26 #include <memory>
27 #include <string>
29 struct LyricsFetcher
31 typedef std::pair<bool, std::string> Result;
33 virtual ~LyricsFetcher() { }
35 virtual const char *name() const = 0;
36 virtual Result fetch(const std::string &artist, const std::string &title);
38 protected:
39 virtual const char *urlTemplate() const = 0;
40 virtual const char *regex() const = 0;
42 virtual bool notLyrics(const std::string &) const { return false; }
43 virtual void postProcess(std::string &data) const;
45 std::vector<std::string> getContent(const char *regex, const std::string &data);
47 static const char msgNotFound[];
50 typedef std::unique_ptr<LyricsFetcher> LyricsFetcher_;
52 typedef std::vector<LyricsFetcher_> LyricsFetchers;
54 std::istream &operator>>(std::istream &is, LyricsFetcher_ &fetcher);
56 /**********************************************************************/
58 struct LyricwikiFetcher : public LyricsFetcher
60 virtual const char *name() const override { return "lyricwiki.com"; }
61 virtual Result fetch(const std::string &artist, const std::string &title) override;
63 protected:
64 virtual const char *urlTemplate() const override { return "http://lyrics.wikia.com/api.php?action=lyrics&fmt=xml&func=getSong&artist=%artist%&song=%title%"; }
65 virtual const char *regex() const override { return "<url>(.*?)</url>"; }
67 virtual bool notLyrics(const std::string &data) const override;
70 /**********************************************************************/
72 struct GoogleLyricsFetcher : public LyricsFetcher
74 virtual Result fetch(const std::string &artist, const std::string &title);
76 protected:
77 virtual const char *urlTemplate() const { return URL; }
78 virtual const char *siteKeyword() const { return name(); }
80 virtual bool isURLOk(const std::string &url);
82 private:
83 const char *URL;
86 struct MetrolyricsFetcher : public GoogleLyricsFetcher
88 virtual const char *name() const override { return "metrolyrics.com"; }
90 protected:
91 virtual const char *regex() const override { return "<div class=\"lyrics-body\">(.*?)</div>"; }
93 virtual bool isURLOk(const std::string &url) override;
96 struct LyricsmaniaFetcher : public GoogleLyricsFetcher
98 virtual const char *name() const override { return "lyricsmania.com"; }
100 protected:
101 virtual const char *regex() const override { return "<div class=\"lyrics-body\".*?</div>(.*?)</div>"; }
104 struct Sing365Fetcher : public GoogleLyricsFetcher
106 virtual const char *name() const override { return "sing365.com"; }
108 protected:
109 virtual const char *regex() const override { return "<div class=\"content\">.*?</script></div>(.*?)<script>"; }
112 struct JustSomeLyricsFetcher : public GoogleLyricsFetcher
114 virtual const char *name() const override { return "justsomelyrics.com"; }
116 protected:
117 virtual const char *regex() const override { return "<div class=\"content.*?</div>(.*?)See also"; }
120 struct AzLyricsFetcher : public GoogleLyricsFetcher
122 virtual const char *name() const override { return "azlyrics.com"; }
124 protected:
125 virtual const char *regex() const override { return "<div class=\"lyricsh\">.*?</h2>.*<div>(.*?)</div>"; }
128 struct GeniusFetcher : public GoogleLyricsFetcher
130 virtual const char *name() const override { return "genius.com"; }
132 protected:
133 virtual const char *regex() const override { return "<div class=\"lyrics\">(.*?)</div>"; }
136 struct JahLyricsFetcher : public GoogleLyricsFetcher
138 virtual const char *name() const override { return "jah-lyrics.com"; }
140 protected:
141 virtual const char *regex() const override { return "<div class=\"song-header\">.*?</div>(.*?)<p class=\"disclaimer\">"; }
144 struct PLyricsFetcher : public GoogleLyricsFetcher
146 virtual const char *name() const override { return "plyrics.com"; }
148 protected:
149 virtual const char *regex() const override { return "<!-- start of lyrics -->(.*?)<!-- end of lyrics -->"; }
152 struct TekstowoFetcher : public GoogleLyricsFetcher
154 virtual const char *name() const override { return "tekstowo.pl"; }
156 protected:
157 virtual const char *regex() const override { return "<div class=\"song-text\">.*?</h2>(.*?)<a"; }
160 struct InternetLyricsFetcher : public GoogleLyricsFetcher
162 virtual const char *name() const override { return "the Internet"; }
163 virtual Result fetch(const std::string &artist, const std::string &title) override;
165 protected:
166 virtual const char *siteKeyword() const override { return nullptr; }
167 virtual const char *regex() const override { return ""; }
169 virtual bool isURLOk(const std::string &url) override;
171 private:
172 std::string URL;
175 #endif // NCMPCPP_LYRICS_FETCHER_H