1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-09 15:47:38 +02:00

Merge pull request #73 from Horrendus/master

Fix Bugs handling Grooveshark Playlist URL Drops
This commit is contained in:
Leo Franchi
2012-01-04 08:41:00 -08:00
3 changed files with 44 additions and 29 deletions

View File

@@ -2,7 +2,7 @@
*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2011, Hugo Lindström <hugolm84@gmail.com>
* Copyright 2010-2011, Stefan Derkits <stefan@derkits.at>
* Copyright 2010-2012, Stefan Derkits <stefan@derkits.at>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -91,42 +91,56 @@ GroovesharkParser::lookupGroovesharkPlaylist( const QString& linkRaw )
{
tLog() << "Parsing Grooveshark Playlist URI:" << linkRaw;
QStringList urlParts = linkRaw.split( "/" );
QString urlFragment = QUrl( linkRaw ).fragment( );
if ( urlFragment.isEmpty() ) {
tDebug() << "no fragment, setting fragment to path";
urlFragment = QUrl(linkRaw).path();
}
tDebug() << urlFragment;
int paramStartingPostition = urlFragment.indexOf( "?" );
if ( paramStartingPostition != -1 )
urlFragment.truncate( paramStartingPostition );
bool ok;
QString playlistStr = urlParts.last();
playlistStr.truncate(playlistStr.indexOf("?"));
int playlistID = playlistStr.toInt( &ok, 10 );
QStringList urlParts = urlFragment.split( "/", QString::SkipEmptyParts );
tDebug() << urlParts;
int playlistID = urlParts.at( 2 ).toInt( &ok, 10 );
if (!ok)
{
tDebug() << "incorrect grooveshark url";
return;
}
m_title = urlParts.at( urlParts.size()-2 );
m_title = urlParts.at( 1 );
tDebug() << "should get playlist " << playlistID;
DropJob::DropType type;
if ( linkRaw.contains( "playlist" ) )
type = DropJob::Playlist;
type = DropJob::Playlist;
QString base_url( "http://api.grooveshark.com/ws3.php?sig=" );
QByteArray data = QString( "{\"method\":\"getPlaylistSongs\",\"parameters\":{\"playlistID\":\"%1\"},\"header\":{\"wsKey\":\"tomahawkplayer\"}}" ).arg( playlistID ).toLocal8Bit();
QCA::MessageAuthenticationCode hmac( "hmac(md5)", m_apiKey );
QCA::SecureArray secdata( data );
hmac.update(secdata);
QCA::SecureArray resultArray = hmac.final();
QString hash = QCA::arrayToHex( resultArray.toByteArray() );
QUrl url = QUrl( base_url + hash );
tDebug() << "Looking up URL..." << url.toString();
QNetworkReply* reply = TomahawkUtils::nam()->post( QNetworkRequest( url ), data );

View File

@@ -35,7 +35,8 @@ ShortenedLinkParser::ShortenedLinkParser ( const QStringList& urls, QObject* par
: QObject( parent )
{
foreach ( const QString& url, urls )
lengthenUrl( url );
if ( handlesUrl( url ) )
lookupUrl( url ) ;
}
@@ -60,13 +61,9 @@ ShortenedLinkParser::handlesUrl( const QString& url )
url.contains( "rd.io" ) );
}
void
ShortenedLinkParser::lengthenUrl( const QString& url )
ShortenedLinkParser::lookupUrl ( const QString& url )
{
if ( !handlesUrl( url ) )
return;
tDebug() << "Looking up..." << url;
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( QUrl( url ) ) );
@@ -75,7 +72,6 @@ ShortenedLinkParser::lengthenUrl( const QString& url )
m_queries.insert( reply );
}
void
ShortenedLinkParser::lookupFinished()
{
@@ -85,14 +81,19 @@ ShortenedLinkParser::lookupFinished()
QVariant redir = r->attribute( QNetworkRequest::RedirectionTargetAttribute );
if ( redir.isValid() && !redir.toUrl().isEmpty() )
{
tLog() << "Got a redirected url:" << redir.toUrl().toString();
m_links << redir.toUrl().toString();
tDebug() << "RedirectionTargetAttribute set on " << redir;
m_queries.remove( r );
r->deleteLater();
lookupUrl( redir.toUrl().toString() );
}
else
{
tLog() << "Got a redirected url:" << r->url().toString();
m_links << r->url().toString();
m_queries.remove( r );
r->deleteLater();
checkFinished();
}
r->deleteLater();
m_queries.remove( r );
checkFinished();
}

View File

@@ -55,7 +55,7 @@ signals:
void urls( const QStringList& urls );
private:
void lengthenUrl( const QString& url );
void lookupUrl( const QString& url );
void checkFinished();
QStringList m_links;