mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 06:07:37 +02:00
Implement chart.TopArtists in the lastfm plugin
This commit is contained in:
@@ -47,7 +47,7 @@ LastFmPlugin::LastFmPlugin()
|
|||||||
: InfoPlugin()
|
: InfoPlugin()
|
||||||
, m_scrobbler( 0 )
|
, m_scrobbler( 0 )
|
||||||
{
|
{
|
||||||
m_supportedGetTypes << InfoAlbumCoverArt << InfoArtistImages << InfoArtistSimilars << InfoArtistSongs;
|
m_supportedGetTypes << InfoAlbumCoverArt << InfoArtistImages << InfoArtistSimilars << InfoArtistSongs << InfoChartArtists;
|
||||||
m_supportedPushTypes << InfoSubmitScrobble << InfoSubmitNowPlaying << InfoLove << InfoUnLove;
|
m_supportedPushTypes << InfoSubmitScrobble << InfoSubmitNowPlaying << InfoLove << InfoUnLove;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -147,6 +147,10 @@ LastFmPlugin::getInfo( uint requestId, Tomahawk::InfoSystem::InfoRequestData req
|
|||||||
fetchTopTracks( requestId, requestData );
|
fetchTopTracks( requestId, requestData );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case InfoChartArtists:
|
||||||
|
fetchChartArtists( requestId, requestData );
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
dataError( requestId, requestData );
|
dataError( requestId, requestData );
|
||||||
}
|
}
|
||||||
@@ -298,6 +302,24 @@ LastFmPlugin::fetchTopTracks( uint requestId, Tomahawk::InfoSystem::InfoRequestD
|
|||||||
emit getCachedInfo( requestId, criteria, 2419200000, requestData );
|
emit getCachedInfo( requestId, criteria, 2419200000, requestData );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LastFmPlugin::fetchChartArtists( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData )
|
||||||
|
{
|
||||||
|
if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() )
|
||||||
|
{
|
||||||
|
dataError( requestId, requestData );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
InfoCriteriaHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
|
||||||
|
Tomahawk::InfoSystem::InfoCriteriaHash criteria;
|
||||||
|
if ( hash.contains( "country" ) )
|
||||||
|
{
|
||||||
|
criteria["country"] = hash["country"];
|
||||||
|
}
|
||||||
|
|
||||||
|
emit getCachedInfo( requestId, criteria, 2419200000, requestData );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LastFmPlugin::fetchCoverArt( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData )
|
LastFmPlugin::fetchCoverArt( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData )
|
||||||
@@ -356,6 +378,25 @@ LastFmPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria,
|
|||||||
|
|
||||||
switch ( requestData.type )
|
switch ( requestData.type )
|
||||||
{
|
{
|
||||||
|
case InfoChartArtists:
|
||||||
|
{
|
||||||
|
tDebug() << "LastfmPlugin: InfoChartArtists notin cache, fetching";
|
||||||
|
QMap<QString, QString> args;
|
||||||
|
if( criteria.contains( "country" ) ) {
|
||||||
|
args["method"] = "geo.getTopArtists";
|
||||||
|
args["country"] = criteria["country"];
|
||||||
|
} else {
|
||||||
|
args["method"] = "chart.getTopArtists";
|
||||||
|
}
|
||||||
|
args["limit"] = "100";
|
||||||
|
QNetworkReply* reply = lastfm::ws::get(args);
|
||||||
|
reply->setProperty( "requestId", requestId );
|
||||||
|
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
||||||
|
|
||||||
|
connect( reply, SIGNAL( finished() ), SLOT( chartTopArtistsReturned() ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
case InfoArtistSimilars:
|
case InfoArtistSimilars:
|
||||||
{
|
{
|
||||||
lastfm::Artist a( criteria["artist"] );
|
lastfm::Artist a( criteria["artist"] );
|
||||||
@@ -447,6 +488,36 @@ LastFmPlugin::similarArtistsReturned()
|
|||||||
emit updateCache( criteria, 2419200000, requestData.type, returnedData );
|
emit updateCache( criteria, 2419200000, requestData.type, returnedData );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LastFmPlugin::chartTopArtistsReturned()
|
||||||
|
{
|
||||||
|
tDebug() << "LastfmPlugin: InfoChartArtists data returned!";
|
||||||
|
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
|
||||||
|
QList<lastfm::Artist> list = lastfm::Artist::list( reply );
|
||||||
|
QStringList al;
|
||||||
|
|
||||||
|
tDebug() << "\tgot " << list.size() << " artists";
|
||||||
|
|
||||||
|
foreach ( const lastfm::Artist& a, list )
|
||||||
|
al << a.toString();
|
||||||
|
|
||||||
|
QVariantMap returnedData;
|
||||||
|
returnedData["artists"] = al;
|
||||||
|
|
||||||
|
Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();
|
||||||
|
|
||||||
|
emit info(
|
||||||
|
reply->property( "requestId" ).toUInt(),
|
||||||
|
requestData,
|
||||||
|
returnedData
|
||||||
|
);
|
||||||
|
|
||||||
|
Tomahawk::InfoSystem::InfoCriteriaHash origData = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash>();
|
||||||
|
Tomahawk::InfoSystem::InfoCriteriaHash criteria;
|
||||||
|
if( origData.contains("country") )
|
||||||
|
criteria["country"] = origData["country"];
|
||||||
|
emit updateCache( criteria, 2419200000, requestData.type, returnedData );
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LastFmPlugin::topTracksReturned()
|
LastFmPlugin::topTracksReturned()
|
||||||
|
@@ -52,6 +52,7 @@ public slots:
|
|||||||
void artistImagesReturned();
|
void artistImagesReturned();
|
||||||
void similarArtistsReturned();
|
void similarArtistsReturned();
|
||||||
void topTracksReturned();
|
void topTracksReturned();
|
||||||
|
void chartTopArtistsReturned();
|
||||||
|
|
||||||
void namChangedSlot( QNetworkAccessManager *nam );
|
void namChangedSlot( QNetworkAccessManager *nam );
|
||||||
|
|
||||||
@@ -66,6 +67,7 @@ private:
|
|||||||
void fetchArtistImages( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
|
void fetchArtistImages( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
|
||||||
void fetchSimilarArtists( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
|
void fetchSimilarArtists( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
|
||||||
void fetchTopTracks( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
|
void fetchTopTracks( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
|
||||||
|
void fetchChartArtists( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
|
||||||
|
|
||||||
void createScrobbler();
|
void createScrobbler();
|
||||||
void nowPlaying( const QVariant &input );
|
void nowPlaying( const QVariant &input );
|
||||||
|
Reference in New Issue
Block a user