mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-11 08:34:34 +02:00
Get rid of custom redirect code for scriptinfoplugin image support
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
#include "../utils/Logger.h"
|
#include "../utils/Logger.h"
|
||||||
#include "../utils/Json.h"
|
#include "../utils/Json.h"
|
||||||
#include "../utils/NetworkAccessManager.h"
|
#include "../utils/NetworkAccessManager.h"
|
||||||
|
#include "../utils/NetworkReply.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -163,7 +164,7 @@ ScriptInfoPlugin::onNotInCacheRequestDone( const QVariantMap& result )
|
|||||||
case InfoSystem::InfoAlbumCoverArt:
|
case InfoSystem::InfoAlbumCoverArt:
|
||||||
{
|
{
|
||||||
QNetworkRequest req( resultData[ "url" ].toUrl() );
|
QNetworkRequest req( resultData[ "url" ].toUrl() );
|
||||||
QNetworkReply* reply = Tomahawk::Utils::nam()->get( req );
|
NetworkReply* reply = new NetworkReply( Tomahawk::Utils::nam()->get( req ) );
|
||||||
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
||||||
reply->setProperty( "criteria", convertInfoStringHashToQVariantMap( criteria ) );
|
reply->setProperty( "criteria", convertInfoStringHashToQVariantMap( criteria ) );
|
||||||
reply->setProperty( "maxAge", result[ "maxAge" ] );
|
reply->setProperty( "maxAge", result[ "maxAge" ] );
|
||||||
@@ -184,16 +185,13 @@ ScriptInfoPlugin::onNotInCacheRequestDone( const QVariantMap& result )
|
|||||||
void
|
void
|
||||||
ScriptInfoPlugin::onCoverArtReturned()
|
ScriptInfoPlugin::onCoverArtReturned()
|
||||||
{
|
{
|
||||||
QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() );
|
NetworkReply* reply = qobject_cast< NetworkReply* >( sender() );
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
QUrl redir = reply->attribute( QNetworkRequest::RedirectionTargetAttribute ).toUrl();
|
|
||||||
if ( redir.isEmpty() )
|
|
||||||
{
|
|
||||||
Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();
|
Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();
|
||||||
Tomahawk::InfoSystem::InfoStringHash criteria = convertQVariantMapToInfoStringHash( reply->property( "criteria" ).toMap() );
|
Tomahawk::InfoSystem::InfoStringHash criteria = convertQVariantMapToInfoStringHash( reply->property( "criteria" ).toMap() );
|
||||||
|
|
||||||
QByteArray ba = reply->readAll();
|
QByteArray ba = reply->reply()->readAll();
|
||||||
if ( ba.isNull() || ba.isEmpty() )
|
if ( ba.isNull() || ba.isEmpty() )
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << "Null byte array for cover of" << criteria["artist"] << criteria["album"];
|
tLog() << Q_FUNC_INFO << "Null byte array for cover of" << criteria["artist"] << criteria["album"];
|
||||||
@@ -203,21 +201,10 @@ ScriptInfoPlugin::onCoverArtReturned()
|
|||||||
|
|
||||||
QVariantMap returnedData;
|
QVariantMap returnedData;
|
||||||
returnedData["imgbytes"] = ba;
|
returnedData["imgbytes"] = ba;
|
||||||
returnedData["url"] = reply->url().toString();
|
returnedData["url"] = reply->reply()->url().toString();
|
||||||
|
|
||||||
emit info( requestData, returnedData );
|
emit info( requestData, returnedData );
|
||||||
emit updateCache( criteria, reply->property( "maxAge" ).toLongLong(), requestData.type, returnedData );
|
emit updateCache( criteria, reply->property( "maxAge" ).toLongLong(), requestData.type, returnedData );
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Follow HTTP redirect
|
|
||||||
QNetworkRequest req( redir );
|
|
||||||
QNetworkReply* newReply = Tomahawk::Utils::nam()->get( req );
|
|
||||||
newReply->setProperty( "requestData", reply->property( "requestData" ) );
|
|
||||||
newReply->setProperty( "criteria", reply->property( "criteria" ) );
|
|
||||||
newReply->setProperty( "maxAge", reply->property( "maxAge" ) );
|
|
||||||
connect( newReply, SIGNAL( finished() ), SLOT( onCoverArtReturned() ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSet< Tomahawk::InfoSystem::InfoType >
|
QSet< Tomahawk::InfoSystem::InfoType >
|
||||||
|
Reference in New Issue
Block a user