1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 06:07:37 +02:00

Handle multiple spotify/xspf links

This commit is contained in:
Leo Franchi
2011-10-02 21:25:03 -04:00
parent de98665b00
commit 1d54be04e0
3 changed files with 41 additions and 36 deletions

View File

@@ -371,14 +371,18 @@ DropJob::tracksFromMixedData( const QMimeData *data )
} }
void 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 ) if ( dropAction() == Default )
setDropAction( Create ); setDropAction( Create );
QFile xspfFile( QUrl::fromUserInput( fileUrl ).toLocalFile() ); foreach ( const QString& url, urls )
{
QFile xspfFile( QUrl::fromUserInput( url ).toLocalFile() );
if ( xspfFile.exists() ) if ( xspfFile.exists() )
{ {
@@ -388,37 +392,29 @@ DropJob::handleXspf( const QString& fileUrl )
} }
else else
tLog( LOGINFO ) << "Error Loading local xspf " << xspfFile.fileName(); tLog( LOGINFO ) << "Error Loading local xspf " << xspfFile.fileName();
}
} }
void 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 /// Lets allow parsing all spotify uris here, if parse server is not available
/// fallback to spotify metadata for tracks /hugo /// 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 ) if ( dropAction() == Default )
setDropAction( Create ); setDropAction( Create );
tDebug() << "Got a spotify browse uri in dropjob!" << browseUri; tDebug() << "Got a spotify browse uri in dropjob!" << urls;
SpotifyParser* spot = new SpotifyParser( browseUri, dropAction() == Create, this ); SpotifyParser* spot = new SpotifyParser( urls, dropAction() == Create, this );
spot->setSingleMode( false ); spot->setSingleMode( false );
/// This currently supports draging and dropping a spotify playlist and artist /// This currently supports draging and dropping a spotify playlist and artist
if ( dropAction() == Append ) 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<Tomahawk::query_ptr> ) ), this, SLOT( onTracksAdded( QList< Tomahawk::query_ptr > ) ) ); connect( spot, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( onTracksAdded( QList< Tomahawk::query_ptr > ) ) );
} }
@@ -429,11 +425,11 @@ void
DropJob::handleAllUrls( const QString& urls ) DropJob::handleAllUrls( const QString& urls )
{ {
if ( urls.contains( "xspf" ) ) 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 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" ) ) && ( urls.contains( "playlist" ) || urls.contains( "artist" ) || urls.contains( "album" ) || urls.contains( "track" ) )
&& s_canParseSpotifyPlaylists ) && s_canParseSpotifyPlaylists )
handleSpotifyUrl( urls ); handleSpotifyUrls( urls );
else else
handleTrackUrls ( urls ); handleTrackUrls ( urls );
} }

View File

@@ -89,8 +89,8 @@ public:
void setGetWholeArtists( bool getWholeArtists ); void setGetWholeArtists( bool getWholeArtists );
void setGetWholeAlbums( bool getWholeAlbums ); void setGetWholeAlbums( bool getWholeAlbums );
void tracksFromMimeData( const QMimeData* data, bool allowDuplicates = false, bool onlyLocal = false, bool top10 = false ); void tracksFromMimeData( const QMimeData* data, bool allowDuplicates = false, bool onlyLocal = false, bool top10 = false );
void handleXspf( const QString& file ); void handleXspfs( const QString& files );
void handleSpotifyUrl( const QString& url ); void handleSpotifyUrls( const QString& urls );
static bool canParseSpotifyPlaylists() { return s_canParseSpotifyPlaylists; } static bool canParseSpotifyPlaylists() { return s_canParseSpotifyPlaylists; }
static void setCanParseSpotifyPlaylists( bool parseable ) { s_canParseSpotifyPlaylists = parseable; } static void setCanParseSpotifyPlaylists( bool parseable ) { s_canParseSpotifyPlaylists = parseable; }

View File

@@ -88,10 +88,19 @@ SpotifyParser::lookupUrl( const QString& link )
void void
SpotifyParser::lookupSpotifyBrowse( const QString& link ) SpotifyParser::lookupSpotifyBrowse( const QString& linkRaw )
{ {
tLog() << "Parsing Spotify Browse URI:" << link; tLog() << "Parsing Spotify Browse URI:" << linkRaw;
QUrl url = QUrl( QString( SPOTIFY_PLAYLIST_API_URL "/browse/%1" ).arg( link ) ); 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(); tDebug() << "Looking up URL..." << url.toString();
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
@@ -99,13 +108,13 @@ SpotifyParser::lookupSpotifyBrowse( const QString& link )
DropJob::DropType type; DropJob::DropType type;
if ( link.contains( "spotify:user" ) ) if ( browseUri.contains( "spotify:user" ) )
type = DropJob::Playlist; type = DropJob::Playlist;
if ( link.contains( "spotify:artist" ) ) if ( browseUri.contains( "spotify:artist" ) )
type = DropJob::Artist; type = DropJob::Artist;
if ( link.contains( "spotify:album" ) ) if ( browseUri.contains( "spotify:album" ) )
type = DropJob::Album; type = DropJob::Album;
if ( link.contains( "spotify:track" ) ) if ( browseUri.contains( "spotify:track" ) )
type = DropJob::Track; type = DropJob::Track;
m_browseJob = new DropJobNotifier( pixmap(), "Spotify", type, reply ); m_browseJob = new DropJobNotifier( pixmap(), "Spotify", type, reply );