From f32320fd679e50863c5ff11c0415af281b415731 Mon Sep 17 00:00:00 2001 From: Casey Link Date: Sun, 4 Sep 2011 22:32:33 -0500 Subject: [PATCH] Fix detection of tracks/artists charts in lastfm --- .../infoplugins/generic/lastfmplugin.cpp | 39 ++++--------------- .../infoplugins/generic/lastfmplugin.h | 2 - 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp index 25adfe281..d4b638a80 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp @@ -403,8 +403,9 @@ LastFmPlugin::notInCacheSlot( uint requestId, QHash criteria, { case InfoChart: { - tDebug() << "LastfmPlugin: InfoChart not in cache, fetching"; + tDebug() << "LastFmPlugin: InfoChart not in cache, fetching"; QMap args; + tDebug() << "LastFmPlugin: " << "args chart_id" << criteria["chart_id"]; args["method"] = criteria["chart_id"]; args["limit"] = "100"; QNetworkReply* reply = lastfm::ws::get(args); @@ -539,8 +540,11 @@ LastFmPlugin::chartReturned() QNetworkReply* reply = qobject_cast( sender() ); QVariantMap returnedData; + const QRegExp tracks_rx( "chart\\.\\S+tracks\\S*", Qt::CaseInsensitive ); + const QRegExp artists_rx( "chart\\.\\S+artists\\S*", Qt::CaseInsensitive ); + const QString url = reply->url().toString(); - if( replyIsTracks( reply) ) { + if( url.contains( tracks_rx ) ) { QList tracks = parseTrackList( reply ); QList top_tracks; foreach( const lastfm::Track &t, tracks ) { @@ -553,7 +557,7 @@ LastFmPlugin::chartReturned() returnedData["tracks"] = QVariant::fromValue( top_tracks ); returnedData["type"] = "tracks"; - } else if( replyIsArtists( reply ) ) { + } else if( url.contains( artists_rx ) ) { QList list = lastfm::Artist::list( reply ); QStringList al; tDebug() << "LastFmPlugin:"<< "\tgot " << list.size() << " artists"; @@ -823,32 +827,3 @@ LastFmPlugin::parseTrackList( QNetworkReply * reply ) return tracks; } -bool -LastFmPlugin::replyIsTracks( QNetworkReply *reply ) -{ - try { - lastfm::XmlQuery lfm = lastfm::ws::parse(reply); - QDomElement e(lfm["tracks"]); - return !e.isNull(); - } - catch (lastfm::ws::ParseError& e) - { - qWarning() << e.what(); - return false; - } -} - -bool -LastFmPlugin::replyIsArtists( QNetworkReply *reply ) -{ - try { - lastfm::XmlQuery lfm = lastfm::ws::parse(reply); - QDomElement e(lfm["artists"]); - return !e.isNull(); - } - catch (lastfm::ws::ParseError& e) - { - qWarning() << e.what(); - return false; - } -} diff --git a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.h b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.h index 6095ffb90..071196402 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.h @@ -78,8 +78,6 @@ private: void dataError( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData ); QList parseTrackList( QNetworkReply * reply ); - bool replyIsTracks( QNetworkReply *reply ); - bool replyIsArtists( QNetworkReply *reply ); lastfm::MutableTrack m_track; lastfm::Audioscrobbler* m_scrobbler;