mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-22 00:42:04 +02:00
Fix Bugs in GroovesharkParser & enable resolving of multiple redirects
This commit is contained in:
parent
bea98a5e30
commit
014c6e7344
src/libtomahawk/utils
@ -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 );
|
||||
|
@ -57,6 +57,7 @@ ShortenedLinkParser::handlesUrl( const QString& url )
|
||||
url.contains( "itun.es" ) ||
|
||||
url.contains( "tinyurl.com" ) ||
|
||||
url.contains( "tinysong.com" ) ||
|
||||
url.contains( "grooveshark.com" ) ||
|
||||
url.contains( "rd.io" ) );
|
||||
}
|
||||
|
||||
@ -85,14 +86,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();
|
||||
lengthenUrl( 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();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user