From 1d54be04e00a1a7796613ce241a11424cd13ee57 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sun, 2 Oct 2011 21:25:03 -0400 Subject: [PATCH] Handle multiple spotify/xspf links --- src/libtomahawk/dropjob.cpp | 50 ++++++++++++------------- src/libtomahawk/dropjob.h | 4 +- src/libtomahawk/utils/spotifyparser.cpp | 23 ++++++++---- 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/libtomahawk/dropjob.cpp b/src/libtomahawk/dropjob.cpp index b9e9b79dd..bc24408e4 100644 --- a/src/libtomahawk/dropjob.cpp +++ b/src/libtomahawk/dropjob.cpp @@ -371,54 +371,50 @@ DropJob::tracksFromMixedData( const QMimeData *data ) } void -DropJob::handleXspf( const QString& fileUrl ) +DropJob::handleXspfs( const QString& fileUrls ) { - tDebug() << Q_FUNC_INFO << "Got xspf playlist!!" << fileUrl; + tDebug() << Q_FUNC_INFO << "Got xspf playlist!!" << fileUrls; + + QStringList urls = fileUrls.split( QRegExp( "\\s+" ), QString::SkipEmptyParts ); if ( dropAction() == Default ) setDropAction( Create ); - QFile xspfFile( QUrl::fromUserInput( fileUrl ).toLocalFile() ); - - if ( xspfFile.exists() ) + foreach ( const QString& url, urls ) { - XSPFLoader* l = new XSPFLoader( true, this ); - tDebug( LOGINFO ) << "Loading local xspf " << xspfFile.fileName(); - l->load( xspfFile ); + QFile xspfFile( QUrl::fromUserInput( url ).toLocalFile() ); + + if ( xspfFile.exists() ) + { + XSPFLoader* l = new XSPFLoader( true, this ); + tDebug( LOGINFO ) << "Loading local xspf " << xspfFile.fileName(); + l->load( xspfFile ); + } + else + tLog( LOGINFO ) << "Error Loading local xspf " << xspfFile.fileName(); } - else - tLog( LOGINFO ) << "Error Loading local xspf " << xspfFile.fileName(); - - } void -DropJob::handleSpotifyUrl( const QString& url ) +DropJob::handleSpotifyUrls( const QString& urlsRaw ) { - qDebug() << "Got spotify browse uri!!" << url; + QStringList urls = urlsRaw.split( QRegExp( "\\s+" ), QString::SkipEmptyParts ); + qDebug() << "Got spotify browse uris!!" << urls; /// Lets allow parsing all spotify uris here, if parse server is not available /// fallback to spotify metadata for tracks /hugo - QString browseUri = url; - if ( url.contains( "open.spotify.com/" ) ) // convert to a URI - { - browseUri.replace( "http://open.spotify.com/", "" ); - browseUri.replace( "/", ":" ); - browseUri = "spotify:" + browseUri; - } - if ( dropAction() == Default ) setDropAction( Create ); - tDebug() << "Got a spotify browse uri in dropjob!" << browseUri; - SpotifyParser* spot = new SpotifyParser( browseUri, dropAction() == Create, this ); + tDebug() << "Got a spotify browse uri in dropjob!" << urls; + SpotifyParser* spot = new SpotifyParser( urls, dropAction() == Create, this ); spot->setSingleMode( false ); /// This currently supports draging and dropping a spotify playlist and artist if ( dropAction() == Append ) { - tDebug() << Q_FUNC_INFO << "Asking for spotify browse contents from" << browseUri; + tDebug() << Q_FUNC_INFO << "Asking for spotify browse contents from" << urls; connect( spot, SIGNAL( tracks( QList ) ), this, SLOT( onTracksAdded( QList< Tomahawk::query_ptr > ) ) ); } @@ -429,11 +425,11 @@ void DropJob::handleAllUrls( const QString& urls ) { if ( urls.contains( "xspf" ) ) - handleXspf( urls ); + handleXspfs( urls ); else if ( urls.contains( "spotify" ) /// Handle all the spotify uris on internal server, if not avail. fallback to spotify && ( urls.contains( "playlist" ) || urls.contains( "artist" ) || urls.contains( "album" ) || urls.contains( "track" ) ) && s_canParseSpotifyPlaylists ) - handleSpotifyUrl( urls ); + handleSpotifyUrls( urls ); else handleTrackUrls ( urls ); } diff --git a/src/libtomahawk/dropjob.h b/src/libtomahawk/dropjob.h index 1bca326af..e79213938 100644 --- a/src/libtomahawk/dropjob.h +++ b/src/libtomahawk/dropjob.h @@ -89,8 +89,8 @@ public: void setGetWholeArtists( bool getWholeArtists ); void setGetWholeAlbums( bool getWholeAlbums ); void tracksFromMimeData( const QMimeData* data, bool allowDuplicates = false, bool onlyLocal = false, bool top10 = false ); - void handleXspf( const QString& file ); - void handleSpotifyUrl( const QString& url ); + void handleXspfs( const QString& files ); + void handleSpotifyUrls( const QString& urls ); static bool canParseSpotifyPlaylists() { return s_canParseSpotifyPlaylists; } static void setCanParseSpotifyPlaylists( bool parseable ) { s_canParseSpotifyPlaylists = parseable; } diff --git a/src/libtomahawk/utils/spotifyparser.cpp b/src/libtomahawk/utils/spotifyparser.cpp index ba0913fee..c21fc2bde 100644 --- a/src/libtomahawk/utils/spotifyparser.cpp +++ b/src/libtomahawk/utils/spotifyparser.cpp @@ -88,10 +88,19 @@ SpotifyParser::lookupUrl( const QString& link ) void -SpotifyParser::lookupSpotifyBrowse( const QString& link ) +SpotifyParser::lookupSpotifyBrowse( const QString& linkRaw ) { - tLog() << "Parsing Spotify Browse URI:" << link; - QUrl url = QUrl( QString( SPOTIFY_PLAYLIST_API_URL "/browse/%1" ).arg( link ) ); + tLog() << "Parsing Spotify Browse URI:" << linkRaw; + QString browseUri = linkRaw; + if ( browseUri.contains( "open.spotify.com/" ) ) // convert to a URI + { + browseUri.replace( "http://open.spotify.com/", "" ); + browseUri.replace( "/", ":" ); + browseUri = "spotify:" + browseUri; + } + + + QUrl url = QUrl( QString( SPOTIFY_PLAYLIST_API_URL "/browse/%1" ).arg( browseUri ) ); tDebug() << "Looking up URL..." << url.toString(); QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); @@ -99,13 +108,13 @@ SpotifyParser::lookupSpotifyBrowse( const QString& link ) DropJob::DropType type; - if ( link.contains( "spotify:user" ) ) + if ( browseUri.contains( "spotify:user" ) ) type = DropJob::Playlist; - if ( link.contains( "spotify:artist" ) ) + if ( browseUri.contains( "spotify:artist" ) ) type = DropJob::Artist; - if ( link.contains( "spotify:album" ) ) + if ( browseUri.contains( "spotify:album" ) ) type = DropJob::Album; - if ( link.contains( "spotify:track" ) ) + if ( browseUri.contains( "spotify:track" ) ) type = DropJob::Track; m_browseJob = new DropJobNotifier( pixmap(), "Spotify", type, reply );