diff --git a/src/infoplugins/generic/discogs/DiscogsPlugin.h b/src/infoplugins/generic/discogs/DiscogsPlugin.h index 654fe7e52..7471e2e11 100644 --- a/src/infoplugins/generic/discogs/DiscogsPlugin.h +++ b/src/infoplugins/generic/discogs/DiscogsPlugin.h @@ -59,5 +59,4 @@ private: } -Q_DECLARE_METATYPE( QNetworkReply* ) #endif diff --git a/src/libtomahawk/AtticaManager.h b/src/libtomahawk/AtticaManager.h index 51c20ff20..a0a0f5f69 100644 --- a/src/libtomahawk/AtticaManager.h +++ b/src/libtomahawk/AtticaManager.h @@ -177,5 +177,4 @@ protected: }; Q_DECLARE_METATYPE( Attica::Content ); -Q_DECLARE_METATYPE( QNetworkReply* ); #endif // ATTICAMANAGER_H diff --git a/src/libtomahawk/Typedefs.h b/src/libtomahawk/Typedefs.h index aad92ff9d..763ae8d32 100644 --- a/src/libtomahawk/Typedefs.h +++ b/src/libtomahawk/Typedefs.h @@ -28,6 +28,8 @@ //template 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 diff --git a/src/libtomahawk/utils/SoundcloudParser.cpp b/src/libtomahawk/utils/SoundcloudParser.cpp index 75241364a..6086250fc 100644 --- a/src/libtomahawk/utils/SoundcloudParser.cpp +++ b/src/libtomahawk/utils/SoundcloudParser.cpp @@ -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; } diff --git a/src/libtomahawk/utils/WebResultHintChecker.cpp b/src/libtomahawk/utils/WebResultHintChecker.cpp index 0ae06f08f..710fcbe5f 100644 --- a/src/libtomahawk/utils/WebResultHintChecker.cpp +++ b/src/libtomahawk/utils/WebResultHintChecker.cpp @@ -25,6 +25,7 @@ #include #include +#include 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(); } diff --git a/src/libtomahawk/utils/WebResultHintChecker.h b/src/libtomahawk/utils/WebResultHintChecker.h index 593d33fa3..92e5f306e 100644 --- a/src/libtomahawk/utils/WebResultHintChecker.h +++ b/src/libtomahawk/utils/WebResultHintChecker.h @@ -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;