Merge pull request #4057 from heduenas/master
Improvement on the detection of empty lyrics
This commit is contained in:
commit
8ac8b33c9d
|
@ -141,7 +141,7 @@ void UltimateLyricsProvider::LyricsFetched() {
|
||||||
ApplyExcludeRule(rule, &lyrics);
|
ApplyExcludeRule(rule, &lyrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!content.isEmpty()) {
|
if (!content.isEmpty() and HTMLHasAlphaNumeric(content)) {
|
||||||
lyrics = content;
|
lyrics = content;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ void UltimateLyricsProvider::LyricsFetched() {
|
||||||
lyrics = original_content;
|
lyrics = original_content;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lyrics.isEmpty()) {
|
if (!lyrics.isEmpty() and HTMLHasAlphaNumeric(lyrics)) {
|
||||||
CollapsibleInfoPane::Data data;
|
CollapsibleInfoPane::Data data;
|
||||||
data.id_ = "ultimatelyrics/" + name_;
|
data.id_ = "ultimatelyrics/" + name_;
|
||||||
data.title_ = tr("Lyrics from %1").arg(name_);
|
data.title_ = tr("Lyrics from %1").arg(name_);
|
||||||
|
@ -317,3 +317,19 @@ QString UltimateLyricsProvider::NoSpace(const QString& text) {
|
||||||
ret.remove(' ');
|
ret.remove(' ');
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tells whether a html block has alphanumeric characters (skipping tags)
|
||||||
|
// TODO: handle special characters (e.g. ® á)
|
||||||
|
bool UltimateLyricsProvider::HTMLHasAlphaNumeric(const QString& html) {
|
||||||
|
bool in_tag = false;
|
||||||
|
foreach (const QChar& c, html) {
|
||||||
|
if (!in_tag and c.isLetterOrNumber())
|
||||||
|
return true;
|
||||||
|
else if (c == QChar('<'))
|
||||||
|
in_tag = true;
|
||||||
|
else if (c == QChar('>'))
|
||||||
|
in_tag = false;
|
||||||
|
}
|
||||||
|
qLog(Debug) << html;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ private:
|
||||||
static QString FirstChar(const QString& text);
|
static QString FirstChar(const QString& text);
|
||||||
static QString TitleCase(const QString& text);
|
static QString TitleCase(const QString& text);
|
||||||
static QString NoSpace(const QString& text);
|
static QString NoSpace(const QString& text);
|
||||||
|
static bool HTMLHasAlphaNumeric(const QString& html);
|
||||||
|
|
||||||
void ReplaceField(const QString& tag, const QString& value, QString* text) const;
|
void ReplaceField(const QString& tag, const QString& value, QString* text) const;
|
||||||
void ReplaceFields(const Song& metadata, QString* text) const;
|
void ReplaceFields(const Song& metadata, QString* text) const;
|
||||||
|
|
Loading…
Reference in New Issue