Make 'update_environment' action also update local mpd status
[ncmpcpp.git] / src / lyrics_fetcher.h
bloba6b7df790352662992c0566194b4646dc00477ab
1 /***************************************************************************
2 * Copyright (C) 2008-2016 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 const char *name() const = 0;
34 virtual Result fetch(const std::string &artist, const std::string &title);
36 protected:
37 virtual const char *urlTemplate() const = 0;
38 virtual const char *regex() const = 0;
40 virtual bool notLyrics(const std::string &) const { return false; }
41 virtual void postProcess(std::string &data) const;
43 std::vector<std::string> getContent(const char *regex, const std::string &data);
45 static const char msgNotFound[];
48 typedef std::unique_ptr<LyricsFetcher> LyricsFetcher_;
50 typedef std::vector<LyricsFetcher_> LyricsFetchers;
52 std::istream &operator>>(std::istream &is, LyricsFetcher_ &fetcher);
54 /**********************************************************************/
56 struct LyricwikiFetcher : public LyricsFetcher
58 virtual const char *name() const override { return "lyricwiki.com"; }
59 virtual Result fetch(const std::string &artist, const std::string &title) override;
61 protected:
62 virtual const char *urlTemplate() const override { return "http://lyrics.wikia.com/api.php?action=lyrics&fmt=xml&func=getSong&artist=%artist%&song=%title%"; }
63 virtual const char *regex() const override { return "<url>(.*?)</url>"; }
65 virtual bool notLyrics(const std::string &data) const override;
68 /**********************************************************************/
70 struct GoogleLyricsFetcher : public LyricsFetcher
72 virtual Result fetch(const std::string &artist, const std::string &title);
74 protected:
75 virtual const char *urlTemplate() const { return URL; }
76 virtual const char *siteKeyword() const { return name(); }
78 virtual bool isURLOk(const std::string &url);
80 private:
81 const char *URL;
84 struct MetrolyricsFetcher : public GoogleLyricsFetcher
86 virtual const char *name() const override { return "metrolyrics.com"; }
88 protected:
89 virtual const char *regex() const override { return "<div class=\"lyrics-body\">(.*?)</div>"; }
91 virtual bool isURLOk(const std::string &url) override;
94 struct LyricsmaniaFetcher : public GoogleLyricsFetcher
96 virtual const char *name() const override { return "lyricsmania.com"; }
98 protected:
99 virtual const char *regex() const override { return "<div class=\"lyrics-body\".*?</strong>(.*?)</div>"; }
102 struct Sing365Fetcher : public GoogleLyricsFetcher
104 virtual const char *name() const override { return "sing365.com"; }
106 protected:
107 virtual const char *regex() const override { return "<!-Lyrics Begin->(.*?)<!-Lyrics End->"; }
110 struct JustSomeLyricsFetcher : public GoogleLyricsFetcher
112 virtual const char *name() const override { return "justsomelyrics.com"; }
114 protected:
115 virtual const char *regex() const override { return "<div class=\"content.*?</div>\\s*</div>(.*?)<div"; }
118 struct AzLyricsFetcher : public GoogleLyricsFetcher
120 virtual const char *name() const override { return "azlyrics.com"; }
122 protected:
123 virtual const char *regex() const override { return "<div class=\"lyricsh\">.*?</h2>.*<div>(.*?)</div>"; }
126 struct GeniusFetcher : public GoogleLyricsFetcher
128 virtual const char *name() const override { return "genius.com"; }
130 protected:
131 virtual const char *regex() const override { return "<lyrics.*?>(.*?)</lyrics>"; }
134 struct TekstowoFetcher : public GoogleLyricsFetcher
136 virtual const char *name() const override { return "tekstowo.pl"; }
138 protected:
139 virtual const char *regex() const override { return "<div class=\"song-text\">.*?</h2>(.*?)<a"; }
142 struct InternetLyricsFetcher : public GoogleLyricsFetcher
144 virtual const char *name() const override { return "the Internet"; }
145 virtual Result fetch(const std::string &artist, const std::string &title) override;
147 protected:
148 virtual const char *siteKeyword() const override { return "lyrics"; }
149 virtual const char *regex() const override { return ""; }
151 virtual bool isURLOk(const std::string &url) override;
153 private:
154 std::string URL;
157 #endif // NCMPCPP_LYRICS_FETCHER_H