Merge pull request #4057 from heduenas/master

Improvement on the detection of empty lyrics
This commit is contained in:
David Sansome 2014-01-03 00:06:22 -08:00
commit 8ac8b33c9d
2 changed files with 19 additions and 2 deletions

View File

@ -141,7 +141,7 @@ void UltimateLyricsProvider::LyricsFetched() {
ApplyExcludeRule(rule, &lyrics);
}
if (!content.isEmpty()) {
if (!content.isEmpty() and HTMLHasAlphaNumeric(content)) {
lyrics = content;
break;
}
@ -150,7 +150,7 @@ void UltimateLyricsProvider::LyricsFetched() {
lyrics = original_content;
}
if (!lyrics.isEmpty()) {
if (!lyrics.isEmpty() and HTMLHasAlphaNumeric(lyrics)) {
CollapsibleInfoPane::Data data;
data.id_ = "ultimatelyrics/" + name_;
data.title_ = tr("Lyrics from %1").arg(name_);
@ -317,3 +317,19 @@ QString UltimateLyricsProvider::NoSpace(const QString& text) {
ret.remove(' ');
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;
}

View File

@ -73,6 +73,7 @@ private:
static QString FirstChar(const QString& text);
static QString TitleCase(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 ReplaceFields(const Song& metadata, QString* text) const;