2010-09-26 16:21:23 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-09-26 16:21:23 +02:00
|
|
|
|
|
|
|
Clementine 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-10-10 18:09:20 +02:00
|
|
|
#ifndef ULTIMATELYRICSPROVIDER_H
|
|
|
|
#define ULTIMATELYRICSPROVIDER_H
|
2010-09-26 16:21:23 +02:00
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QPair>
|
|
|
|
#include <QStringList>
|
|
|
|
|
2010-10-10 18:09:20 +02:00
|
|
|
#include "songinfoprovider.h"
|
2010-09-26 16:21:23 +02:00
|
|
|
|
2010-10-10 18:09:20 +02:00
|
|
|
class NetworkAccessManager;
|
|
|
|
|
|
|
|
class QNetworkReply;
|
|
|
|
|
|
|
|
class UltimateLyricsProvider : public SongInfoProvider {
|
2010-09-26 16:21:23 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2010-10-16 19:20:54 +02:00
|
|
|
UltimateLyricsProvider();
|
2010-09-26 16:21:23 +02:00
|
|
|
|
|
|
|
static const int kRedirectLimit;
|
|
|
|
|
|
|
|
typedef QPair<QString, QString> RuleItem;
|
|
|
|
typedef QList<RuleItem> Rule;
|
|
|
|
typedef QPair<QString, QString> UrlFormat;
|
|
|
|
|
|
|
|
void set_name(const QString& name) { name_ = name; }
|
|
|
|
void set_title(const QString& title) { title_ = title; }
|
|
|
|
void set_url(const QString& url) { url_ = url; }
|
|
|
|
void set_charset(const QString& charset) { charset_ = charset; }
|
2010-10-10 18:46:35 +02:00
|
|
|
void set_relevance(int relevance) { relevance_ = relevance; }
|
2010-09-26 16:21:23 +02:00
|
|
|
|
|
|
|
void add_url_format(const QString& replace, const QString& with) {
|
2014-02-07 16:34:20 +01:00
|
|
|
url_formats_ << UrlFormat(replace, with);
|
|
|
|
}
|
2010-09-26 16:21:23 +02:00
|
|
|
|
|
|
|
void add_extract_rule(const Rule& rule) { extract_rules_ << rule; }
|
|
|
|
void add_exclude_rule(const Rule& rule) { exclude_rules_ << rule; }
|
2014-02-07 16:34:20 +01:00
|
|
|
void add_invalid_indicator(const QString& indicator) {
|
|
|
|
invalid_indicators_ << indicator;
|
|
|
|
}
|
2010-09-26 16:21:23 +02:00
|
|
|
|
2010-10-10 18:46:35 +02:00
|
|
|
QString name() const { return name_; }
|
|
|
|
int relevance() const { return relevance_; }
|
|
|
|
|
2010-10-10 18:09:20 +02:00
|
|
|
void FetchInfo(int id, const Song& metadata);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private slots:
|
2010-10-16 19:20:54 +02:00
|
|
|
void LyricsFetched();
|
2010-09-26 16:21:23 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2013-12-03 10:21:52 +01:00
|
|
|
bool ApplyExtractRule(const Rule& rule, QString* content) const;
|
2010-09-26 16:21:23 +02:00
|
|
|
void ApplyExcludeRule(const Rule& rule, QString* content) const;
|
|
|
|
|
2013-12-03 10:21:52 +01:00
|
|
|
static QString ExtractUrl(const QString& source, const Rule& rule);
|
2010-09-26 16:21:23 +02:00
|
|
|
static QString ExtractXmlTag(const QString& source, const QString& tag);
|
2014-02-07 16:34:20 +01:00
|
|
|
static QString Extract(const QString& source, const QString& begin,
|
|
|
|
const QString& end);
|
2010-09-26 16:21:23 +02:00
|
|
|
static QString ExcludeXmlTag(const QString& source, const QString& tag);
|
2014-02-07 16:34:20 +01:00
|
|
|
static QString Exclude(const QString& source, const QString& begin,
|
|
|
|
const QString& end);
|
2010-09-26 16:21:23 +02:00
|
|
|
static QString FirstChar(const QString& text);
|
|
|
|
static QString TitleCase(const QString& text);
|
2012-02-12 16:17:18 +01:00
|
|
|
static QString NoSpace(const QString& text);
|
2014-01-02 23:52:35 +01:00
|
|
|
static bool HTMLHasAlphaNumeric(const QString& html);
|
2012-02-12 16:17:18 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void ReplaceField(const QString& tag, const QString& value,
|
|
|
|
QString* text) const;
|
2012-02-12 16:17:18 +01:00
|
|
|
void ReplaceFields(const Song& metadata, QString* text) const;
|
2010-09-26 16:21:23 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2010-10-10 18:09:20 +02:00
|
|
|
NetworkAccessManager* network_;
|
2010-10-16 19:20:54 +02:00
|
|
|
QMap<QNetworkReply*, int> requests_;
|
2010-10-10 18:09:20 +02:00
|
|
|
|
2010-09-26 16:21:23 +02:00
|
|
|
QString name_;
|
|
|
|
QString title_;
|
|
|
|
QString url_;
|
|
|
|
QString charset_;
|
2010-10-10 18:46:35 +02:00
|
|
|
int relevance_;
|
2010-09-26 16:21:23 +02:00
|
|
|
|
|
|
|
QList<UrlFormat> url_formats_;
|
|
|
|
QList<Rule> extract_rules_;
|
|
|
|
QList<Rule> exclude_rules_;
|
|
|
|
QStringList invalid_indicators_;
|
2010-10-10 18:09:20 +02:00
|
|
|
|
2012-02-12 16:17:18 +01:00
|
|
|
Song metadata_;
|
2010-10-10 18:09:20 +02:00
|
|
|
int redirect_count_;
|
2013-12-03 10:21:52 +01:00
|
|
|
bool url_hop_;
|
2010-09-26 16:21:23 +02:00
|
|
|
};
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
#endif // ULTIMATELYRICSPROVIDER_H
|