mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 19:30:21 +02:00
Set Tomahawk's User-Agent on requests to Musicbrainz
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/NetworkAccessManager.h"
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
#include "TomahawkVersion.h"
|
||||||
|
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QDomDocument>
|
#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
|
void
|
||||||
MusicBrainzPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requestData )
|
MusicBrainzPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requestData )
|
||||||
@@ -111,8 +122,7 @@ MusicBrainzPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ
|
|||||||
TomahawkUtils::urlAddQueryItem( url, "limit", "100" );
|
TomahawkUtils::urlAddQueryItem( url, "limit", "100" );
|
||||||
|
|
||||||
tDebug() << Q_FUNC_INFO << url.toString();
|
tDebug() << Q_FUNC_INFO << url.toString();
|
||||||
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
QNetworkReply* reply = getUrl( url, QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
||||||
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
|
||||||
|
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( gotReleaseGroupsSlot() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( gotReleaseGroupsSlot() ) );
|
||||||
|
|
||||||
@@ -131,8 +141,7 @@ MusicBrainzPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ
|
|||||||
TomahawkUtils::urlAddQueryItem( url, "limit", "100" );
|
TomahawkUtils::urlAddQueryItem( url, "limit", "100" );
|
||||||
|
|
||||||
tDebug() << Q_FUNC_INFO << url.toString();
|
tDebug() << Q_FUNC_INFO << url.toString();
|
||||||
QNetworkReply* reply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
QNetworkReply* reply = getUrl( url, QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
||||||
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
|
||||||
|
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( gotReleasesSlot() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( gotReleasesSlot() ) );
|
||||||
|
|
||||||
@@ -154,6 +163,7 @@ MusicBrainzPlugin::gotReleaseGroupsSlot()
|
|||||||
if ( !oldReply )
|
if ( !oldReply )
|
||||||
return; //timeout will handle it
|
return; //timeout will handle it
|
||||||
oldReply->deleteLater();
|
oldReply->deleteLater();
|
||||||
|
tDebug() << Q_FUNC_INFO << "HTTP response code:" << oldReply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt();
|
||||||
|
|
||||||
QDomDocument doc;
|
QDomDocument doc;
|
||||||
doc.setContent( oldReply->readAll() );
|
doc.setContent( oldReply->readAll() );
|
||||||
@@ -237,8 +247,7 @@ MusicBrainzPlugin::gotReleasesSlot()
|
|||||||
TomahawkUtils::urlAddQueryItem( url, "inc", "recordings" );
|
TomahawkUtils::urlAddQueryItem( url, "inc", "recordings" );
|
||||||
tDebug() << Q_FUNC_INFO << url.toString();
|
tDebug() << Q_FUNC_INFO << url.toString();
|
||||||
|
|
||||||
QNetworkReply* newReply = Tomahawk::Utils::nam()->get( QNetworkRequest( url ) );
|
QNetworkReply* newReply = getUrl( url, oldReply->property( "requestData" ) );
|
||||||
newReply->setProperty( "requestData", oldReply->property( "requestData" ) );
|
|
||||||
connect( newReply, SIGNAL( finished() ), SLOT( gotRecordingsSlot() ) );
|
connect( newReply, SIGNAL( finished() ), SLOT( gotRecordingsSlot() ) );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -261,6 +270,8 @@ MusicBrainzPlugin::gotRecordingsSlot()
|
|||||||
return; //timeout will handle it
|
return; //timeout will handle it
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
|
tDebug() << Q_FUNC_INFO << "HTTP response code:" << reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt();
|
||||||
|
|
||||||
QDomDocument doc;
|
QDomDocument doc;
|
||||||
doc.setContent( reply->readAll() );
|
doc.setContent( reply->readAll() );
|
||||||
QDomNodeList mediumList = doc.elementsByTagName( "medium-list" );
|
QDomNodeList mediumList = doc.elementsByTagName( "medium-list" );
|
||||||
|
@@ -59,6 +59,7 @@ private slots:
|
|||||||
void gotReleaseGroupsSlot();
|
void gotReleaseGroupsSlot();
|
||||||
void gotReleasesSlot();
|
void gotReleasesSlot();
|
||||||
void gotRecordingsSlot();
|
void gotRecordingsSlot();
|
||||||
|
QNetworkReply* getUrl( QUrl url, QVariant requestData );
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user