mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-11 16:44:05 +02:00
Add extra types
This commit is contained in:
@@ -42,7 +42,7 @@ NewReleasesPlugin::NewReleasesPlugin()
|
|||||||
: InfoPlugin()
|
: InfoPlugin()
|
||||||
, m_nrFetchJobs ( 0 )
|
, m_nrFetchJobs ( 0 )
|
||||||
{
|
{
|
||||||
m_nrVersion = "0";
|
m_nrVersion = "0.1";
|
||||||
m_supportedGetTypes << InfoNewReleaseCapabilities << InfoNewRelease;
|
m_supportedGetTypes << InfoNewReleaseCapabilities << InfoNewRelease;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,8 +54,10 @@ NewReleasesPlugin::~NewReleasesPlugin()
|
|||||||
void
|
void
|
||||||
NewReleasesPlugin::init()
|
NewReleasesPlugin::init()
|
||||||
{
|
{
|
||||||
|
|
||||||
QVariantList source_qvarlist = TomahawkUtils::Cache::instance()->getData( "NewReleasesPlugin", "nr_sources" ).toList();
|
QVariantList source_qvarlist = TomahawkUtils::Cache::instance()->getData( "NewReleasesPlugin", "nr_sources" ).toList();
|
||||||
foreach( const QVariant & source, source_qvarlist ) {
|
foreach( const QVariant & source, source_qvarlist )
|
||||||
|
{
|
||||||
m_nrSources.append( source.toString() );
|
m_nrSources.append( source.toString() );
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "fetched source from cache" << source.toString();
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "fetched source from cache" << source.toString();
|
||||||
|
|
||||||
@@ -79,21 +81,28 @@ void NewReleasesPlugin::getInfo ( InfoRequestData requestData )
|
|||||||
InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >();
|
InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >();
|
||||||
bool foundSource = false;
|
bool foundSource = false;
|
||||||
|
|
||||||
switch ( requestData.type ) {
|
switch ( requestData.type )
|
||||||
|
{
|
||||||
case InfoNewRelease:
|
case InfoNewRelease:
|
||||||
/// We need something to check if the request is actually ment to go to this plugin
|
/// We need something to check if the request is actually ment to go to this plugin
|
||||||
if ( !hash.contains ( "nr_source" ) ) {
|
if ( !hash.contains ( "nr_source" ) )
|
||||||
|
{
|
||||||
tDebug ( LOGVERBOSE ) << Q_FUNC_INFO << "Hash did not contain required param!";
|
tDebug ( LOGVERBOSE ) << Q_FUNC_INFO << "Hash did not contain required param!";
|
||||||
dataError ( requestData );
|
dataError ( requestData );
|
||||||
break;
|
break;
|
||||||
} else {
|
}
|
||||||
foreach ( QString resource, m_nrSources ) {
|
else
|
||||||
if ( resource == hash["nr_source"] ) {
|
{
|
||||||
|
foreach ( QString resource, m_nrSources )
|
||||||
|
{
|
||||||
|
if ( resource == hash["nr_source"] )
|
||||||
|
{
|
||||||
foundSource = true;
|
foundSource = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !foundSource ) {
|
if ( !foundSource )
|
||||||
|
{
|
||||||
dataError ( requestData );
|
dataError ( requestData );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -112,7 +121,8 @@ void NewReleasesPlugin::getInfo ( InfoRequestData requestData )
|
|||||||
|
|
||||||
void NewReleasesPlugin::fetchNRFromCache ( InfoRequestData requestData )
|
void NewReleasesPlugin::fetchNRFromCache ( InfoRequestData requestData )
|
||||||
{
|
{
|
||||||
if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) {
|
if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
|
||||||
|
{
|
||||||
dataError ( requestData );
|
dataError ( requestData );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -121,7 +131,8 @@ void NewReleasesPlugin::fetchNRFromCache ( InfoRequestData requestData )
|
|||||||
Tomahawk::InfoSystem::InfoStringHash criteria;
|
Tomahawk::InfoSystem::InfoStringHash criteria;
|
||||||
|
|
||||||
/// Each request needs to contain both a id and source
|
/// Each request needs to contain both a id and source
|
||||||
if ( !hash.contains ( "nr_id" ) && !hash.contains ( "nr_source" ) ) {
|
if ( !hash.contains ( "nr_id" ) && !hash.contains ( "nr_source" ) )
|
||||||
|
{
|
||||||
tDebug ( LOGVERBOSE ) << Q_FUNC_INFO << "Hash did not contain required params!";
|
tDebug ( LOGVERBOSE ) << Q_FUNC_INFO << "Hash did not contain required params!";
|
||||||
dataError ( requestData );
|
dataError ( requestData );
|
||||||
return;
|
return;
|
||||||
@@ -136,7 +147,8 @@ void NewReleasesPlugin::fetchNRFromCache ( InfoRequestData requestData )
|
|||||||
|
|
||||||
void NewReleasesPlugin::fetchNRCapabilitiesFromCache ( InfoRequestData requestData )
|
void NewReleasesPlugin::fetchNRCapabilitiesFromCache ( InfoRequestData requestData )
|
||||||
{
|
{
|
||||||
if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) {
|
if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
|
||||||
|
{
|
||||||
tDebug ( LOGVERBOSE ) << Q_FUNC_INFO << "Could not convert requestData to InfoStringHash!";
|
tDebug ( LOGVERBOSE ) << Q_FUNC_INFO << "Could not convert requestData to InfoStringHash!";
|
||||||
dataError ( requestData );
|
dataError ( requestData );
|
||||||
return;
|
return;
|
||||||
@@ -150,15 +162,18 @@ void NewReleasesPlugin::fetchNRCapabilitiesFromCache ( InfoRequestData requestDa
|
|||||||
|
|
||||||
void NewReleasesPlugin::notInCacheSlot ( InfoStringHash criteria, InfoRequestData requestData )
|
void NewReleasesPlugin::notInCacheSlot ( InfoStringHash criteria, InfoRequestData requestData )
|
||||||
{
|
{
|
||||||
switch ( requestData.type ) {
|
switch ( requestData.type )
|
||||||
case InfoNewRelease: {
|
{
|
||||||
|
case InfoNewRelease:
|
||||||
|
{
|
||||||
tDebug ( LOGVERBOSE ) << Q_FUNC_INFO << "InfoNewRelease not in cache! Fetching...";
|
tDebug ( LOGVERBOSE ) << Q_FUNC_INFO << "InfoNewRelease not in cache! Fetching...";
|
||||||
fetchNR ( requestData, criteria["nr_source"], criteria["nr_id"] );
|
fetchNR ( requestData, criteria["nr_source"], criteria["nr_id"] );
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case InfoNewReleaseCapabilities: {
|
case InfoNewReleaseCapabilities:
|
||||||
|
{
|
||||||
tDebug ( LOGVERBOSE ) << Q_FUNC_INFO << "InfoChartCapabilities not in cache! Fetching...";
|
tDebug ( LOGVERBOSE ) << Q_FUNC_INFO << "InfoChartCapabilities not in cache! Fetching...";
|
||||||
fetchNRSourcesList( false );
|
fetchNRSourcesList( false );
|
||||||
m_cachedRequests.append ( requestData );
|
m_cachedRequests.append ( requestData );
|
||||||
@@ -166,7 +181,8 @@ void NewReleasesPlugin::notInCacheSlot ( InfoStringHash criteria, InfoRequestDat
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
default: {
|
default:
|
||||||
|
{
|
||||||
tLog() << Q_FUNC_INFO << "Couldn't figure out what to do with this type of request after cache miss";
|
tLog() << Q_FUNC_INFO << "Couldn't figure out what to do with this type of request after cache miss";
|
||||||
emit info ( requestData, QVariant() );
|
emit info ( requestData, QVariant() );
|
||||||
return;
|
return;
|
||||||
@@ -191,19 +207,22 @@ void NewReleasesPlugin::nrSourcesList()
|
|||||||
tDebug ( LOGVERBOSE ) << "Got newreleases sources list";
|
tDebug ( LOGVERBOSE ) << "Got newreleases sources list";
|
||||||
QNetworkReply* reply = qobject_cast<QNetworkReply*> ( sender() );
|
QNetworkReply* reply = qobject_cast<QNetworkReply*> ( sender() );
|
||||||
|
|
||||||
if ( reply->error() == QNetworkReply::NoError ) {
|
if ( reply->error() == QNetworkReply::NoError )
|
||||||
|
{
|
||||||
QJson::Parser p;
|
QJson::Parser p;
|
||||||
bool ok;
|
bool ok;
|
||||||
const QVariantMap res = p.parse ( reply, &ok ).toMap();
|
const QVariantMap res = p.parse ( reply, &ok ).toMap();
|
||||||
const QVariantList sources = res.value ( "sources" ).toList();
|
const QVariantList sources = res.value ( "sources" ).toList();
|
||||||
|
|
||||||
if ( !ok ) {
|
if ( !ok )
|
||||||
|
{
|
||||||
tLog() << "Failed to parse sources" << p.errorString() << "On line" << p.errorLine();
|
tLog() << "Failed to parse sources" << p.errorString() << "On line" << p.errorLine();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_nrSources.clear();
|
m_nrSources.clear();
|
||||||
foreach ( const QVariant &source, sources ) {
|
foreach ( const QVariant &source, sources )
|
||||||
|
{
|
||||||
m_nrSources << source.toString();
|
m_nrSources << source.toString();
|
||||||
}
|
}
|
||||||
TomahawkUtils::Cache::instance()->putData( "NewReleasesPlugin", 172800000 /* 2 days */, "nr_sources", m_nrSources );
|
TomahawkUtils::Cache::instance()->putData( "NewReleasesPlugin", 172800000 /* 2 days */, "nr_sources", m_nrSources );
|
||||||
@@ -214,9 +233,11 @@ void NewReleasesPlugin::nrSourcesList()
|
|||||||
|
|
||||||
void NewReleasesPlugin::fetchAllNRSources()
|
void NewReleasesPlugin::fetchAllNRSources()
|
||||||
{
|
{
|
||||||
if ( !m_nrSources.isEmpty() && m_allNRsMap.isEmpty() ) {
|
if ( !m_nrSources.isEmpty() && m_allNRsMap.isEmpty() )
|
||||||
|
{
|
||||||
tDebug ( LOGVERBOSE ) << Q_FUNC_INFO << "InfoNewRelease fetching source data";
|
tDebug ( LOGVERBOSE ) << Q_FUNC_INFO << "InfoNewRelease fetching source data";
|
||||||
foreach ( QString source, m_nrSources ) {
|
foreach ( QString source, m_nrSources )
|
||||||
|
{
|
||||||
QUrl url = QUrl ( QString ( CHART_URL "newreleases/%1" ).arg ( source ) );
|
QUrl url = QUrl ( QString ( CHART_URL "newreleases/%1" ).arg ( source ) );
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get ( QNetworkRequest ( url ) );
|
QNetworkReply* reply = TomahawkUtils::nam()->get ( QNetworkRequest ( url ) );
|
||||||
reply->setProperty ( "nr_source", source );
|
reply->setProperty ( "nr_source", source );
|
||||||
@@ -246,12 +267,14 @@ void NewReleasesPlugin::nrList()
|
|||||||
tDebug ( LOGVERBOSE ) << "Got newreleases list result";
|
tDebug ( LOGVERBOSE ) << "Got newreleases list result";
|
||||||
QNetworkReply* reply = qobject_cast<QNetworkReply*> ( sender() );
|
QNetworkReply* reply = qobject_cast<QNetworkReply*> ( sender() );
|
||||||
|
|
||||||
if ( reply->error() == QNetworkReply::NoError ) {
|
if ( reply->error() == QNetworkReply::NoError )
|
||||||
|
{
|
||||||
QJson::Parser p;
|
QJson::Parser p;
|
||||||
bool ok;
|
bool ok;
|
||||||
const QVariantMap res = p.parse ( reply, &ok ).toMap();
|
const QVariantMap res = p.parse ( reply, &ok ).toMap();
|
||||||
|
|
||||||
if ( !ok ) {
|
if ( !ok )
|
||||||
|
{
|
||||||
tLog() << "Failed to parse resources" << p.errorString() << "On line" << p.errorLine();
|
tLog() << "Failed to parse resources" << p.errorString() << "On line" << p.errorLine();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -267,31 +290,53 @@ void NewReleasesPlugin::nrList()
|
|||||||
// Building:
|
// Building:
|
||||||
// [Source] - New Release
|
// [Source] - New Release
|
||||||
QList< InfoStringHash > albumNRs;
|
QList< InfoStringHash > albumNRs;
|
||||||
|
QHash< QString, QVariantMap > extraType;
|
||||||
foreach ( const QVariant &nrObj, res.values() ) {
|
foreach ( const QVariant &nrObj, res.values() )
|
||||||
if ( !nrObj.toMap().isEmpty() ) {
|
{
|
||||||
|
if ( !nrObj.toMap().isEmpty() )
|
||||||
|
{
|
||||||
const QVariantMap nrMap = nrObj.toMap();
|
const QVariantMap nrMap = nrObj.toMap();
|
||||||
const QString type = nrMap.value ( "type" ).toString();
|
const QString type = nrMap.value ( "type" ).toString();
|
||||||
|
const QString extra = nrMap.value( "extra" ).toString();
|
||||||
|
|
||||||
InfoStringHash nr;
|
InfoStringHash nr;
|
||||||
nr["id"] = nrMap.value ( "id" ).toString();
|
nr["id"] = nrMap.value ( "id" ).toString();
|
||||||
nr["label"] = nrMap.value ( "name" ).toString();
|
nr["label"] = nrMap.value ( "name" ).toString();
|
||||||
nr["date"] = nrMap.value ( "date" ).toString();
|
nr["date"] = nrMap.value ( "date" ).toString();
|
||||||
|
|
||||||
if ( type == "Album" ) {
|
if ( type == "Album" )
|
||||||
|
{
|
||||||
nr[ "type" ] = "album";
|
nr[ "type" ] = "album";
|
||||||
albumNRs.append ( nr );
|
|
||||||
} else {
|
if( !extra.isEmpty() )
|
||||||
|
{
|
||||||
|
qDebug() << "FOUND EXTRA!! " << extra;
|
||||||
|
QList< Tomahawk::InfoSystem::InfoStringHash > extraTypeData = extraType[ extra ][ type ].value< QList< Tomahawk::InfoSystem::InfoStringHash > >();
|
||||||
|
extraTypeData.append( nr );
|
||||||
|
extraType[ extra ][ type ] = QVariant::fromValue< QList< Tomahawk::InfoSystem::InfoStringHash > >( extraTypeData );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
albumNRs.append ( nr );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
tLog() << "Unknown newrelease type " << type;
|
tLog() << "Unknown newrelease type " << type;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach( const QString& c, extraType.keys() )
|
||||||
|
{
|
||||||
|
newreleases[ c ] = extraType[ c ];
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "extraType has types:" << c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !albumNRs.isEmpty() )
|
if ( !albumNRs.isEmpty() )
|
||||||
newreleases.insert ( tr ( "Albums" ), QVariant::fromValue< QList< Tomahawk::InfoSystem::InfoStringHash > > ( albumNRs ) );
|
newreleases.insert ( tr ( "Albums" ), QVariant::fromValue< QList< Tomahawk::InfoSystem::InfoStringHash > > ( albumNRs ) );
|
||||||
|
|
||||||
|
|
||||||
/// @note For displaying purposes, upper the first letter
|
/// @note For displaying purposes, upper the first letter
|
||||||
/// @note Remeber to lower it when fetching this!
|
/// @note Remeber to lower it when fetching this!
|
||||||
nrName = source;
|
nrName = source;
|
||||||
@@ -306,8 +351,10 @@ void NewReleasesPlugin::nrList()
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_nrFetchJobs--;
|
m_nrFetchJobs--;
|
||||||
if ( !m_cachedRequests.isEmpty() && m_nrFetchJobs == 0 ) {
|
if ( !m_cachedRequests.isEmpty() && m_nrFetchJobs == 0 )
|
||||||
foreach ( InfoRequestData request, m_cachedRequests ) {
|
{
|
||||||
|
foreach ( InfoRequestData request, m_cachedRequests )
|
||||||
|
{
|
||||||
emit info ( request, m_allNRsMap );
|
emit info ( request, m_allNRsMap );
|
||||||
// update cache
|
// update cache
|
||||||
Tomahawk::InfoSystem::InfoStringHash criteria;
|
Tomahawk::InfoSystem::InfoStringHash criteria;
|
||||||
@@ -325,12 +372,14 @@ void NewReleasesPlugin::nrReturned()
|
|||||||
QNetworkReply* reply = qobject_cast<QNetworkReply*> ( sender() );
|
QNetworkReply* reply = qobject_cast<QNetworkReply*> ( sender() );
|
||||||
QVariantMap returnedData;
|
QVariantMap returnedData;
|
||||||
|
|
||||||
if ( reply->error() == QNetworkReply::NoError ) {
|
if ( reply->error() == QNetworkReply::NoError )
|
||||||
|
{
|
||||||
QJson::Parser p;
|
QJson::Parser p;
|
||||||
bool ok;
|
bool ok;
|
||||||
QVariantMap res = p.parse ( reply, &ok ).toMap();
|
QVariantMap res = p.parse ( reply, &ok ).toMap();
|
||||||
|
|
||||||
if ( !ok ) {
|
if ( !ok )
|
||||||
|
{
|
||||||
tLog() << "Failed to parse json from chart lookup:" << p.errorString() << "On line" << p.errorLine();
|
tLog() << "Failed to parse json from chart lookup:" << p.errorString() << "On line" << p.errorLine();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -339,9 +388,11 @@ void NewReleasesPlugin::nrReturned()
|
|||||||
QVariantList albumList = res.value ( "list" ).toList();
|
QVariantList albumList = res.value ( "list" ).toList();
|
||||||
QList< Tomahawk::InfoSystem::InfoStringHash > newreleases;
|
QList< Tomahawk::InfoSystem::InfoStringHash > newreleases;
|
||||||
|
|
||||||
foreach( const QVariant & albumObj, albumList ) {
|
foreach( const QVariant & albumObj, albumList )
|
||||||
|
{
|
||||||
QVariantMap albumMap = albumObj.toMap();
|
QVariantMap albumMap = albumObj.toMap();
|
||||||
if(!albumMap.isEmpty()) {
|
if( !albumMap.isEmpty() )
|
||||||
|
{
|
||||||
const QString album = albumMap.value("album").toString();
|
const QString album = albumMap.value("album").toString();
|
||||||
const QString artist = albumMap.value("artist").toString();
|
const QString artist = albumMap.value("artist").toString();
|
||||||
const QString date = albumMap.value("date").toString();
|
const QString date = albumMap.value("date").toString();
|
||||||
|
Reference in New Issue
Block a user