Add darklyrics support and do {field} replacement on extract rules as well as URLs.
Fixes issue 1889
This commit is contained in:
parent
62d5c8224b
commit
051c543373
@ -11,6 +11,15 @@
|
|||||||
<item begin="[" end="]"/>
|
<item begin="[" end="]"/>
|
||||||
</exclude>
|
</exclude>
|
||||||
</provider>
|
</provider>
|
||||||
|
<provider name="darklyrics.com" title ="{ARTIST} LYRICS - "{title}" ({year}) album" charset="utf-8" url="http://www.darklyrics.com/lyrics/{artist2}/{album2}.html">
|
||||||
|
<extract>
|
||||||
|
<item begin="<h3><a name="{track}">{track}. {Title2}</a></h3><br />" end="<h3>"/>
|
||||||
|
</extract>
|
||||||
|
<extract>
|
||||||
|
<item begin="<h3><a name="{track}">{track}. {Title2}</a></h3><br />" end="<div class="thanks">"/>
|
||||||
|
</extract>
|
||||||
|
<invalidIndicator value="The page you requested was not found on DarkLyrics.com."/>
|
||||||
|
</provider>
|
||||||
<provider name="directlyrics.com" title="{artist} - {title} lyrics" charset="iso-8859-1" url="http://www.directlyrics.com/{artist}-{title}-lyrics.html">
|
<provider name="directlyrics.com" title="{artist} - {title} lyrics" charset="iso-8859-1" url="http://www.directlyrics.com/{artist}-{title}-lyrics.html">
|
||||||
<urlFormat replace=" _@,;&\/'"" with="-"/>
|
<urlFormat replace=" _@,;&\/'"" with="-"/>
|
||||||
<urlFormat replace="." with=""/>
|
<urlFormat replace="." with=""/>
|
||||||
@ -195,7 +204,7 @@
|
|||||||
<item begin="<div style="float:left"" end=">"/>
|
<item begin="<div style="float:left"" end=">"/>
|
||||||
</exclude>
|
</exclude>
|
||||||
</provider>
|
</provider>
|
||||||
<provider name="teksty.org" title="{artist} - {title} - tekst" charset="UTF-8" url="http://www.teksty.org/{Artist},{Title2}">
|
<provider name="teksty.org" title="{Artist} - {Title2} - tekst" charset="UTF-8" url="http://www.teksty.org/{artist},{title},tekst-piosenki">
|
||||||
<urlFormat replace=" _@,;&\/"." with="_"/>
|
<urlFormat replace=" _@,;&\/"." with="_"/>
|
||||||
<urlFormat replace="'" with=""/>
|
<urlFormat replace="'" with=""/>
|
||||||
<extract>
|
<extract>
|
||||||
|
@ -113,7 +113,8 @@ void SongInfoView::ReloadSettings() {
|
|||||||
<< "teksty.org"
|
<< "teksty.org"
|
||||||
<< "tekstowo.pl (Polish translations)"
|
<< "tekstowo.pl (Polish translations)"
|
||||||
<< "vagalume.uol.com.br"
|
<< "vagalume.uol.com.br"
|
||||||
<< "vagalume.uol.com.br (Portuguese translations)";
|
<< "vagalume.uol.com.br (Portuguese translations)"
|
||||||
|
<< "darklyrics.com";
|
||||||
|
|
||||||
QVariant saved_order = s.value("search_order", default_order);
|
QVariant saved_order = s.value("search_order", default_order);
|
||||||
foreach (const QVariant& name, saved_order.toList()) {
|
foreach (const QVariant& name, saved_order.toList()) {
|
||||||
|
@ -46,19 +46,13 @@ void UltimateLyricsProvider::FetchInfo(int id, const Song& metadata) {
|
|||||||
|
|
||||||
// Fill in fields in the URL
|
// Fill in fields in the URL
|
||||||
QString url_text(url_);
|
QString url_text(url_);
|
||||||
DoUrlReplace("{artist}", metadata.artist().toLower(), &url_text);
|
ReplaceFields(metadata, &url_text);
|
||||||
DoUrlReplace("{album}", metadata.album().toLower(), &url_text);
|
|
||||||
DoUrlReplace("{title}", metadata.title().toLower(), &url_text);
|
|
||||||
DoUrlReplace("{Artist}", metadata.artist(), &url_text);
|
|
||||||
DoUrlReplace("{Album}", metadata.album(), &url_text);
|
|
||||||
DoUrlReplace("{Title}", metadata.title(), &url_text);
|
|
||||||
DoUrlReplace("{Title2}", TitleCase(metadata.title()), &url_text);
|
|
||||||
DoUrlReplace("{a}", FirstChar(metadata.artist()), &url_text);
|
|
||||||
|
|
||||||
QUrl url(url_text);
|
QUrl url(url_text);
|
||||||
qLog(Debug) << "Fetching lyrics from" << url;
|
qLog(Debug) << "Fetching lyrics from" << url;
|
||||||
|
|
||||||
// Fetch the URL, follow redirects
|
// Fetch the URL, follow redirects
|
||||||
|
metadata_ = metadata;
|
||||||
redirect_count_ = 0;
|
redirect_count_ = 0;
|
||||||
QNetworkReply* reply = network_->get(QNetworkRequest(url));
|
QNetworkReply* reply = network_->get(QNetworkRequest(url));
|
||||||
requests_[reply] = id;
|
requests_[reply] = id;
|
||||||
@ -115,13 +109,20 @@ void UltimateLyricsProvider::LyricsFetched() {
|
|||||||
|
|
||||||
// Apply extract rules
|
// Apply extract rules
|
||||||
foreach (const Rule& rule, extract_rules_) {
|
foreach (const Rule& rule, extract_rules_) {
|
||||||
|
// Modify the rule for this request's metadata
|
||||||
|
Rule rule_copy(rule);
|
||||||
|
for (Rule::iterator it = rule_copy.begin() ; it != rule_copy.end() ; ++it) {
|
||||||
|
ReplaceFields(metadata_, &it->first);
|
||||||
|
}
|
||||||
|
|
||||||
QString content = original_content;
|
QString content = original_content;
|
||||||
ApplyExtractRule(rule, &content);
|
ApplyExtractRule(rule_copy, &content);
|
||||||
|
qLog(Debug) << "Extract rule" << rule_copy << "matched" << content.length();
|
||||||
|
|
||||||
qLog(Debug) << "Extract rule" << rule << "matched" << content.length();
|
if (!content.isEmpty()) {
|
||||||
|
|
||||||
if (!content.isEmpty())
|
|
||||||
lyrics = content;
|
lyrics = content;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply exclude rules
|
// Apply exclude rules
|
||||||
@ -215,14 +216,25 @@ QString UltimateLyricsProvider::FirstChar(const QString& text) {
|
|||||||
QString UltimateLyricsProvider::TitleCase(const QString& text) {
|
QString UltimateLyricsProvider::TitleCase(const QString& text) {
|
||||||
if (text.length() == 0)
|
if (text.length() == 0)
|
||||||
return QString();
|
return QString();
|
||||||
if (text.length() == 1)
|
|
||||||
return text[0].toUpper();
|
QString ret = text;
|
||||||
return text[0].toUpper() + text.right(text.length() - 1).toLower();
|
bool last_was_space = true;
|
||||||
|
|
||||||
|
for (QString::iterator it = ret.begin() ; it != ret.end() ; ++it) {
|
||||||
|
if (last_was_space) {
|
||||||
|
*it = it->toUpper();
|
||||||
|
last_was_space = false;
|
||||||
|
} else if (it->isSpace()) {
|
||||||
|
last_was_space = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UltimateLyricsProvider::DoUrlReplace(const QString& tag, const QString& value,
|
void UltimateLyricsProvider::ReplaceField(const QString& tag, const QString& value,
|
||||||
QString* url) const {
|
QString* text) const {
|
||||||
if (!url->contains(tag))
|
if (!text->contains(tag))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Apply URL character replacement
|
// Apply URL character replacement
|
||||||
@ -232,5 +244,27 @@ void UltimateLyricsProvider::DoUrlReplace(const QString& tag, const QString& val
|
|||||||
value_copy.replace(re, format.second);
|
value_copy.replace(re, format.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
url->replace(tag, value_copy, Qt::CaseInsensitive);
|
text->replace(tag, value_copy, Qt::CaseInsensitive);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UltimateLyricsProvider::ReplaceFields(const Song& metadata, QString* text) const {
|
||||||
|
ReplaceField("{artist}", metadata.artist().toLower(), text);
|
||||||
|
ReplaceField("{artist2}",NoSpace(metadata.artist().toLower()), text);
|
||||||
|
ReplaceField("{album}", metadata.album().toLower(), text);
|
||||||
|
ReplaceField("{album2}", NoSpace(metadata.album().toLower()), text);
|
||||||
|
ReplaceField("{title}", metadata.title().toLower(), text);
|
||||||
|
ReplaceField("{Artist}", metadata.artist(), text);
|
||||||
|
ReplaceField("{Album}", metadata.album(), text);
|
||||||
|
ReplaceField("{ARTIST}", metadata.artist().toUpper(), text);
|
||||||
|
ReplaceField("{year}", metadata.PrettyYear(), text);
|
||||||
|
ReplaceField("{Title}", metadata.title(), text);
|
||||||
|
ReplaceField("{Title2}", TitleCase(metadata.title()), text);
|
||||||
|
ReplaceField("{a}", FirstChar(metadata.artist()), text);
|
||||||
|
ReplaceField("{track}", QString::number(metadata.track()), text);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString UltimateLyricsProvider::NoSpace(const QString& text) {
|
||||||
|
QString ret(text);
|
||||||
|
ret.remove(' ');
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,10 @@ private:
|
|||||||
static QString Exclude(const QString& source, const QString& begin, const QString& end);
|
static QString Exclude(const QString& source, const QString& begin, const QString& end);
|
||||||
static QString FirstChar(const QString& text);
|
static QString FirstChar(const QString& text);
|
||||||
static QString TitleCase(const QString& text);
|
static QString TitleCase(const QString& text);
|
||||||
void DoUrlReplace(const QString& tag, const QString& value, QString* url) const;
|
static QString NoSpace(const QString& text);
|
||||||
|
|
||||||
|
void ReplaceField(const QString& tag, const QString& value, QString* text) const;
|
||||||
|
void ReplaceFields(const Song& metadata, QString* text) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NetworkAccessManager* network_;
|
NetworkAccessManager* network_;
|
||||||
@ -88,6 +91,7 @@ private:
|
|||||||
QList<Rule> exclude_rules_;
|
QList<Rule> exclude_rules_;
|
||||||
QStringList invalid_indicators_;
|
QStringList invalid_indicators_;
|
||||||
|
|
||||||
|
Song metadata_;
|
||||||
int redirect_count_;
|
int redirect_count_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user