1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-01-17 14:28:24 +01:00

Set Tomahawk's User-Agent on requests to Musicbrainz

This commit is contained in:
Anton Romanov 2017-01-30 11:56:14 -08:00
parent 3b6ba36e83
commit 97a407f837
2 changed files with 18 additions and 6 deletions

View File

@ -22,6 +22,7 @@
#include "utils/TomahawkUtils.h"
#include "utils/Logger.h"
#include "utils/NetworkAccessManager.h"
#include "TomahawkVersion.h"
#include <QNetworkReply>
#include <QDomDocument>
@ -88,6 +89,16 @@ MusicBrainzPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
}
}
QNetworkReply*
MusicBrainzPlugin::getUrl(QUrl url, QVariant requestData)
{
QNetworkRequest request = QNetworkRequest( url );
QByteArray userAgent = TomahawkUtils::userAgentString( TOMAHAWK_APPLICATION_NAME, TOMAHAWK_VERSION ).toUtf8();
request.setRawHeader( "User-Agent", userAgent );
QNetworkReply* reply = Tomahawk::Utils::nam()->get( request );
reply->setProperty( "requestData", requestData );
return reply;
}
void
MusicBrainzPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requestData )
@ -111,8 +122,7 @@ MusicBrainzPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ
TomahawkUtils::urlAddQueryItem( url, "limit", "100" );
tDebug() << Q_FUNC_INFO << url.toString();
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
QNetworkReply* reply = getUrl( url, QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
connect( reply, SIGNAL( finished() ), SLOT( gotReleaseGroupsSlot() ) );
@ -131,8 +141,7 @@ MusicBrainzPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ
TomahawkUtils::urlAddQueryItem( url, "limit", "100" );
tDebug() << Q_FUNC_INFO << url.toString();
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
QNetworkReply* reply = getUrl( url, QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
connect( reply, SIGNAL( finished() ), SLOT( gotReleasesSlot() ) );
@ -154,6 +163,7 @@ MusicBrainzPlugin::gotReleaseGroupsSlot()
if ( !oldReply )
return; //timeout will handle it
oldReply->deleteLater();
tDebug() << Q_FUNC_INFO << "HTTP response code:" << oldReply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt();
QDomDocument doc;
doc.setContent( oldReply->readAll() );
@ -237,8 +247,7 @@ MusicBrainzPlugin::gotReleasesSlot()
TomahawkUtils::urlAddQueryItem( url, "inc", "recordings" );
tDebug() << Q_FUNC_INFO << url.toString();
QNetworkReply* newReply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
newReply->setProperty( "requestData", oldReply->property( "requestData" ) );
QNetworkReply* newReply = getUrl( url, oldReply->property( "requestData" ) );
connect( newReply, SIGNAL( finished() ), SLOT( gotRecordingsSlot() ) );
break;
@ -261,6 +270,8 @@ MusicBrainzPlugin::gotRecordingsSlot()
return; //timeout will handle it
reply->deleteLater();
tDebug() << Q_FUNC_INFO << "HTTP response code:" << reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt();
QDomDocument doc;
doc.setContent( reply->readAll() );
QDomNodeList mediumList = doc.elementsByTagName( "medium-list" );

View File

@ -59,6 +59,7 @@ private slots:
void gotReleaseGroupsSlot();
void gotReleasesSlot();
void gotRecordingsSlot();
QNetworkReply* getUrl( QUrl url, QVariant requestData );
};
}