Improvement on the detection of empty lyrics

This commit is contained in:
Hugo Dueñas 2014-01-02 16:52:35 -06:00
parent 6e0014e3dc
commit db07c2a5cb
2 changed files with 22 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,22 @@ 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 has_alphanumeric = false;
for (int i = 0; i < html.size(); )
if (html[i] == QChar('<')) {
while (i < html.size() and html[i] != QChar('>'))
i ++;
} else {
if (isalnum(html[i].toAscii())) {
has_alphanumeric = true;
break;
}
i ++;
}
return has_alphanumeric;
}

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;