1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 11:20:22 +02:00

Support new spotify server-side parsing, courtesy of Hugo. Thanks!

This commit is contained in:
Leo Franchi
2011-10-02 12:18:48 -04:00
parent 6ebc103bc5
commit 56280db289
7 changed files with 185 additions and 177 deletions

View File

@@ -194,6 +194,7 @@ set( libSources
utils/shortenedlinkparser.cpp utils/shortenedlinkparser.cpp
utils/stylehelper.cpp utils/stylehelper.cpp
utils/qnr_iodevicestream.cpp utils/qnr_iodevicestream.cpp
utils/dropjobnotifier.cpp
widgets/checkdirtree.cpp widgets/checkdirtree.cpp
widgets/querylabel.cpp widgets/querylabel.cpp
@@ -413,6 +414,7 @@ set( libHeaders
utils/rdioparser.h utils/rdioparser.h
utils/shortenedlinkparser.h utils/shortenedlinkparser.h
utils/qnr_iodevicestream.h utils/qnr_iodevicestream.h
utils/dropjobnotifier.h
widgets/checkdirtree.h widgets/checkdirtree.h
widgets/querylabel.h widgets/querylabel.h

View File

@@ -116,12 +116,16 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
{ {
if ( url.contains( "itunes" ) && url.contains( "album" ) ) // YES itunes is fucked up and song links have album/ in the url. if ( url.contains( "itunes" ) && url.contains( "album" ) ) // YES itunes is fucked up and song links have album/ in the url.
return true; return true;
if ( url.contains( "spotify" ) && url.contains( "album" ) )
return true;
} }
if ( acceptedType.testFlag( Artist ) ) if ( acceptedType.testFlag( Artist ) )
{ {
if ( url.contains( "itunes" ) && url.contains( "artist" ) ) // YES itunes is fucked up and song links have album/ in the url. if ( url.contains( "itunes" ) && url.contains( "artist" ) ) // YES itunes is fucked up and song links have album/ in the url.
return true; return true;
if ( url.contains( "spotify" ) && url.contains( "artist" ) )
return true;
} }
// We whitelist t.co and bit.ly (and j.mp) since they do some link checking. Often playable (e.g. spotify..) links hide behind them, // We whitelist t.co and bit.ly (and j.mp) since they do some link checking. Often playable (e.g. spotify..) links hide behind them,
@@ -374,41 +378,46 @@ DropJob::handleXspf( const QString& fileUrl )
if ( dropAction() == Default ) if ( dropAction() == Default )
setDropAction( Create ); setDropAction( Create );
// Doing like so on *nix, dont know really how files are QFile xspfFile( QUrl::fromUserInput( fileUrl ).toLocalFile() );
// passed on others.
// TODO look in to! if ( xspfFile.exists() )
// QString newFile = fileUrl; {
// newFile.replace("file://", ""); XSPFLoader* l = new XSPFLoader( true, this );
// QFile xspfFile(newFile); tDebug( LOGINFO ) << "Loading local xspf " << xspfFile.fileName();
// XSPFLoader* l = new XSPFLoader( createNewPlaylist, this ); l->load( xspfFile );
// tDebug( LOGINFO ) << "Loading local xspf:" << newFile; }
// l->load( xspfFile ); else
tLog( LOGINFO ) << "Error Loading local xspf " << xspfFile.fileName();
} }
void void
DropJob::handleSpPlaylist( const QString& url ) DropJob::handleSpotifyUrl( const QString& url )
{ {
qDebug() << "Got spotify playlist!!" << url; qDebug() << "Got spotify browse uri!!" << url;
QString playlistUri = url; /// Lets allow parsing all spotify uris here, if parse server is not available
if ( url.contains( "open.spotify.com/user" ) ) // convert to a URI /// fallback to spotify metadata for tracks /hugo
QString browseUri = url;
if ( url.contains( "open.spotify.com/" ) ) // convert to a URI
{ {
playlistUri.replace("http://open.spotify.com/", ""); browseUri.replace( "http://open.spotify.com/", "" );
playlistUri.replace( "/", ":" ); browseUri.replace( "/", ":" );
playlistUri = "spotify:" + playlistUri; browseUri = "spotify:" + browseUri;
} }
if ( dropAction() == Default ) if ( dropAction() == Default )
setDropAction( Create ); setDropAction( Create );
tDebug() << "Got a spotify playlist uri in dropjob!" << playlistUri; tDebug() << "Got a spotify browse uri in dropjob!" << browseUri;
SpotifyParser* spot = new SpotifyParser( playlistUri, dropAction() == Create, this ); SpotifyParser* spot = new SpotifyParser( browseUri, dropAction() == Create, this );
//This currently supports draging and dropping a spotify playlist /// This currently supports draging and dropping a spotify playlist and artist
if ( dropAction() == Append ) if ( dropAction() == Append )
{ {
tDebug() << Q_FUNC_INFO << "Asking for spotify playlist contents from" << playlistUri; tDebug() << Q_FUNC_INFO << "Asking for spotify browse contents from" << browseUri;
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 > ) ) );
} }
@@ -420,8 +429,10 @@ DropJob::handleAllUrls( const QString& urls )
{ {
if ( urls.contains( "xspf" ) ) if ( urls.contains( "xspf" ) )
handleXspf( urls ); handleXspf( urls );
else if ( urls.contains( "spotify" ) && urls.contains( "playlist" ) && s_canParseSpotifyPlaylists ) else if ( urls.contains( "spotify" ) /// Handle all the spotify uris on internal server, if not avail. fallback to spotify
handleSpPlaylist( urls ); && ( urls.contains( "playlist" ) || urls.contains( "artist" ) || urls.contains( "album" ) || urls.contains( "track" ) )
&& s_canParseSpotifyPlaylists )
handleSpotifyUrl( urls );
else else
handleTrackUrls ( urls ); handleTrackUrls ( urls );
} }
@@ -430,14 +441,7 @@ DropJob::handleAllUrls( const QString& urls )
void void
DropJob::handleTrackUrls( const QString& urls ) DropJob::handleTrackUrls( const QString& urls )
{ {
// TODO REMOVE HACK if ( urls.contains( "itunes.apple.com") )
if ( urls.contains( "open.spotify.com/user") ||
urls.contains( "spotify:user" ) )
{
Q_ASSERT( false );
// handleSpPlaylist( urls, dropAction() );
}
else if ( urls.contains( "itunes.apple.com") )
{ {
QStringList tracks = urls.split( QRegExp( "\\s+" ), QString::SkipEmptyParts ); QStringList tracks = urls.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );
@@ -457,7 +461,7 @@ DropJob::handleTrackUrls( const QString& urls )
} }
else if ( urls.contains( "rdio.com" ) ) else if ( urls.contains( "rdio.com" ) )
{ {
QStringList tracks = urls.split( "\n" ); QStringList tracks = urls.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );
tDebug() << "Got a list of rdio urls!" << tracks; tDebug() << "Got a list of rdio urls!" << tracks;
RdioParser* rdio = new RdioParser( this ); RdioParser* rdio = new RdioParser( this );
@@ -470,7 +474,7 @@ DropJob::handleTrackUrls( const QString& urls )
urls.contains( "t.co" ) || urls.contains( "t.co" ) ||
urls.contains( "rd.io" ) ) urls.contains( "rd.io" ) )
{ {
QStringList tracks = urls.split( "\n" ); QStringList tracks = urls.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );
tDebug() << "Got a list of shortened urls!" << tracks; tDebug() << "Got a list of shortened urls!" << tracks;
ShortenedLinkParser* parser = new ShortenedLinkParser( tracks, this ); ShortenedLinkParser* parser = new ShortenedLinkParser( tracks, this );

View File

@@ -90,8 +90,9 @@ public:
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 handleXspf( const QString& file );
void handleSpPlaylist( const QString& url ); void handleSpotifyUrl( const QString& url );
static bool canParseSpotifyPlaylists() { return s_canParseSpotifyPlaylists; }
static void setCanParseSpotifyPlaylists( bool parseable ) { s_canParseSpotifyPlaylists = parseable; } static void setCanParseSpotifyPlaylists( bool parseable ) { s_canParseSpotifyPlaylists = parseable; }
signals: signals:
/// QMimeData parsing results /// QMimeData parsing results

View File

@@ -23,6 +23,9 @@
#include "utils/tomahawkutils.h" #include "utils/tomahawkutils.h"
#include "query.h" #include "query.h"
#include "sourcelist.h" #include "sourcelist.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include <qjson/parser.h> #include <qjson/parser.h>
#include <QtNetwork/QNetworkAccessManager> #include <QtNetwork/QNetworkAccessManager>
@@ -31,6 +34,8 @@
using namespace Tomahawk; using namespace Tomahawk;
QPixmap* ItunesParser::s_pixmap = 0;
ItunesParser::ItunesParser( const QStringList& urls, QObject* parent ) ItunesParser::ItunesParser( const QStringList& urls, QObject* parent )
: QObject ( parent ) : QObject ( parent )
, m_single( false ) , m_single( false )
@@ -41,6 +46,9 @@ ItunesParser::ItunesParser( const QStringList& urls, QObject* parent )
lookupItunesUri( url ); lookupItunesUri( url );
} }
if ( !s_pixmap )
s_pixmap = new QPixmap( );
} }
ItunesParser::ItunesParser( const QString& Url, QObject* parent ) ItunesParser::ItunesParser( const QString& Url, QObject* parent )
@@ -48,6 +56,9 @@ ItunesParser::ItunesParser( const QString& Url, QObject* parent )
, m_single( true ) , m_single( true )
{ {
lookupItunesUri( Url ); lookupItunesUri( Url );
if ( !s_pixmap )
s_pixmap = new QPixmap( RESPATH "images/itunes.png" );
} }
ItunesParser::~ItunesParser() ItunesParser::~ItunesParser()
@@ -58,7 +69,6 @@ ItunesParser::~ItunesParser()
void void
ItunesParser::lookupItunesUri( const QString& link ) ItunesParser::lookupItunesUri( const QString& link )
{ {
// Itunes uri parsing, using regex // Itunes uri parsing, using regex
// (\d+)(?:\?i=*)(\d+) = AlbumId and trackId // (\d+)(?:\?i=*)(\d+) = AlbumId and trackId
// (\d+)(?:\s*) = id // (\d+)(?:\s*) = id
@@ -69,7 +79,8 @@ ItunesParser::lookupItunesUri( const QString& link )
// Doing a parse on regex in 2 stages, // Doing a parse on regex in 2 stages,
// first, look if we have both album and track id // first, look if we have both album and track id
int pos = rxAlbumTrack.indexIn( link ); int pos = rxAlbumTrack.indexIn( link );
if ( pos > -1 ) { if ( pos > -1 )
{
id = rxAlbumTrack.cap( 1 ); id = rxAlbumTrack.cap( 1 );
trackId = rxAlbumTrack.cap( 2 ); trackId = rxAlbumTrack.cap( 2 );
} }
@@ -85,20 +96,27 @@ ItunesParser::lookupItunesUri( const QString& link )
return; return;
} }
qDebug() << "Got Itunes link with id " << id << "and trackid" <<trackId;
tLog() << "Parsing itunes track:" << link; tLog() << "Parsing itunes track:" << link;
QUrl url; QUrl url;
DropJob::DropType type;
if( link.contains( "artist" ) ) if( link.contains( "artist" ) )
{
type = DropJob::Artist;
url = QUrl( QString( "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsLookup?id=%1&entity=song&limit=30" ).arg( id ) ); url = QUrl( QString( "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsLookup?id=%1&entity=song&limit=30" ).arg( id ) );
else }else
{
type = ( trackId.isEmpty() ? DropJob::Album : DropJob::Track );
url = QUrl( QString( "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsLookup?id=%1&entity=song" ).arg( ( trackId.isEmpty() ? id : trackId ) ) ); url = QUrl( QString( "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsLookup?id=%1&entity=song" ).arg( ( trackId.isEmpty() ? id : trackId ) ) );
}
qDebug() << "Looking up..." << url.toString(); qDebug() << "Looking up..." << url.toString();
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
connect( reply, SIGNAL( finished() ), this, SLOT( itunesResponseLookupFinished() ) ); connect( reply, SIGNAL( finished() ), this, SLOT( itunesResponseLookupFinished() ) );
DropJobNotifier* j = new DropJobNotifier( *s_pixmap, QString( "Itunes" ), type, reply );
JobStatusView::instance()->model()->addJob( j );
m_queries.insert( reply ); m_queries.insert( reply );
} }

