From ba16ca9a72c21df95c2f50fbeda71c3cff5a4c31 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Tue, 17 Jul 2012 10:10:00 -0400 Subject: [PATCH] Ask local resolver for playlist if running and logged in --- src/libtomahawk/utils/SpotifyParser.cpp | 44 +++++++++++++++++++++++++ src/libtomahawk/utils/SpotifyParser.h | 3 ++ 2 files changed, 47 insertions(+) diff --git a/src/libtomahawk/utils/SpotifyParser.cpp b/src/libtomahawk/utils/SpotifyParser.cpp index bab88c7d3..d873f16f1 100644 --- a/src/libtomahawk/utils/SpotifyParser.cpp +++ b/src/libtomahawk/utils/SpotifyParser.cpp @@ -98,12 +98,31 @@ SpotifyParser::lookupSpotifyBrowse( const QString& linkRaw ) { tLog() << "Parsing Spotify Browse URI:" << linkRaw; m_browseUri = linkRaw; + if ( m_browseUri.contains( "open.spotify.com/" ) ) // convert to a URI { m_browseUri.replace( "http://open.spotify.com/", "" ); m_browseUri.replace( "/", ":" ); m_browseUri = "spotify:" + m_browseUri; } + + if ( m_browseUri.contains( "playlist" ) && + Tomahawk::Accounts::SpotifyAccount::instance() != 0 && + Tomahawk::Accounts::SpotifyAccount::instance()->loggedIn() ) + { + // Do a playlist lookup locally + // Running resolver, so do the lookup through that + qDebug() << Q_FUNC_INFO << "Doing playlist lookup through spotify resolver:" << m_browseUri; + QVariantMap message; + message[ "_msgtype" ] = "playlistListing"; + message[ "id" ] = m_browseUri; + + QMetaObject::invokeMethod( Tomahawk::Accounts::SpotifyAccount::instance(), "sendMessage", Qt::QueuedConnection, Q_ARG( QVariantMap, message ), + Q_ARG( QObject*, this ), + Q_ARG( QString, "playlistListingResult" ) ); + + return; + } DropJob::DropType type; @@ -293,6 +312,31 @@ SpotifyParser::spotifyTrackLookupFinished() } +void +SpotifyParser::playlistListingResult( const QString& msgType, const QVariantMap& msg, const QVariant& extraData ) +{ + Q_ASSERT( msgType == "playlistListing" ); + + m_title = msg.value( "name" ).toString(); + m_single = false; + m_creator = msg.value( "creator" ).toString(); + + const QVariantList tracks = msg.value( "tracks" ).toList(); + foreach ( const QVariant& blob, tracks ) + { + QVariantMap trackMap = blob.toMap(); + const query_ptr q = Query::get( trackMap.value( "artist" ).toString(), trackMap.value( "track" ).toString(), trackMap.value( "album" ).toString(), uuid(), false ); + + if ( q.isNull() ) + continue; + + m_tracks << q; + } + + checkBrowseFinished(); +} + + void SpotifyParser::checkBrowseFinished() { diff --git a/src/libtomahawk/utils/SpotifyParser.h b/src/libtomahawk/utils/SpotifyParser.h index 1bde874e3..3675489ca 100644 --- a/src/libtomahawk/utils/SpotifyParser.h +++ b/src/libtomahawk/utils/SpotifyParser.h @@ -60,6 +60,9 @@ public: // the single track signal void setSingleMode( bool single ) { m_single = single; } +public slots: + void playlistListingResult( const QString& msgType, const QVariantMap& msg, const QVariant& extraData ); + signals: void track( const Tomahawk::query_ptr& track ); void tracks( const QList< Tomahawk::query_ptr > tracks );