mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-12 09:04:33 +02:00
Follow redirects on stream URL
This commit is contained in:
@@ -29,6 +29,7 @@
|
|||||||
#include "network/Servent.h"
|
#include "network/Servent.h"
|
||||||
#include "utils/Closure.h"
|
#include "utils/Closure.h"
|
||||||
#include "utils/NetworkAccessManager.h"
|
#include "utils/NetworkAccessManager.h"
|
||||||
|
#include "utils/NetworkReply.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@@ -595,9 +596,9 @@ void
|
|||||||
JSResolverHelper::returnStreamUrl( const QString& streamUrl, const QMap<QString, QString>& headers,
|
JSResolverHelper::returnStreamUrl( const QString& streamUrl, const QMap<QString, QString>& headers,
|
||||||
boost::function< void( QSharedPointer< QIODevice >& ) > callback )
|
boost::function< void( QSharedPointer< QIODevice >& ) > callback )
|
||||||
{
|
{
|
||||||
QSharedPointer< QIODevice > sp;
|
|
||||||
if ( streamUrl.isEmpty() )
|
if ( streamUrl.isEmpty() )
|
||||||
{
|
{
|
||||||
|
QSharedPointer< QIODevice > sp;
|
||||||
callback( sp );
|
callback( sp );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -608,10 +609,21 @@ JSResolverHelper::returnStreamUrl( const QString& streamUrl, const QMap<QString,
|
|||||||
req.setRawHeader( key.toLatin1(), headers[key].toLatin1() );
|
req.setRawHeader( key.toLatin1(), headers[key].toLatin1() );
|
||||||
}
|
}
|
||||||
tDebug() << "Creating a QNetowrkReply with url:" << req.url().toString();
|
tDebug() << "Creating a QNetowrkReply with url:" << req.url().toString();
|
||||||
QNetworkReply* reply = Tomahawk::Utils::nam()->get( req );
|
NetworkReply* reply = new NetworkReply( Tomahawk::Utils::nam()->get( req ) );
|
||||||
|
|
||||||
|
NewClosure( QSharedPointer<NetworkReply>( reply ) , SIGNAL( finalUrlReached ), this, SLOT( gotStreamUrl() ), callback );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
JSResolverHelper::gotStreamUrl( boost::function< void( QSharedPointer< QIODevice >& ) > callback )
|
||||||
|
{
|
||||||
|
NetworkReply* reply = (NetworkReply*) sender();
|
||||||
|
|
||||||
//boost::functions cannot accept temporaries as parameters
|
//boost::functions cannot accept temporaries as parameters
|
||||||
sp = QSharedPointer< QIODevice >( reply, &QObject::deleteLater );
|
QSharedPointer< QIODevice > sp = QSharedPointer< QIODevice >( reply->reply(), &QObject::deleteLater );
|
||||||
|
reply->disconnectFromReply();
|
||||||
|
reply->deleteLater();
|
||||||
|
|
||||||
callback( sp );
|
callback( sp );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
#include <QVariantMap>
|
#include <QVariantMap>
|
||||||
|
|
||||||
class JSResolver;
|
class JSResolver;
|
||||||
|
Q_DECLARE_METATYPE( boost::function< void( QSharedPointer< QIODevice >& ) > )
|
||||||
|
|
||||||
class DLLEXPORT JSResolverHelper : public QObject
|
class DLLEXPORT JSResolverHelper : public QObject
|
||||||
{
|
{
|
||||||
@@ -81,6 +82,7 @@ public slots:
|
|||||||
void reportCapabilities( const QVariant& capabilities );
|
void reportCapabilities( const QVariant& capabilities );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void gotStreamUrl( boost::function< void( QSharedPointer< QIODevice >& ) > callback );
|
||||||
void tracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::ModelMode, const Tomahawk::collection_ptr& collection );
|
void tracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::ModelMode, const Tomahawk::collection_ptr& collection );
|
||||||
void pltemplateTracksLoadedForUrl( const QString& url, const Tomahawk::playlisttemplate_ptr& pltemplate );
|
void pltemplateTracksLoadedForUrl( const QString& url, const Tomahawk::playlisttemplate_ptr& pltemplate );
|
||||||
|
|
||||||
|
@@ -51,6 +51,14 @@ NetworkReply::blacklistHostFromRedirection( const QString& host )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
NetworkReply::disconnectFromReply()
|
||||||
|
{
|
||||||
|
disconnectReplySignals();
|
||||||
|
m_reply = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
NetworkReply::deletedByParent()
|
NetworkReply::deletedByParent()
|
||||||
{
|
{
|
||||||
|
@@ -37,6 +37,7 @@ public:
|
|||||||
|
|
||||||
void blacklistHostFromRedirection( const QString& host );
|
void blacklistHostFromRedirection( const QString& host );
|
||||||
QNetworkReply* reply() const { return m_reply; }
|
QNetworkReply* reply() const { return m_reply; }
|
||||||
|
void disconnectFromReply();
|
||||||
|
|
||||||
static const int maxRedirects = 100;
|
static const int maxRedirects = 100;
|
||||||
static const int maxSameRedirects = 5;
|
static const int maxSameRedirects = 5;
|
||||||
|
Reference in New Issue
Block a user