mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 22:26:32 +02:00
Fix closure call and handle redirects
This commit is contained in:
@@ -59,5 +59,4 @@ private:
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE( QNetworkReply* )
|
||||
#endif
|
||||
|
@@ -177,5 +177,4 @@ protected:
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE( Attica::Content );
|
||||
Q_DECLARE_METATYPE( QNetworkReply* );
|
||||
#endif // ATTICAMANAGER_H
|
||||
|
@@ -28,6 +28,8 @@
|
||||
|
||||
//template <typename T> class QSharedPointer;
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
namespace Tomahawk
|
||||
{
|
||||
class Artist;
|
||||
@@ -221,5 +223,6 @@ inline static QString uuid()
|
||||
|
||||
Q_DECLARE_METATYPE( QModelIndex )
|
||||
Q_DECLARE_METATYPE( QPersistentModelIndex )
|
||||
Q_DECLARE_METATYPE( QNetworkReply* );
|
||||
|
||||
#endif // TYPEDEFS_H
|
||||
|
@@ -103,8 +103,10 @@ SoundcloudParser::parseTrack( const QVariantMap& res )
|
||||
|
||||
if ( !q.isNull() )
|
||||
{
|
||||
tLog() << "Setting resulthint to " << res.value( "stream_url" ) << res;
|
||||
q->setResultHint( res.value( "stream_url" ).toString() + "?client_id=TiNg2DRYhBnp01DA3zNag" );
|
||||
QUrl url = QUrl::fromUserInput( res.value( "stream_url" ).toString() );
|
||||
url.addQueryItem( "client_id", "TiNg2DRYhBnp01DA3zNag" );
|
||||
tLog() << "Setting resulthint to " << res.value( "stream_url" ) << url.toString();
|
||||
q->setResultHint( url.toString() );
|
||||
q->setSaveHTTPResultHint( true );
|
||||
m_tracks << q;
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
@@ -50,8 +51,7 @@ WebResultHintChecker::WebResultHintChecker( const query_ptr& q )
|
||||
return;
|
||||
}
|
||||
|
||||
QNetworkReply* reply = TomahawkUtils::nam()->head( QNetworkRequest( QUrl( m_url ) ) );
|
||||
NewClosure( reply, SIGNAL( finished() ), this, SLOT( headFinished( QNetworkReply* ) ) );
|
||||
check( m_url );
|
||||
}
|
||||
|
||||
WebResultHintChecker::~WebResultHintChecker()
|
||||
@@ -60,10 +60,28 @@ WebResultHintChecker::~WebResultHintChecker()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
WebResultHintChecker::check( const QString &url )
|
||||
{
|
||||
QNetworkReply* reply = TomahawkUtils::nam()->head( QNetworkRequest( QUrl( url ) ) );
|
||||
NewClosure( reply, SIGNAL( finished() ), this, SLOT( headFinished( QNetworkReply* ) ), reply );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
WebResultHintChecker::headFinished( QNetworkReply* reply )
|
||||
{
|
||||
if ( reply->error() != QNetworkReply::NoError )
|
||||
reply->deleteLater();
|
||||
|
||||
const QUrl redir = reply->attribute( QNetworkRequest::RedirectionTargetAttribute ).toUrl();
|
||||
if ( redir.isValid() )
|
||||
{
|
||||
const QUrl url = reply->url().resolved( redir );
|
||||
check( url.toString() );
|
||||
|
||||
return;
|
||||
}
|
||||
else if ( reply->error() != QNetworkReply::NoError )
|
||||
{
|
||||
// Error getting headers for the http resulthint, remove it from the result
|
||||
// as it's definitely not playable
|
||||
@@ -72,8 +90,8 @@ WebResultHintChecker::headFinished( QNetworkReply* reply )
|
||||
m_query->removeResult( m_result );
|
||||
if ( m_query->resultHint() == m_url )
|
||||
m_query->setResultHint( QString() );
|
||||
m_query->setSaveHTTPResultHint( false );
|
||||
}
|
||||
|
||||
reply->deleteLater();
|
||||
deleteLater();
|
||||
}
|
||||
|
@@ -37,6 +37,8 @@ private slots:
|
||||
void headFinished( QNetworkReply* reply );
|
||||
|
||||
private:
|
||||
void check( const QString& url );
|
||||
|
||||
query_ptr m_query;
|
||||
result_ptr m_result;
|
||||
QString m_url;
|
||||
|
Reference in New Issue
Block a user