1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 21:57:41 +02:00

Adding Rdio and WeAreHunted to charts

This commit is contained in:
Hugo Lindström
2011-11-02 14:29:34 +01:00
parent 8ebbb55842
commit a98f6db089

View File

@@ -49,7 +49,7 @@ ChartsPlugin::ChartsPlugin()
/// Add resources here /// Add resources here
m_chartResources << "billboard" << "itunes"; m_chartResources << "billboard" << "itunes" << "rdio" << "wearehunted";
m_supportedGetTypes << InfoChart << InfoChartCapabilities; m_supportedGetTypes << InfoChart << InfoChartCapabilities;
} }
@@ -275,14 +275,19 @@ ChartsPlugin::chartTypes()
QVariantMap charts; QVariantMap charts;
QString chartName; QString chartName;
QStringList defaultChain; QStringList defaultChain;
if ( source == "itunes" ) if ( source == "wearehunted" || source == "itunes" )
{ {
// Some charts can have an extra param, itunes has geo, WAH has emerging/mainstream
// Itunes has geographic-area based charts. So we build a breadcrumb of // Itunes has geographic-area based charts. So we build a breadcrumb of
// ITunes - Country - Albums - Top Chart Type // ITunes - Country - Albums - Top Chart Type
// - Tracks - Top Chart Type // - Tracks - Top Chart Type
QHash< QString, QVariantMap > countries; // WeAreHunted has Mainstream/Emerging
// WeAreHunted - Type - Artists - Chart Type
// - Tracks - Chart Type
QHash< QString, QVariantMap > extraType;
foreach( const QVariant& chartObj, chartObjs.values() ) foreach( const QVariant& chartObj, chartObjs.values() )
{ {
if( !chartObj.toMap().isEmpty() ){
const QVariantMap chart = chartObj.toMap(); const QVariantMap chart = chartObj.toMap();
const QString id = chart.value( "id" ).toString(); const QString id = chart.value( "id" ).toString();
const QString geo = chart.value( "geo" ).toString(); const QString geo = chart.value( "geo" ).toString();
@@ -290,26 +295,29 @@ ChartsPlugin::chartTypes()
const QString type = chart.value( "type" ).toString(); const QString type = chart.value( "type" ).toString();
const bool isDefault = ( chart.contains( "default" ) && chart[ "default" ].toInt() == 1 ); const bool isDefault = ( chart.contains( "default" ) && chart[ "default" ].toInt() == 1 );
QString country; QString extra;
if( !geo.isEmpty() ){
if ( !m_cachedCountries.contains( geo ) ) if ( !m_cachedCountries.contains( geo ) )
{ {
QLocale l( QString( "en_%1" ).arg( geo ) ); QLocale l( QString( "en_%1" ).arg( geo ) );
country = Tomahawk::CountryUtils::fullCountryFromCode( geo ); extra = Tomahawk::CountryUtils::fullCountryFromCode( geo );
for ( int i = 1; i < country.size(); i++ ) for ( int i = 1; i < extra.size(); i++ )
{ {
if ( country.at( i ).isUpper() ) if ( extra.at( i ).isUpper() )
{ {
country.insert( i, " " ); extra.insert( i, " " );
i++; i++;
} }
} }
m_cachedCountries[ geo ] = country; m_cachedCountries[ geo ] = extra;
} }
else else
{ {
country = m_cachedCountries[ geo ]; extra = m_cachedCountries[ geo ];
} }
}else extra = chart.value( "extra" ).toString();
if ( name.isEmpty() ) // not a specific chart, an all chart if ( name.isEmpty() ) // not a specific chart, an all chart
name = tr( "Top Overall" ); name = tr( "Top Overall" );
@@ -321,34 +329,43 @@ ChartsPlugin::chartTypes()
if ( isDefault ) if ( isDefault )
c[ "default" ] = "true"; c[ "default" ] = "true";
QList<InfoStringHash> countryTypeData = countries[ country ][ type ].value< QList< InfoStringHash > >(); QList<InfoStringHash> extraTypeData = extraType[ extra ][ type ].value< QList< InfoStringHash > >();
countryTypeData.append( c ); extraTypeData.append( c );
countries[ country ].insert( type, QVariant::fromValue< QList< InfoStringHash > >( countryTypeData ) ); extraType[ extra ].insert( type, QVariant::fromValue< QList< InfoStringHash > >( extraTypeData ) );
if ( isDefault ) if ( isDefault )
{ {
defaultChain.clear(); defaultChain.clear();
defaultChain.append( country ); defaultChain.append( extra );
defaultChain.append( type ); defaultChain.append( type );
defaultChain.append( name ); defaultChain.append( name );
} }
} }
foreach( const QString& c, extraType.keys() )
foreach( const QString& c, countries.keys() )
{ {
charts[ c ] = countries[ c ]; charts[ c ] = extraType[ c ];
// qDebug() << "Country has types:" << countries[ c ]; qDebug() << "extraType has types:" << c;
} }
if( source == "itunes" ){
chartName = "iTunes"; chartName = "iTunes";
} else }
if( source == "wearehunted" ){
chartName = "WeAreHunted";
}
}
}else
{ {
// We'll just build: // We'll just build:
// [Source] - Album - Chart Type // [Source] - Album - Chart Type
// [Source] - Track - Chart Type // [Source] - Track - Chart Type
QList< InfoStringHash > albumCharts; QList< InfoStringHash > albumCharts;
QList< InfoStringHash > trackCharts; QList< InfoStringHash > trackCharts;
QList< InfoStringHash > artistCharts;
foreach( const QVariant& chartObj, chartObjs.values() ) foreach( const QVariant& chartObj, chartObjs.values() )
{ {
if( !chartObj.toMap().isEmpty() ){
const QVariantMap chart = chartObj.toMap(); const QVariantMap chart = chartObj.toMap();
const QString type = chart.value( "type" ).toString(); const QString type = chart.value( "type" ).toString();
const bool isDefault = ( chart.contains( "default" ) && chart[ "default" ].toInt() == 1 ); const bool isDefault = ( chart.contains( "default" ) && chart[ "default" ].toInt() == 1 );
@@ -368,6 +385,12 @@ ChartsPlugin::chartTypes()
{ {
c[ "type" ] = "tracks"; c[ "type" ] = "tracks";
trackCharts.append( c ); trackCharts.append( c );
}else if ( type == "Artist" )
{
c[ "type" ] = "artists";
artistCharts.append( c );
} }
if ( isDefault ) if ( isDefault )
@@ -377,7 +400,11 @@ ChartsPlugin::chartTypes()
defaultChain.append( c[ "label" ] ); defaultChain.append( c[ "label" ] );
} }
} }
if( !artistCharts.isEmpty() )
charts.insert( tr( "Artists" ), QVariant::fromValue< QList< InfoStringHash > >( artistCharts ) );
if( !albumCharts.isEmpty() )
charts.insert( tr( "Albums" ), QVariant::fromValue< QList< InfoStringHash > >( albumCharts ) ); charts.insert( tr( "Albums" ), QVariant::fromValue< QList< InfoStringHash > >( albumCharts ) );
if( !trackCharts.isEmpty() )
charts.insert( tr( "Tracks" ), QVariant::fromValue< QList< InfoStringHash > >( trackCharts ) ); charts.insert( tr( "Tracks" ), QVariant::fromValue< QList< InfoStringHash > >( trackCharts ) );
/// @note For displaying purposes, upper the first letter /// @note For displaying purposes, upper the first letter
@@ -385,6 +412,7 @@ ChartsPlugin::chartTypes()
chartName = source; chartName = source;
chartName[0] = chartName[0].toUpper(); chartName[0] = chartName[0].toUpper();
} }
}
/// Add the possible charts and its types to breadcrumb /// Add the possible charts and its types to breadcrumb
// qDebug() << "ADDING CHART TYPE TO CHARTS:" << chartName; // qDebug() << "ADDING CHART TYPE TO CHARTS:" << chartName;
@@ -436,6 +464,7 @@ ChartsPlugin::chartReturned()
QVariantList chartResponse = res.value( "list" ).toList(); QVariantList chartResponse = res.value( "list" ).toList();
QList< InfoStringHash > top_tracks; QList< InfoStringHash > top_tracks;
QList< InfoStringHash > top_albums; QList< InfoStringHash > top_albums;
QStringList top_artists;
/// Deside what type, we need to handle it differently /// Deside what type, we need to handle it differently
/// @todo: We allready know the type, append it to breadcrumb hash /// @todo: We allready know the type, append it to breadcrumb hash
@@ -444,6 +473,8 @@ ChartsPlugin::chartReturned()
setChartType( Album ); setChartType( Album );
else if( res.value( "type" ).toString() == "Track" ) else if( res.value( "type" ).toString() == "Track" )
setChartType( Track ); setChartType( Track );
else if( res.value( "type" ).toString() == "Artist" )
setChartType( Artist );
else else
setChartType( None ); setChartType( None );
@@ -499,10 +530,29 @@ ChartsPlugin::chartReturned()
top_tracks << pair; top_tracks << pair;
} }
}else if( chartType() == Artist )
{
if ( artist.isEmpty() ) // don't have enough...
{
tLog() << "Didn't get an artist from charts, not enough to build a query on. Aborting" << artist;
}
else
{
top_artists << artist;
}
} }
} }
} }
if( chartType() == Artist )
{
tDebug() << "ChartsPlugin:" << "\tgot " << top_artists.size() << " artists";
returnedData["artists"] = QVariant::fromValue( top_artists );
returnedData["type"] = "artists";
}
if( chartType() == Track ) if( chartType() == Track )
{ {
tDebug() << "ChartsPlugin:" << "\tgot " << top_tracks.size() << " tracks"; tDebug() << "ChartsPlugin:" << "\tgot " << top_tracks.size() << " tracks";