1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-01 03:40:16 +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,115 +275,143 @@ 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() )
{ {
const QVariantMap chart = chartObj.toMap(); if( !chartObj.toMap().isEmpty() ){
const QString id = chart.value( "id" ).toString(); const QVariantMap chart = chartObj.toMap();
const QString geo = chart.value( "geo" ).toString(); const QString id = chart.value( "id" ).toString();
QString name = chart.value( "genre" ).toString(); const QString geo = chart.value( "geo" ).toString();
const QString type = chart.value( "type" ).toString(); QString name = chart.value( "genre" ).toString();
const bool isDefault = ( chart.contains( "default" ) && chart[ "default" ].toInt() == 1 ); const QString type = chart.value( "type" ).toString();
const bool isDefault = ( chart.contains( "default" ) && chart[ "default" ].toInt() == 1 );
QString country; QString extra;
if ( !m_cachedCountries.contains( geo ) ) if( !geo.isEmpty() ){
{
QLocale l( QString( "en_%1" ).arg( geo ) );
country = Tomahawk::CountryUtils::fullCountryFromCode( geo );
for ( int i = 1; i < country.size(); i++ ) if ( !m_cachedCountries.contains( geo ) )
{
if ( country.at( i ).isUpper() )
{ {
country.insert( i, " " ); QLocale l( QString( "en_%1" ).arg( geo ) );
i++; extra = Tomahawk::CountryUtils::fullCountryFromCode( geo );
for ( int i = 1; i < extra.size(); i++ )
{
if ( extra.at( i ).isUpper() )
{
extra.insert( i, " " );
i++;
}
}
m_cachedCountries[ geo ] = extra;
} }
else
{
extra = m_cachedCountries[ geo ];
}
}else extra = chart.value( "extra" ).toString();
if ( name.isEmpty() ) // not a specific chart, an all chart
name = tr( "Top Overall" );
InfoStringHash c;
c[ "id" ] = id;
c[ "label" ] = name;
c[ "type" ] = "album";
if ( isDefault )
c[ "default" ] = "true";
QList<InfoStringHash> extraTypeData = extraType[ extra ][ type ].value< QList< InfoStringHash > >();
extraTypeData.append( c );
extraType[ extra ].insert( type, QVariant::fromValue< QList< InfoStringHash > >( extraTypeData ) );
if ( isDefault )
{
defaultChain.clear();
defaultChain.append( extra );
defaultChain.append( type );
defaultChain.append( name );
} }
m_cachedCountries[ geo ] = country;
} }
else foreach( const QString& c, extraType.keys() )
{ {
country = m_cachedCountries[ geo ]; charts[ c ] = extraType[ c ];
qDebug() << "extraType has types:" << c;
} }
if( source == "itunes" ){
if ( name.isEmpty() ) // not a specific chart, an all chart chartName = "iTunes";
name = tr( "Top Overall" ); }
if( source == "wearehunted" ){
InfoStringHash c; chartName = "WeAreHunted";
c[ "id" ] = id;
c[ "label" ] = name;
c[ "type" ] = "album";
if ( isDefault )
c[ "default" ] = "true";
QList<InfoStringHash> countryTypeData = countries[ country ][ type ].value< QList< InfoStringHash > >();
countryTypeData.append( c );
countries[ country ].insert( type, QVariant::fromValue< QList< InfoStringHash > >( countryTypeData ) );
if ( isDefault )
{
defaultChain.clear();
defaultChain.append( country );
defaultChain.append( type );
defaultChain.append( name );
} }
} }
foreach( const QString& c, countries.keys() ) }else
{
charts[ c ] = countries[ c ];
// qDebug() << "Country has types:" << countries[ c ];
}
chartName = "iTunes";
} 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() )
{ {
const QVariantMap chart = chartObj.toMap(); if( !chartObj.toMap().isEmpty() ){
const QString type = chart.value( "type" ).toString(); const QVariantMap chart = chartObj.toMap();
const bool isDefault = ( chart.contains( "default" ) && chart[ "default" ].toInt() == 1 ); const QString type = chart.value( "type" ).toString();
const bool isDefault = ( chart.contains( "default" ) && chart[ "default" ].toInt() == 1 );
InfoStringHash c; InfoStringHash c;
c[ "id" ] = chart.value( "id" ).toString(); c[ "id" ] = chart.value( "id" ).toString();
c[ "label" ] = chart.value( "name" ).toString(); c[ "label" ] = chart.value( "name" ).toString();
if ( isDefault ) if ( isDefault )
c[ "default" ] = "true"; c[ "default" ] = "true";
if ( type == "Album" ) if ( type == "Album" )
{ {
c[ "type" ] = "album"; c[ "type" ] = "album";
albumCharts.append( c ); albumCharts.append( c );
} }
else if ( type == "Track" ) else if ( type == "Track" )
{ {
c[ "type" ] = "tracks"; c[ "type" ] = "tracks";
trackCharts.append( c ); trackCharts.append( c );
}
if ( isDefault ) }else if ( type == "Artist" )
{ {
defaultChain.clear(); c[ "type" ] = "artists";
defaultChain.append( type + "s" ); //UGLY but it's plural to the user, see below artistCharts.append( c );
defaultChain.append( c[ "label" ] );
}
if ( isDefault )
{
defaultChain.clear();
defaultChain.append( type + "s" ); //UGLY but it's plural to the user, see below
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 ) );
if( !trackCharts.isEmpty() )
charts.insert( tr( "Tracks" ), QVariant::fromValue< QList< InfoStringHash > >( trackCharts ) );
/// @note For displaying purposes, upper the first letter
/// @note Remeber to lower it when fetching this!
chartName = source;
chartName[0] = chartName[0].toUpper();
} }
charts.insert( tr( "Albums" ), QVariant::fromValue< QList< InfoStringHash > >( albumCharts ) );
charts.insert( tr( "Tracks" ), QVariant::fromValue< QList< InfoStringHash > >( trackCharts ) );
/// @note For displaying purposes, upper the first letter
/// @note Remeber to lower it when fetching this!
chartName = source;
chartName[0] = chartName[0].toUpper();
} }
/// Add the possible charts and its types to breadcrumb /// Add the possible charts and its types to breadcrumb
@@ -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";