View File

@@ -24,6 +24,7 @@
#include "dllmacro.h" #include "dllmacro.h"
#include "typedefs.h" #include "typedefs.h"
#include "query.h" #include "query.h"
#include "dropjobnotifier.h"
#include <QObject> #include <QObject>
#include <QSet> #include <QSet>
@@ -64,6 +65,9 @@ private:
QSet< QNetworkReply* > m_queries; QSet< QNetworkReply* > m_queries;
QString m_title, m_info, m_creator; QString m_title, m_info, m_creator;
Tomahawk::playlist_ptr m_playlist; Tomahawk::playlist_ptr m_playlist;
DropJobNotifier* m_browseJob;
static QPixmap* s_pixmap;
}; };
} }

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org> * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2011, Hugo Lindström <hugolm84@gmail.com>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -22,6 +23,7 @@
#include "utils/tomahawkutils.h" #include "utils/tomahawkutils.h"
#include "query.h" #include "query.h"
#include "sourcelist.h" #include "sourcelist.h"
#include "dropjob.h"
#include "jobview/JobStatusView.h" #include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h" #include "jobview/JobStatusModel.h"
@@ -29,62 +31,18 @@
#include <QtNetwork/QNetworkAccessManager> #include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply> #include <QtNetwork/QNetworkReply>
#include "dropjobnotifier.h"
using namespace Tomahawk; using namespace Tomahawk;
QPixmap* SpotifyParser::s_pixmap = 0; QPixmap* SpotifyParser::s_pixmap = 0;
SpotifyJobNotifier::SpotifyJobNotifier( QNetworkReply* job )
: JobStatusItem()
, m_type( "track" )
, m_job( job )
{
connect( job, SIGNAL( finished() ), this, SLOT( setFinished()) );
}
SpotifyJobNotifier::SpotifyJobNotifier()
: JobStatusItem()
, m_type( "playlist" )
, m_job( 0 )
{
}
SpotifyJobNotifier::~SpotifyJobNotifier()
{}
QString
SpotifyJobNotifier::rightColumnText() const
{
return QString();
}
QPixmap
SpotifyJobNotifier::icon() const
{
return SpotifyParser::pixmap();
}
QString
SpotifyJobNotifier::mainText() const
{
return tr( "Parsing Spotify %1" ).arg( m_type );
}
void
SpotifyJobNotifier::setFinished()
{
emit finished();
}
SpotifyParser::SpotifyParser( const QStringList& Urls, bool createNewPlaylist, QObject* parent ) SpotifyParser::SpotifyParser( const QStringList& Urls, bool createNewPlaylist, QObject* parent )
: QObject ( parent ) : QObject ( parent )
, m_single( false ) , m_single( false )
, m_trackMode( true ) , m_trackMode( true )
, m_createNewPlaylist( createNewPlaylist ) , m_createNewPlaylist( createNewPlaylist )
, m_playlistJob( 0 ) , m_browseJob( 0 )
{ {
foreach ( const QString& url, Urls ) foreach ( const QString& url, Urls )
@@ -96,7 +54,7 @@ SpotifyParser::SpotifyParser( const QString& Url, bool createNewPlaylist, QObjec
, m_single( true ) , m_single( true )
, m_trackMode( true ) , m_trackMode( true )
, m_createNewPlaylist( createNewPlaylist ) , m_createNewPlaylist( createNewPlaylist )
, m_playlistJob( 0 ) , m_browseJob( 0 )
{ {
lookupUrl( Url ); lookupUrl( Url );
} }
@@ -114,32 +72,44 @@ SpotifyParser::lookupUrl( const QString& link )
m_trackMode = true; m_trackMode = true;
lookupTrack( link ); lookupTrack( link );
} }
else if( link.contains( "playlist" ) ) else if( link.contains( "playlist" ) || link.contains( "album" ) || link.contains( "artist" ) )
{ {
if( !m_createNewPlaylist )
m_trackMode = true;
else
m_trackMode = false; m_trackMode = false;
lookupPlaylist( link );
lookupSpotifyBrowse( link );
} }
else else
return; // We only support tracks and playlists return; // Not valid spotify item
} }
void void
SpotifyParser::lookupPlaylist( const QString& link ) SpotifyParser::lookupSpotifyBrowse( const QString& link )
{ {
if ( !link.contains( "spotify:user:" ) ) // we only support playlist here tLog() << "Parsing Spotify Browse URI:" << link;
return; QUrl url = QUrl( QString( SPOTIFY_PLAYLIST_API_URL "/browse/%1" ).arg( link ) );
tLog() << "Parsing Spotify Playlist URI:" << link;
QUrl url = QUrl( QString( SPOTIFY_PLAYLIST_API_URL "/playlist/%1" ).arg( link ) );
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 ) );
connect( reply, SIGNAL( finished() ), this, SLOT( spotifyPlaylistLookupFinished() ) ); connect( reply, SIGNAL( finished() ), this, SLOT( spotifyBrowseFinished() ) );
m_playlistJob = new SpotifyJobNotifier(); DropJob::DropType type;
JobStatusView::instance()->model()->addJob( m_playlistJob );
if ( link.contains( "spotify:user" ) )
type = DropJob::Playlist;
if ( link.contains( "spotify:artist" ) )
type = DropJob::Artist;
if ( link.contains( "spotify:album" ) )
type = DropJob::Album;
if ( link.contains( "spotify:track" ) )
type = DropJob::Track;
m_browseJob = new DropJobNotifier( pixmap(), QString( "Spotify" ).arg( (int)type ), type, reply );
JobStatusView::instance()->model()->addJob( m_browseJob );
m_queries.insert( reply ); m_queries.insert( reply );
} }
@@ -147,7 +117,6 @@ SpotifyParser::lookupPlaylist( const QString& link )
void void
SpotifyParser::lookupTrack( const QString& link ) SpotifyParser::lookupTrack( const QString& link )
{ {
tDebug() << "Got a QString " << link; tDebug() << "Got a QString " << link;
if ( !link.contains( "track" )) // we only support track links atm if ( !link.contains( "track" )) // we only support track links atm
return; return;
@@ -162,12 +131,12 @@ SpotifyParser::lookupTrack( const QString& link )
} }
QUrl url = QUrl( QString( "http://ws.spotify.com/lookup/1/.json?uri=%1" ).arg( uri ) ); QUrl url = QUrl( QString( "http://ws.spotify.com/lookup/1/.json?uri=%1" ).arg( uri ) );
tLog() << "Looking up spotify track information..." << url.toString(); tDebug() << "Looking up URL..." << url.toString();
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
connect( reply, SIGNAL( finished() ), this, SLOT( spotifyTrackLookupFinished() ) ); connect( reply, SIGNAL( finished() ), this, SLOT( spotifyTrackLookupFinished() ) );
SpotifyJobNotifier* j = new SpotifyJobNotifier( reply ); DropJobNotifier* j = new DropJobNotifier( pixmap(), QString( "Spotify" ), DropJob::Track, reply );
JobStatusView::instance()->model()->addJob( j ); JobStatusView::instance()->model()->addJob( j );
m_queries.insert( reply ); m_queries.insert( reply );
@@ -176,7 +145,7 @@ SpotifyParser::lookupTrack( const QString& link )
void void
SpotifyParser::spotifyPlaylistLookupFinished() SpotifyParser::spotifyBrowseFinished()
{ {
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() ); QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() );
Q_ASSERT( r ); Q_ASSERT( r );
@@ -192,28 +161,50 @@ SpotifyParser::spotifyPlaylistLookupFinished()
if ( !ok ) if ( !ok )
{ {
tLog() << "Failed to parse json from Spotify playlist lookup:" << p.errorString() << "On line" << p.errorLine(); tLog() << "Failed to parse json from Spotify browse item :" << p.errorString() << "On line" << p.errorLine();
checkTrackFinished(); checkTrackFinished();
return; return;
} }
else if ( !res.contains( "tracks" ) ) else if ( res.contains( "trackCount" ) && res.value( "trackCount" ).toInt() < 0 )
{ {
tLog() << "No tracks' item in the spotify playlist lookup result... not doing anything"; tLog() << "No tracks' item in the spotify browse result... not doing anything";
checkTrackFinished(); checkTrackFinished();
return; return;
} }
QVariantList trackResponse = res.value( "tracks" ).toList(); QVariantMap resultResponse = res.value( res.value( "type" ).toString() ).toMap();
if ( !trackResponse.isEmpty() )
if ( !resultResponse.isEmpty() )
{ {
m_title = res.value( "title" ).toString();
m_creator = res.value( "creator" ).toString(); m_title = resultResponse.value( "name" ).toString();
qDebug() << "playlist owner: " << m_creator; m_single = false;
if ( res.value( "type" ).toString() == "playlist" )
m_creator = resultResponse.value( "creator" ).toString();
// TODO for now only take the first artist
foreach ( QVariant result, resultResponse.value( "result" ).toList() )
{
QVariantMap trackResult = result.toMap();
QString title, artist, album;
title = trackResult.value( "title", QString() ).toString();
artist = trackResult.value( "artist", QString() ).toString();
album = trackResult.value( "album", QString() ).toString();
if ( title.isEmpty() && artist.isEmpty() ) // don't have enough...
{
tLog() << "Didn't get an artist and track name from spotify, not enough to build a query on. Aborting" << title << artist << album;
return;
}
Tomahawk::query_ptr q = Tomahawk::Query::get( artist, title, album, uuid(), m_trackMode );
m_tracks << q;
} }
foreach( QVariant track, trackResponse )
{
lookupTrack( track.toString() );
} }
} else } else
@@ -221,7 +212,10 @@ SpotifyParser::spotifyPlaylistLookupFinished()
tLog() << "Error in network request to Spotify for track decoding:" << r->errorString(); tLog() << "Error in network request to Spotify for track decoding:" << r->errorString();
} }
checkPlaylistFinished(); if ( m_trackMode )
checkTrackFinished();
else
checkBrowseFinished();
} }
@@ -272,7 +266,6 @@ SpotifyParser::spotifyTrackLookupFinished()
Tomahawk::query_ptr q = Tomahawk::Query::get( artist, title, album, uuid(), m_trackMode ); Tomahawk::query_ptr q = Tomahawk::Query::get( artist, title, album, uuid(), m_trackMode );
m_tracks << q; m_tracks << q;
} else } else
{ {
tLog() << "Error in network request to Spotify for track decoding:" << r->errorString(); tLog() << "Error in network request to Spotify for track decoding:" << r->errorString();
@@ -281,18 +274,20 @@ SpotifyParser::spotifyTrackLookupFinished()
if ( m_trackMode ) if ( m_trackMode )
checkTrackFinished(); checkTrackFinished();
else else
checkPlaylistFinished(); checkBrowseFinished();
} }
void void
SpotifyParser::checkPlaylistFinished() SpotifyParser::checkBrowseFinished()
{ {
tDebug() << "Checking for spotify batch playlist job finished" << m_queries.isEmpty() << m_createNewPlaylist; tDebug() << "Checking for spotify batch playlist job finished" << m_queries.isEmpty() << m_createNewPlaylist;
if ( m_queries.isEmpty() ) // we're done if ( m_queries.isEmpty() ) // we're done
{ {
if ( m_playlistJob ) if ( m_browseJob )
m_playlistJob->setFinished(); m_browseJob->setFinished();
if( m_createNewPlaylist )
if( m_createNewPlaylist && !m_tracks.isEmpty() )
m_playlist = Playlist::create( SourceList::instance()->getLocal(), m_playlist = Playlist::create( SourceList::instance()->getLocal(),
uuid(), uuid(),
m_title, m_title,
@@ -301,12 +296,13 @@ SpotifyParser::checkPlaylistFinished()
false, false,
m_tracks ); m_tracks );
else if ( !m_tracks.isEmpty() && !m_createNewPlaylist) else if ( m_single && !m_tracks.isEmpty() )
emit track( m_tracks.first() );
else if ( !m_single && !m_tracks.isEmpty() )
emit tracks( m_tracks ); emit tracks( m_tracks );
deleteLater(); deleteLater();
} }
} }
void void
@@ -315,6 +311,9 @@ SpotifyParser::checkTrackFinished()
tDebug() << "Checking for spotify batch track job finished" << m_queries.isEmpty(); tDebug() << "Checking for spotify batch track job finished" << m_queries.isEmpty();
if ( m_queries.isEmpty() ) // we're done if ( m_queries.isEmpty() ) // we're done
{ {
if ( m_browseJob )
m_browseJob->setFinished();
if ( m_single && !m_tracks.isEmpty() ) if ( m_single && !m_tracks.isEmpty() )
emit track( m_tracks.first() ); emit track( m_tracks.first() );
else if ( !m_single && !m_tracks.isEmpty() ) else if ( !m_single && !m_tracks.isEmpty() )
@@ -326,7 +325,7 @@ SpotifyParser::checkTrackFinished()
} }
QPixmap QPixmap
SpotifyParser::pixmap() SpotifyParser::pixmap() const
{ {
if ( !s_pixmap ) if ( !s_pixmap )
s_pixmap = new QPixmap( RESPATH "images/spotify-logo.png" ); s_pixmap = new QPixmap( RESPATH "images/spotify-logo.png" );

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org> * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2011, Hugo Lindström <hugolm84@gmail.com>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -30,40 +31,18 @@
#define SPOTIFY_PLAYLIST_API_URL "http://spotikea.tomahawk-player.org:10380" #define SPOTIFY_PLAYLIST_API_URL "http://spotikea.tomahawk-player.org:10380"
class QNetworkReply;
namespace Tomahawk
{
class DLLEXPORT SpotifyJobNotifier : public JobStatusItem
{
Q_OBJECT
public:
// track
SpotifyJobNotifier( QNetworkReply* job );
// playlist
SpotifyJobNotifier();
virtual ~SpotifyJobNotifier();
virtual QString rightColumnText() const;
virtual QString mainText() const;
virtual QPixmap icon() const;
virtual QString type() const { return m_type; }
virtual bool collapseItem() const { return true; }
public slots:
void setFinished();
private:
QString m_type;
QNetworkReply* m_job;
};
/** /**
* Small class to parse spotify links into query_ptrs * Small class to parse spotify links into query_ptrs
* *
* Connect to the signals to get the results * Connect to the signals to get the results
*/ */
class QNetworkReply;
namespace Tomahawk
{
class DropJobNotifier;
class DLLEXPORT SpotifyParser : public QObject class DLLEXPORT SpotifyParser : public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -73,6 +52,7 @@ public:
explicit SpotifyParser( const QStringList& trackUrls, bool createNewPlaylist = false, QObject* parent = 0 ); explicit SpotifyParser( const QStringList& trackUrls, bool createNewPlaylist = false, QObject* parent = 0 );
virtual ~SpotifyParser(); virtual ~SpotifyParser();
signals: signals:
void track( const Tomahawk::query_ptr& track ); void track( const Tomahawk::query_ptr& track );
void tracks( const QList< Tomahawk::query_ptr > tracks ); void tracks( const QList< Tomahawk::query_ptr > tracks );
@@ -80,16 +60,16 @@ signals:
private slots: private slots:
void spotifyTrackLookupFinished(); void spotifyTrackLookupFinished();
void spotifyPlaylistLookupFinished(); void spotifyBrowseFinished();
private: private:
static QPixmap pixmap(); QPixmap pixmap() const;
void lookupUrl( const QString& url ); void lookupUrl( const QString& url );
void lookupTrack( const QString& track ); void lookupTrack( const QString& track );
void lookupPlaylist( const QString& playlist ); void lookupSpotifyBrowse( const QString& playlist );
void checkTrackFinished(); void checkTrackFinished();
void checkPlaylistFinished(); void checkBrowseFinished();
bool m_single; bool m_single;
bool m_trackMode; bool m_trackMode;
@@ -98,7 +78,7 @@ private:
QSet< QNetworkReply* > m_queries; QSet< QNetworkReply* > m_queries;
QString m_title, m_info, m_creator; QString m_title, m_info, m_creator;
Tomahawk::playlist_ptr m_playlist; Tomahawk::playlist_ptr m_playlist;
SpotifyJobNotifier* m_playlistJob; DropJobNotifier* m_browseJob;
static QPixmap* s_pixmap; static QPixmap* s_pixmap;
}; };