1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

Support SC user favorites

This commit is contained in:
Hugo Lindström 2012-12-21 01:32:51 +01:00
parent 4cf4b995af
commit 47956a1bde
2 changed files with 52 additions and 4 deletions

View File

@ -43,6 +43,7 @@ SoundcloudParser::SoundcloudParser( const QStringList& Urls, bool createNewPlayl
, m_createNewPlaylist( createNewPlaylist )
, m_browseJob( 0 )
, m_type( DropJob::All )
, m_getLikes( false )
{
foreach ( const QString& url, Urls )
@ -57,6 +58,7 @@ SoundcloudParser::SoundcloudParser( const QString& Url, bool createNewPlaylist,
, m_createNewPlaylist( createNewPlaylist )
, m_browseJob( 0 )
, m_type( DropJob::All )
, m_getLikes( false )
{
lookupUrl( Url );
}
@ -71,8 +73,14 @@ void
SoundcloudParser::lookupUrl( const QString& link )
{
tDebug() << "Looking up URL..." << link;
QUrl scLink( QString( "http://api.soundcloud.com/resolve.json?client_id=TiNg2DRYhBnp01DA3zNag&url=" ) + link );
QString url = link;
if ( link.contains( "/likes" ) )
{
qDebug() << Q_FUNC_INFO << "Requesting likes";
url.replace( "/likes", "" );
m_getLikes = true;
}
QUrl scLink( QString( "http://api.soundcloud.com/resolve.json?client_id=TiNg2DRYhBnp01DA3zNag&url=" ) + url );
NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( scLink ) ) );
connect( reply, SIGNAL( finished() ), SLOT( soundcloudLookupFinished() ) );
@ -90,6 +98,7 @@ SoundcloudParser::parseTrack( const QVariantMap& res )
QString title, artist;
title = res.value( "title", QString() ).toString();
artist = res.value( "user" ).toMap().value( "username", QString() ).toString();
bool streamable = res.value( "streamable" ).toBool();
if ( title.isEmpty() && artist.isEmpty() ) // don't have enough...
{
@ -97,6 +106,14 @@ SoundcloudParser::parseTrack( const QVariantMap& res )
return;
}
if ( !streamable )
{
JobStatusView::instance()->model()->addJob(
new ErrorStatusMessage( tr( "Track '%1' by %2 is not streamable." ).arg( title ).arg( artist ), 5 ) );
tLog() << "Track is not streamble, aborting." << res.value( "uri" ).toString();
return;
}
Tomahawk::query_ptr q = Tomahawk::Query::get( artist, title, QString(), uuid(), m_trackMode );
if ( !q.isNull() )
@ -136,9 +153,21 @@ SoundcloudParser::soundcloudLookupFinished()
m_type = DropJob::Track;
if( res.value( "kind" ).toString() == "user" )
{
QUrl url = QUrl( QString( res.value( "uri" ).toString() + "/tracks.json?client_id=TiNg2DRYhBnp01DA3zNag" ) );
qDebug() << Q_FUNC_INFO << url;
QUrl url;
if ( m_getLikes )
{
url = QUrl( QString( res.value( "uri" ).toString() + "/favorites.json?client_id=TiNg2DRYhBnp01DA3zNag" ) );
}
else
{
url = QUrl( QString( res.value( "uri" ).toString() + "/tracks.json?client_id=TiNg2DRYhBnp01DA3zNag" ) );
}
NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( QUrl( url ) ) ) );
if ( m_createNewPlaylist )
m_userData = res;
connect( reply, SIGNAL( finished() ), SLOT( soundcloudArtistLookupFinished() ) );
return;
}
@ -206,9 +235,26 @@ SoundcloudParser::soundcloudArtistLookupFinished()
QJson::Parser p;
bool ok;
QVariantList res = p.parse( r->reply(), &ok ).toList();
foreach( const QVariant& track, res )
parseTrack( track.toMap() );
if ( m_createNewPlaylist )
{
const QString user = m_userData.value( "full_name" ).toString();
const QString title = user + "'s " + ( m_getLikes ? "Favorites" : "Tracks" );
m_playlist = Playlist::create( SourceList::instance()->getLocal(),
uuid(),
title,
"",
user,
false,
m_tracks );
connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistCreated() ) );
return;
}
if ( m_single && !m_tracks.isEmpty() )
emit track( m_tracks.first() );
else if ( !m_single && !m_tracks.isEmpty() )

View File

@ -79,6 +79,8 @@ private:
int m_subscribers;
QList< query_ptr > m_tracks;
QVariantMap m_userData;
bool m_getLikes;
QSet< NetworkReply* > m_queries;
Tomahawk::playlist_ptr m_playlist;
DropJobNotifier* m_browseJob;