mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-07 14:46:33 +02:00
Utilize new detailed information, allowing any new sources after 0.6.99
This commit is contained in:
@@ -55,12 +55,8 @@ ChartsPlugin::ChartsPlugin()
|
|||||||
{
|
{
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << QThread::currentThread();
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << QThread::currentThread();
|
||||||
|
|
||||||
// If you add resource, update version as well
|
m_chartVersion = "2.6.5";
|
||||||
m_chartVersion = "2.6.4";
|
|
||||||
m_supportedGetTypes << InfoChart << InfoChartCapabilities;
|
m_supportedGetTypes << InfoChart << InfoChartCapabilities;
|
||||||
|
|
||||||
// Charts that have geo or genre types
|
|
||||||
m_geoChartIds << "itunes" << "hotnewhiphop" << "djshop.de" << "rdio";
|
|
||||||
m_cacheIdentifier = TomahawkUtils::md5( QString("ChartsPlugin" + m_chartVersion ).toUtf8() );
|
m_cacheIdentifier = TomahawkUtils::md5( QString("ChartsPlugin" + m_chartVersion ).toUtf8() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,6 +397,7 @@ ChartsPlugin::fetchExpiredSources()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ChartsPlugin::fetchAllChartSources()
|
ChartsPlugin::fetchAllChartSources()
|
||||||
{
|
{
|
||||||
@@ -441,7 +438,7 @@ ChartsPlugin::chartsList()
|
|||||||
{
|
{
|
||||||
QJson::Parser p;
|
QJson::Parser p;
|
||||||
bool ok;
|
bool ok;
|
||||||
const QVariantMap res = p.parse( reply, &ok ).toMap();
|
QVariantMap res = p.parse( reply, &ok ).toMap();
|
||||||
|
|
||||||
if ( !ok )
|
if ( !ok )
|
||||||
{
|
{
|
||||||
@@ -450,8 +447,12 @@ ChartsPlugin::chartsList()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Got types, append!
|
const QVariantMap details = res.take( "details" ).toMap();
|
||||||
const QString source = reply->property("chart_source").toString();
|
const QVariantMap response = res;
|
||||||
|
const bool haveExtra = details.value( "have_extra", false ).toBool();
|
||||||
|
// This is what we use as ID
|
||||||
|
const QString source = reply->property( "chart_source" ).toString();
|
||||||
|
const QString prettyName = details.value( "name", source ).toString();
|
||||||
const qlonglong expires = QString( reply->rawHeader( QString( "Expires" ).toLocal8Bit() ) ).toLongLong( &ok );
|
const qlonglong expires = QString( reply->rawHeader( QString( "Expires" ).toLocal8Bit() ) ).toLongLong( &ok );
|
||||||
|
|
||||||
if ( !ok )
|
if ( !ok )
|
||||||
@@ -463,27 +464,29 @@ ChartsPlugin::chartsList()
|
|||||||
|
|
||||||
// We'll populate charts with the data from the server
|
// We'll populate charts with the data from the server
|
||||||
QVariantMap charts;
|
QVariantMap charts;
|
||||||
QString chartName;
|
|
||||||
QStringList defaultChain;
|
QStringList defaultChain;
|
||||||
|
|
||||||
if ( m_geoChartIds.contains( source ) )
|
if ( haveExtra )
|
||||||
{
|
{
|
||||||
// Some charts can have an extra param, itunes has geo, WAH has emerging/mainstream
|
// Some charts can have an extra param, itunes has geo, HNHH has upcomming/all/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
|
||||||
|
// NameID - Extra - Type -> Chart Name
|
||||||
QHash< QString, QVariantMap > extraType;
|
QHash< QString, QVariantMap > extraType;
|
||||||
QStringList processed;
|
QStringList processed;
|
||||||
foreach ( const QVariant& chartObj, res.values() )
|
|
||||||
|
foreach ( const QVariant& chartObj, response.values() )
|
||||||
{
|
{
|
||||||
if ( !chartObj.toMap().isEmpty() )
|
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();
|
||||||
QString name = chart.value( "genre" ).toString();
|
const QString name = chart.value( "display_name" ).toString();
|
||||||
const QString type = QString( chart.value( "type" ).toString() + "s" );
|
const QString type = QString( 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 extra;
|
||||||
|
|
||||||
// Hack!
|
// Hack!
|
||||||
// Japan charts contains multiple duplicates, all which are linked
|
// Japan charts contains multiple duplicates, all which are linked
|
||||||
@@ -496,81 +499,37 @@ ChartsPlugin::chartsList()
|
|||||||
processed << name;
|
processed << name;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString extra;
|
|
||||||
if ( !geo.isEmpty() )
|
if ( !geo.isEmpty() )
|
||||||
{
|
extra = countryName( geo );
|
||||||
if ( !m_cachedCountries.contains( geo ) )
|
|
||||||
{
|
|
||||||
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
|
else
|
||||||
extra = chart.value( "extra" ).toString();
|
extra = chart.value( "extra" ).toString();
|
||||||
|
|
||||||
if ( source == "hotnewhiphop" || source == "djshop.de" || source == "rdio" )
|
|
||||||
name = chart.value( "name" ).toString();
|
|
||||||
|
|
||||||
if ( name.isEmpty() ) // not a specific chart, an all chart
|
|
||||||
name = tr( "Top Overall" );
|
|
||||||
|
|
||||||
InfoStringHash c;
|
InfoStringHash c;
|
||||||
c[ "id" ] = id;
|
c[ "id" ] = id;
|
||||||
c[ "label" ] = name;
|
c[ "label" ] = name;
|
||||||
c[ "type" ] = "album";
|
c[ "type" ] = type;
|
||||||
if ( isDefault )
|
|
||||||
c[ "default" ] = "true";
|
|
||||||
|
|
||||||
/// If this item has expired, set it to 0.
|
if ( isDefault )
|
||||||
|
{
|
||||||
|
c[ "default" ] = "true";
|
||||||
|
defaultChain.clear();
|
||||||
|
defaultChain.append( extra );
|
||||||
|
defaultChain.append( type );
|
||||||
|
defaultChain.append( name );
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this item has expired, set it to 0.
|
||||||
c[ "expires" ] = ( ok ? QString::number (expires ) : QString::number( 0 ) );
|
c[ "expires" ] = ( ok ? QString::number (expires ) : QString::number( 0 ) );
|
||||||
|
|
||||||
QList< Tomahawk::InfoSystem::InfoStringHash > extraTypeData = extraType[ extra ][ type ].value< QList< Tomahawk::InfoSystem::InfoStringHash > >();
|
QList< Tomahawk::InfoSystem::InfoStringHash > extraTypeData = extraType[ extra ][ type ].value< QList< Tomahawk::InfoSystem::InfoStringHash > >();
|
||||||
extraTypeData.append( c );
|
extraTypeData.append( c );
|
||||||
extraType[ extra ][ type ] = QVariant::fromValue< QList< Tomahawk::InfoSystem::InfoStringHash > >( extraTypeData );
|
extraType[ extra ][ type ] = QVariant::fromValue< QList< Tomahawk::InfoSystem::InfoStringHash > >( extraTypeData );
|
||||||
|
|
||||||
if ( isDefault )
|
|
||||||
{
|
|
||||||
defaultChain.clear();
|
|
||||||
defaultChain.append( extra );
|
|
||||||
defaultChain.append( type );
|
|
||||||
defaultChain.append( name );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
foreach ( const QString& c, extraType.keys() )
|
foreach ( const QString& c, extraType.keys() )
|
||||||
{
|
{
|
||||||
charts[ c ] = extraType[ c ];
|
charts[ c ] = extraType[ c ];
|
||||||
}
|
}
|
||||||
if ( source == "itunes" )
|
|
||||||
{
|
|
||||||
chartName = "iTunes";
|
|
||||||
}
|
|
||||||
else if ( source == "soundcloudwall" )
|
|
||||||
{
|
|
||||||
chartName = "SoundCloudWall";
|
|
||||||
}
|
|
||||||
else if ( source == "hotnewhiphop" )
|
|
||||||
{
|
|
||||||
chartName = "HotNewHiphop";
|
|
||||||
}
|
|
||||||
else if ( source == "djshop.de" )
|
|
||||||
{
|
|
||||||
chartName = "DjShop.de";
|
|
||||||
}
|
|
||||||
else if ( source == "rdio" )
|
|
||||||
{
|
|
||||||
chartName = "Rdio";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -582,47 +541,36 @@ ChartsPlugin::chartsList()
|
|||||||
QList< InfoStringHash > trackCharts;
|
QList< InfoStringHash > trackCharts;
|
||||||
QList< InfoStringHash > artistCharts;
|
QList< InfoStringHash > artistCharts;
|
||||||
|
|
||||||
foreach ( const QVariant& chartObj, res.values() )
|
foreach ( const QVariant& chartObj, response.values() )
|
||||||
{
|
{
|
||||||
if ( !chartObj.toMap().isEmpty() )
|
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 QString name = chart.value( "display_name" ).toString();
|
||||||
const bool isDefault = ( chart.contains( "default" ) && chart[ "default" ].toInt() == 1 );
|
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" ] = name;
|
||||||
c[ "expires" ] = ( ok ? QString::number( expires ) : QString::number( 0 ) );
|
c[ "expires" ] = ( ok ? QString::number( expires ) : QString::number( 0 ) );
|
||||||
if ( chart.value( "genre").isValid() )
|
c[ "type" ] = type.toLower();
|
||||||
c[ "label" ] = chart.value( "genre" ).toString();
|
|
||||||
else
|
|
||||||
c[ "label" ] = chart.value( "name" ).toString();
|
|
||||||
|
|
||||||
if ( isDefault )
|
if ( isDefault )
|
||||||
|
{
|
||||||
c[ "default" ] = "true";
|
c[ "default" ] = "true";
|
||||||
|
|
||||||
if ( type == "Album" )
|
|
||||||
{
|
|
||||||
c[ "type" ] = "album";
|
|
||||||
albumCharts.append( c );
|
|
||||||
}
|
|
||||||
else if ( type == "Track" )
|
|
||||||
{
|
|
||||||
c[ "type" ] = "tracks";
|
|
||||||
trackCharts.append( c );
|
|
||||||
}
|
|
||||||
else if ( type == "Artist" )
|
|
||||||
{
|
|
||||||
c[ "type" ] = "artists";
|
|
||||||
artistCharts.append( c );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( isDefault )
|
|
||||||
{
|
|
||||||
defaultChain.clear();
|
defaultChain.clear();
|
||||||
defaultChain.append( type + "s" ); //UGLY but it's plural to the user, see below
|
defaultChain.append( type );
|
||||||
defaultChain.append( c[ "label" ] );
|
defaultChain.append( c[ "label" ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( type == "Albums" )
|
||||||
|
albumCharts.append( c );
|
||||||
|
else if ( type == "Tracks" )
|
||||||
|
trackCharts.append( c );
|
||||||
|
else if ( type == "Artists" )
|
||||||
|
artistCharts.append( c );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !artistCharts.isEmpty() )
|
if ( !artistCharts.isEmpty() )
|
||||||
@@ -632,21 +580,16 @@ ChartsPlugin::chartsList()
|
|||||||
if ( !trackCharts.isEmpty() )
|
if ( !trackCharts.isEmpty() )
|
||||||
charts.insert( tr( "Tracks" ), QVariant::fromValue< QList< Tomahawk::InfoSystem::InfoStringHash > >( trackCharts ) );
|
charts.insert( tr( "Tracks" ), QVariant::fromValue< QList< Tomahawk::InfoSystem::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
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Adding to charts:" << chartName;
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Adding to charts:" << prettyName;
|
||||||
QVariantMap defaultMap = m_allChartsMap.value( "defaults" ).value< QVariantMap >();
|
QVariantMap defaultMap = m_allChartsMap.value( "defaults" ).value< QVariantMap >();
|
||||||
defaultMap[ source ] = defaultChain;
|
defaultMap[ source ] = defaultChain;
|
||||||
m_allChartsMap[ "defaults" ] = defaultMap;
|
m_allChartsMap[ "defaults" ] = defaultMap;
|
||||||
m_allChartsMap[ "defaultSource" ] = "itunes";
|
m_allChartsMap[ "defaultSource" ] = "itunes";
|
||||||
m_allChartsMap.insert( chartName , QVariant::fromValue< QVariantMap >( charts ) );
|
m_allChartsMap.insert( prettyName , QVariant::fromValue< QVariantMap >( charts ) );
|
||||||
|
|
||||||
m_refetchSource.removeOne( source );
|
m_refetchSource.removeOne( source );
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Fetched " << source << " have " << m_refetchSource << "left";
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Fetched " << source << " have " << m_refetchSource << "left";
|
||||||
}
|
}
|
||||||
@@ -818,6 +761,27 @@ ChartsPlugin::chartReturned()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString
|
||||||
|
ChartsPlugin::countryName( const QString& cc )
|
||||||
|
{
|
||||||
|
if ( m_cachedCountries.contains( cc ) )
|
||||||
|
return m_cachedCountries[ cc ];
|
||||||
|
|
||||||
|
QString name = Tomahawk::CountryUtils::fullCountryFromCode( cc );
|
||||||
|
for ( int i = 1; i < name.size(); i++ )
|
||||||
|
{
|
||||||
|
if ( name.at( i ).isUpper() )
|
||||||
|
{
|
||||||
|
name.insert( i, " " );
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_cachedCountries[ cc ] = name;
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
qlonglong
|
qlonglong
|
||||||
ChartsPlugin::getMaxAge( const QByteArray &rawHeader ) const
|
ChartsPlugin::getMaxAge( const QByteArray &rawHeader ) const
|
||||||
{
|
{
|
||||||
|
@@ -49,7 +49,6 @@ public:
|
|||||||
Track = 0x01,
|
Track = 0x01,
|
||||||
Album = 0x02,
|
Album = 0x02,
|
||||||
Artist = 0x04
|
Artist = 0x04
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void setChartType( ChartType type ) { m_chartType = type; }
|
void setChartType( ChartType type ) { m_chartType = type; }
|
||||||
@@ -102,22 +101,23 @@ private:
|
|||||||
void fetchChartCapabilitiesFromCache( Tomahawk::InfoSystem::InfoRequestData requestData );
|
void fetchChartCapabilitiesFromCache( Tomahawk::InfoSystem::InfoRequestData requestData );
|
||||||
void dataError( Tomahawk::InfoSystem::InfoRequestData requestData );
|
void dataError( Tomahawk::InfoSystem::InfoRequestData requestData );
|
||||||
|
|
||||||
|
QString countryName( const QString& cc );
|
||||||
|
|
||||||
qlonglong getMaxAge( const QByteArray &rawHeader ) const;
|
qlonglong getMaxAge( const QByteArray &rawHeader ) const;
|
||||||
qlonglong getMaxAge( const qlonglong expires ) const;
|
qlonglong getMaxAge( const qlonglong expires ) const;
|
||||||
|
|
||||||
|
QVariantMap m_allChartsMap;
|
||||||
|
QHash< QString, QString > m_cachedCountries;
|
||||||
QList< Tomahawk::InfoSystem::InfoStringHash > m_chartResources;
|
QList< Tomahawk::InfoSystem::InfoStringHash > m_chartResources;
|
||||||
|
QList< InfoRequestData > m_cachedRequests;
|
||||||
QStringList m_refetchSource;
|
QStringList m_refetchSource;
|
||||||
|
QString m_cacheIdentifier;
|
||||||
QString m_chartVersion;
|
QString m_chartVersion;
|
||||||
ChartType m_chartType;
|
ChartType m_chartType;
|
||||||
QVariantMap m_allChartsMap;
|
|
||||||
uint m_chartsFetchJobs;
|
uint m_chartsFetchJobs;
|
||||||
QList< InfoRequestData > m_cachedRequests;
|
|
||||||
QHash< QString, QString > m_cachedCountries;
|
|
||||||
QPointer< QNetworkAccessManager > m_nam;
|
|
||||||
QStringList m_geoChartIds;
|
|
||||||
bool m_fetchAll;
|
bool m_fetchAll;
|
||||||
QString m_cacheIdentifier;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user