File: lyrics_fetcher.h

package info (click to toggle)
ncmpcpp 0.5.10-1.1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,820 kB
  • sloc: cpp: 17,199; sh: 11,214; makefile: 50
file content (213 lines) | stat: -rw-r--r-- 7,211 bytes parent folder | download | duplicates (2)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/***************************************************************************
 *   Copyright (C) 2008-2012 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 _LYRICS_FETCHER_H
#define _LYRICS_FETCHER_H

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#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 *getURL() = 0;
		virtual const char *getOpenTag() = 0;
		virtual const char *getCloseTag() = 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);
		
		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 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 *getSiteKeyword() = 0;
		virtual const char *getURL() { return URL; }
		
		virtual bool isURLOk(const std::string &url);
		
	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 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 *getSiteKeyword() { return "lyricsmania"; }
		virtual const char *getOpenTag() { return "</strong> :<br />"; }
		virtual const char *getCloseTag() { return "&#91; <a"; }
		
		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>"; }
};

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>"; }
};

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 *getSiteKeyword() { return "lyrics"; }
		virtual const char *getOpenTag() { return ""; }
		virtual const char *getCloseTag() { return ""; }
		
		virtual bool isURLOk(const std::string &url);
		
	private:
		std::string URL;
};

extern LyricsFetcher *lyricsPlugins[];

#endif // HAVE_CURL_CURL_H

#endif