void UltimateLyricsProvider::lyricsFetched() { NetworkJob *reply = qobject_cast<NetworkJob*>(sender()); if (!reply) { return; } int id = requests.take(reply); reply->deleteLater(); Song song=songs.take(id); if (!reply->ok()) { //emit Finished(id); emit lyricsReady(id, QString()); return; } const QTextCodec *codec = QTextCodec::codecForName(charset.toLatin1().constData()); const QString originalContent = codec->toUnicode(reply->readAll()).replace("<br />", "<br/>"); DBUG << name << "response" << originalContent; // Check for invalid indicators for (const QString &indicator: invalidIndicators) { if (originalContent.contains(indicator)) { //emit Finished(id); DBUG << name << "invalid"; emit lyricsReady(id, QString()); return; } } QString lyrics; // Apply extract rules for (const Rule& rule: extractRules) { QString content = originalContent; applyExtractRule(rule, content, song); #ifndef Q_OS_WIN content.replace(QLatin1String("\r"), QLatin1String("")); #endif content=content.trimmed(); if (!content.isEmpty()) { lyrics = content; break; } } // Apply exclude rules for (const Rule& rule: excludeRules) { applyExcludeRule(rule, lyrics, song); } lyrics=lyrics.trimmed(); lyrics.replace("<br/>\n", "<br/>"); lyrics.replace("<br>\n", "<br/>"); DBUG << name << (lyrics.isEmpty() ? "empty" : "succeeded"); emit lyricsReady(id, lyrics); }
void UltimateLyricsProvider::wikiMediaLyricsFetched() { NetworkJob *reply = qobject_cast<NetworkJob*>(sender()); if (!reply) { return; } int id = requests.take(reply); reply->deleteLater(); if (!reply->ok()) { emit lyricsReady(id, QString()); return; } const QTextCodec *codec = QTextCodec::codecForName(charset.toLatin1().constData()); QString contents = codec->toUnicode(reply->readAll()).replace("<br />", "<br/>"); DBUG << name << "response" << contents; emit lyricsReady(id, extract(contents, QLatin1String("<lyrics>"), QLatin1String("</lyrics>"))); }
void ArtistView::handleSimilarReply() { NetworkJob *reply = qobject_cast<NetworkJob*>(sender()); if (!reply) { return; } if (reply==currentSimilarJob) { if (reply->ok()) { QByteArray data=reply->readAll(); QStringList artists=parseSimilarResponse(data); if (!artists.isEmpty()) { buildSimilar(artists); setBio(); QFile f(cacheFileName(reply->property(constNameKey).toString(), QString(), true, true)); if (f.open(QIODevice::WriteOnly|QIODevice::Text)) { QTextStream stream(&f); foreach (const QString &artist, artists) { stream << artist << endl; } } }
void UltimateLyricsProvider::wikiMediaSearchResponse() { NetworkJob *reply = qobject_cast<NetworkJob*>(sender()); if (!reply) { return; } int id = requests.take(reply); reply->deleteLater(); if (!reply->ok()) { emit lyricsReady(id, QString()); return; } QUrl url; QXmlStreamReader doc(reply->actualJob()); while (!doc.atEnd()) { doc.readNext(); if (doc.isStartElement() && QLatin1String("url")==doc.name()) { QString lyricsUrl=doc.readElementText(); if (!lyricsUrl.contains(QLatin1String("action=edit"))) { url=QUrl::fromEncoded(lyricsUrl.toUtf8()).toString(); } break; } } if (url.isValid()) { QString path=url.path(); QByteArray u=url.scheme().toLatin1()+"://"+url.host().toLatin1()+"/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles="; QByteArray titles=QUrl::toPercentEncoding(path.startsWith(QLatin1Char('/')) ? path.mid(1) : path).replace('+', "%2b"); NetworkJob *reply = NetworkAccessManager::self()->get(QUrl::fromEncoded(u+titles)); requests[reply] = id; connect(reply, SIGNAL(finished()), this, SLOT(wikiMediaLyricsFetched())); } else { emit lyricsReady(id, QString()); } }