1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
/***************************************************************************
* Copyright (C) 2008-2013 by Andrzej Rybczak *
* electricityispower@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef NCMPCPP_LYRICS_FETCHER_H
#define NCMPCPP_LYRICS_FETCHER_H
#include "config.h"
#ifdef HAVE_CURL_CURL_H
#include <string>
struct LyricsFetcher
{
typedef std::pair<bool, std::string> Result;
virtual const char *name() = 0;
virtual Result fetch(const std::string &artist, const std::string &title);
protected:
virtual const char *urlTemplate() = 0;
virtual const char *regex() = 0;
virtual bool notLyrics(const std::string &) { return false; }
virtual void postProcess(std::string &data);
std::vector<std::string> getContent(const char *regex, const std::string &data);
static const char msgNotFound[];
};
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 *urlTemplate() { 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);
};
/**********************************************************************/
struct GoogleLyricsFetcher : public LyricsFetcher
{
virtual Result fetch(const std::string &artist, const std::string &title);
protected:
virtual const char *urlTemplate() { return URL; }
virtual const char *siteKeyword() { return name(); }
virtual bool isURLOk(const std::string &url);
private:
const char *URL;
};
struct MetrolyricsFetcher : public GoogleLyricsFetcher
{
virtual const char *name() { return "metrolyrics.com"; }
protected:
virtual const char *regex() { return "<div id=\"lyrics-body\">(.*?)</div>"; }
virtual bool isURLOk(const std::string &url);
virtual void postProcess(std::string &data);
};
struct LyricsmaniaFetcher : public GoogleLyricsFetcher
{
virtual const char *name() { return "lyricsmania.com"; }
protected:
virtual const char *regex() { return "<div id='songlyrics_h' class='dn'>(.*?)</div>"; }
virtual void postProcess(std::string &data);
};
struct Sing365Fetcher : public GoogleLyricsFetcher
{
virtual const char *name() { return "sing365.com"; }
protected:
virtual const char *regex() { return "<div style=\"font-size: 14px;\">(.*?)</div>"; }
};
struct JustSomeLyricsFetcher : public GoogleLyricsFetcher
{
virtual const char *name() { return "justsomelyrics.com"; }
protected:
virtual const char *regex() { return "<p class=\"lyrics\">(.*?)</p>"; }
};
struct AzLyricsFetcher : public GoogleLyricsFetcher
{
virtual const char *name() { return "azlyrics.com"; }
protected:
virtual const char *regex() { return "<!-- start of lyrics -->(.*?)<!-- end of lyrics -->"; }
};
struct InternetLyricsFetcher : public GoogleLyricsFetcher
{
virtual const char *name() { return "the Internet"; }
virtual Result fetch(const std::string &artist, const std::string &title);
protected:
virtual const char *siteKeyword() { return "lyrics"; }
virtual const char *regex() { return ""; }
virtual bool isURLOk(const std::string &url);
private:
std::string URL;
};
extern LyricsFetcher *lyricsPlugins[];
#endif // HAVE_CURL_CURL_H
#endif // NCMPCPP_LYRICS_FETCHER_H
|