Code review comments from r2050
This commit is contained in:
parent
bd273efe0d
commit
f90f51197d
@ -42,14 +42,14 @@ LyricProvider::Result HtmlScraper::Search(const Song& metadata) const {
|
|||||||
|
|
||||||
// Fill in fields in the URL
|
// Fill in fields in the URL
|
||||||
QString url_text(url_);
|
QString url_text(url_);
|
||||||
DoUrlReplace(&url_text, "{artist}", metadata.artist().toLower());
|
DoUrlReplace("{artist}", metadata.artist().toLower(), &url_text);
|
||||||
DoUrlReplace(&url_text, "{album}", metadata.album().toLower());
|
DoUrlReplace("{album}", metadata.album().toLower(), &url_text);
|
||||||
DoUrlReplace(&url_text, "{title}", metadata.title().toLower());
|
DoUrlReplace("{title}", metadata.title().toLower(), &url_text);
|
||||||
DoUrlReplace(&url_text, "{Artist}", metadata.artist());
|
DoUrlReplace("{Artist}", metadata.artist(), &url_text);
|
||||||
DoUrlReplace(&url_text, "{Album}", metadata.album());
|
DoUrlReplace("{Album}", metadata.album(), &url_text);
|
||||||
DoUrlReplace(&url_text, "{Title}", metadata.title());
|
DoUrlReplace("{Title}", metadata.title(), &url_text);
|
||||||
DoUrlReplace(&url_text, "{Title2}", TitleCase(metadata.title()));
|
DoUrlReplace("{Title2}", TitleCase(metadata.title()), &url_text);
|
||||||
DoUrlReplace(&url_text, "{a}", FirstChar(metadata.artist()));
|
DoUrlReplace("{a}", FirstChar(metadata.artist()), &url_text);
|
||||||
|
|
||||||
QUrl url(url_text);
|
QUrl url(url_text);
|
||||||
|
|
||||||
@ -66,16 +66,16 @@ LyricProvider::Result HtmlScraper::Search(const Song& metadata) const {
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
QVariant redirect_target = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
|
QVariant redirect_target = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
|
||||||
if (redirect_target.isValid()) {
|
if (!redirect_target.isValid())
|
||||||
QUrl target = redirect_target.toUrl();
|
|
||||||
if (target.scheme().isEmpty() || target.host().isEmpty()) {
|
|
||||||
QString path = target.path();
|
|
||||||
target = url;
|
|
||||||
target.setPath(path);
|
|
||||||
}
|
|
||||||
url = target;
|
|
||||||
} else
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
QUrl target = redirect_target.toUrl();
|
||||||
|
if (target.scheme().isEmpty() || target.host().isEmpty()) {
|
||||||
|
QString path = target.path();
|
||||||
|
target = url;
|
||||||
|
target.setPath(path);
|
||||||
|
}
|
||||||
|
url = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString original_content = codec->toUnicode(reply->readAll());
|
const QString original_content = codec->toUnicode(reply->readAll());
|
||||||
@ -116,7 +116,7 @@ void HtmlScraper::ApplyExtractRule(const Rule& rule, QString* content) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString HtmlScraper::ExtractXmlTag(const QString& source, const QString& tag) {
|
QString HtmlScraper::ExtractXmlTag(const QString& source, const QString& tag) {
|
||||||
QRegExp re("<(\\w+).*>");
|
QRegExp re("<(\\w+).*>"); // ಠ_ಠ
|
||||||
if (re.indexIn(tag) == -1)
|
if (re.indexIn(tag) == -1)
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ void HtmlScraper::ApplyExcludeRule(const Rule& rule, QString* content) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString HtmlScraper::ExcludeXmlTag(const QString& source, const QString& tag) {
|
QString HtmlScraper::ExcludeXmlTag(const QString& source, const QString& tag) {
|
||||||
QRegExp re("<(\\w+).*>");
|
QRegExp re("<(\\w+).*>"); // ಠ_ಠ
|
||||||
if (re.indexIn(tag) == -1)
|
if (re.indexIn(tag) == -1)
|
||||||
return source;
|
return source;
|
||||||
|
|
||||||
@ -180,8 +180,8 @@ QString HtmlScraper::TitleCase(const QString& text) {
|
|||||||
return text[0].toUpper() + text.right(text.length() - 1).toLower();
|
return text[0].toUpper() + text.right(text.length() - 1).toLower();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HtmlScraper::DoUrlReplace(QString* url, const QString& tag,
|
void HtmlScraper::DoUrlReplace(const QString& tag, const QString& value,
|
||||||
const QString& value) const {
|
QString* url) const {
|
||||||
if (!url->contains(tag))
|
if (!url->contains(tag))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ 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(QString* url, const QString& tag, const QString& value) const;
|
void DoUrlReplace(const QString& tag, const QString& value, QString* url) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString name_;
|
QString name_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user