1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-12 09:04:33 +02:00

Blacklist deezer redirects

This commit is contained in:
Uwe L. Korn
2013-07-23 09:22:36 +02:00
parent 58c3224b0a
commit 0af4b46c50
3 changed files with 26 additions and 2 deletions

View File

@@ -46,6 +46,13 @@ NetworkReply::~NetworkReply()
} }
void
NetworkReply::blacklistHostFromRedirection( const QString& host )
{
m_blacklistedHosts << host;
}
void void
NetworkReply::deletedByParent() NetworkReply::deletedByParent()
{ {
@@ -97,9 +104,17 @@ NetworkReply::networkLoadFinished()
if ( redir.isValid() && !redir.toUrl().isEmpty() ) if ( redir.isValid() && !redir.toUrl().isEmpty() )
{ {
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Redirected HTTP request to" << redir; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Redirected HTTP request to" << redir;
if ( m_blacklistedHosts.contains( redir.toUrl().host() ) )
{
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Reached blacklisted host, not redirecting anymore.";
emit finished();
}
else
{
load( redir.toUrl() ); load( redir.toUrl() );
emit redirected(); emit redirected();
} }
}
else else
emit finished(); emit finished();
} }

View File

@@ -21,6 +21,7 @@
#include <QObject> #include <QObject>
#include <QNetworkReply> #include <QNetworkReply>
#include <QStringList>
#include "Typedefs.h" #include "Typedefs.h"
@@ -34,6 +35,7 @@ public:
explicit NetworkReply( QNetworkReply* parent = 0 ); explicit NetworkReply( QNetworkReply* parent = 0 );
virtual ~NetworkReply(); virtual ~NetworkReply();
void blacklistHostFromRedirection( const QString& host );
QNetworkReply* reply() const { return m_reply; } QNetworkReply* reply() const { return m_reply; }
signals: signals:
@@ -49,6 +51,7 @@ private slots:
private: private:
void load( const QUrl& url ); void load( const QUrl& url );
QStringList m_blacklistedHosts;
QNetworkReply* m_reply; QNetworkReply* m_reply;
QUrl m_url; QUrl m_url;
}; };

View File

@@ -80,6 +80,12 @@ ShortenedLinkParser::lookupUrl( const QString& url )
cleaned.replace( "/#", "" ); cleaned.replace( "/#", "" );
NetworkReply* reply = new NetworkReply( Tomahawk::Utils::nam()->get( QNetworkRequest( QUrl( cleaned ) ) ) ); NetworkReply* reply = new NetworkReply( Tomahawk::Utils::nam()->get( QNetworkRequest( QUrl( cleaned ) ) ) );
// Deezer is doing a nasty redirect to /comingsoon in some countries.
// This removes valubale information from the URL.
reply->blacklistHostFromRedirection( "www.deezer.com" );
reply->blacklistHostFromRedirection( "deezer.com" );
connect( reply, SIGNAL( finished() ), SLOT( lookupFinished() ) ); connect( reply, SIGNAL( finished() ), SLOT( lookupFinished() ) );
m_queries.insert( reply ); m_queries.insert( reply );