split PressSpace action into modular pieces
[ncmpcpp.git] / src / lyrics_fetcher.h
blob8687bd7daf4dbbe6a2705313b196960edbc9c4f1
1 /***************************************************************************
2 * Copyright (C) 2008-2014 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 #ifdef HAVE_CURL_CURL_H
28 #include <string>
30 struct LyricsFetcher
32 typedef std::pair<bool, std::string> Result;
34 virtual const char *name() = 0;
35 virtual Result fetch(const std::string &artist, const std::string &title);
37 protected:
38 virtual const char *urlTemplate() = 0;
39 virtual const char *regex() = 0;
41 virtual bool notLyrics(const std::string &) { return false; }
42 virtual void postProcess(std::string &data);
44 std::vector<std::string> getContent(const char *regex, const std::string &data);
46 static const char msgNotFound[];
49 struct LyricwikiFetcher : public LyricsFetcher
51 virtual const char *name() { return "lyricwiki.com"; }
52 virtual Result fetch(const std::string &artist, const std::string &title);
54 protected:
55 virtual const char *urlTemplate() { return "http://lyrics.wikia.com/api.php?action=lyrics&fmt=xml&func=getSong&artist=%artist%&song=%title%"; }
56 virtual const char *regex() { return "<url>(.*?)</url>"; }
58 virtual bool notLyrics(const std::string &data);
61 /**********************************************************************/
63 struct GoogleLyricsFetcher : public LyricsFetcher
65 virtual Result fetch(const std::string &artist, const std::string &title);
67 protected:
68 virtual const char *urlTemplate() { return URL; }
69 virtual const char *siteKeyword() { return name(); }
71 virtual bool isURLOk(const std::string &url);
73 private:
74 const char *URL;
77 struct MetrolyricsFetcher : public GoogleLyricsFetcher
79 virtual const char *name() { return "metrolyrics.com"; }
81 protected:
82 virtual const char *regex() { return "<div id=\"lyrics-body\">(.*?)</div>"; }
84 virtual bool isURLOk(const std::string &url);
85 virtual void postProcess(std::string &data);
88 struct LyricsmaniaFetcher : public GoogleLyricsFetcher
90 virtual const char *name() { return "lyricsmania.com"; }
92 protected:
93 virtual const char *regex() { return "<div class=\"lyrics-body\".*?</strong>(.*?)</div>"; }
96 struct Sing365Fetcher : public GoogleLyricsFetcher
98 virtual const char *name() { return "sing365.com"; }
100 protected:
101 virtual const char *regex() { return "<script src=\"//srv.tonefuse.com/showads/showad.js\"></script>(.*?)<script>\n/\\* Sing365 - Below Lyrics"; }
103 virtual void postProcess(std::string &data);
106 struct JustSomeLyricsFetcher : public GoogleLyricsFetcher
108 virtual const char *name() { return "justsomelyrics.com"; }
110 protected:
111 virtual const char *regex() { return "<div class=\"core-left\">(.*?)</div>"; }
114 struct AzLyricsFetcher : public GoogleLyricsFetcher
116 virtual const char *name() { return "azlyrics.com"; }
118 protected:
119 virtual const char *regex() { return "<!-- start of lyrics -->(.*?)<!-- end of lyrics -->"; }
122 struct InternetLyricsFetcher : public GoogleLyricsFetcher
124 virtual const char *name() { return "the Internet"; }
125 virtual Result fetch(const std::string &artist, const std::string &title);
127 protected:
128 virtual const char *siteKeyword() { return "lyrics"; }
129 virtual const char *regex() { return ""; }
131 virtual bool isURLOk(const std::string &url);
133 private:
134 std::string URL;
137 extern LyricsFetcher *lyricsPlugins[];
139 #endif // HAVE_CURL_CURL_H
141 #endif // NCMPCPP_LYRICS_FETCHER_H