mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-11 08:34:34 +02:00
Merge pull request #73 from Horrendus/master
Fix Bugs handling Grooveshark Playlist URL Drops
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||||
* Copyright 2010-2011, Hugo Lindström <hugolm84@gmail.com>
|
* 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
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -91,33 +91,47 @@ GroovesharkParser::lookupGroovesharkPlaylist( const QString& linkRaw )
|
|||||||
{
|
{
|
||||||
tLog() << "Parsing Grooveshark Playlist URI:" << 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;
|
bool ok;
|
||||||
QString playlistStr = urlParts.last();
|
|
||||||
playlistStr.truncate(playlistStr.indexOf("?"));
|
QStringList urlParts = urlFragment.split( "/", QString::SkipEmptyParts );
|
||||||
int playlistID = playlistStr.toInt( &ok, 10 );
|
|
||||||
|
tDebug() << urlParts;
|
||||||
|
|
||||||
|
int playlistID = urlParts.at( 2 ).toInt( &ok, 10 );
|
||||||
if (!ok)
|
if (!ok)
|
||||||
{
|
{
|
||||||
tDebug() << "incorrect grooveshark url";
|
tDebug() << "incorrect grooveshark url";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_title = urlParts.at( urlParts.size()-2 );
|
|
||||||
|
|
||||||
|
m_title = urlParts.at( 1 );
|
||||||
|
|
||||||
tDebug() << "should get playlist " << playlistID;
|
tDebug() << "should get playlist " << playlistID;
|
||||||
|
|
||||||
DropJob::DropType type;
|
DropJob::DropType type;
|
||||||
|
|
||||||
if ( linkRaw.contains( "playlist" ) )
|
type = DropJob::Playlist;
|
||||||
type = DropJob::Playlist;
|
|
||||||
|
|
||||||
QString base_url( "http://api.grooveshark.com/ws3.php?sig=" );
|
QString base_url( "http://api.grooveshark.com/ws3.php?sig=" );
|
||||||
|
|
||||||
QByteArray data = QString( "{\"method\":\"getPlaylistSongs\",\"parameters\":{\"playlistID\":\"%1\"},\"header\":{\"wsKey\":\"tomahawkplayer\"}}" ).arg( playlistID ).toLocal8Bit();
|
QByteArray data = QString( "{\"method\":\"getPlaylistSongs\",\"parameters\":{\"playlistID\":\"%1\"},\"header\":{\"wsKey\":\"tomahawkplayer\"}}" ).arg( playlistID ).toLocal8Bit();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QCA::MessageAuthenticationCode hmac( "hmac(md5)", m_apiKey );
|
QCA::MessageAuthenticationCode hmac( "hmac(md5)", m_apiKey );
|
||||||
|
|
||||||
QCA::SecureArray secdata( data );
|
QCA::SecureArray secdata( data );
|
||||||
|
@@ -35,7 +35,8 @@ ShortenedLinkParser::ShortenedLinkParser ( const QStringList& urls, QObject* par
|
|||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
{
|
{
|
||||||
foreach ( const QString& url, urls )
|
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" ) );
|
url.contains( "rd.io" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ShortenedLinkParser::lengthenUrl( const QString& url )
|
ShortenedLinkParser::lookupUrl ( const QString& url )
|
||||||
{
|
{
|
||||||
if ( !handlesUrl( url ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
tDebug() << "Looking up..." << url;
|
tDebug() << "Looking up..." << url;
|
||||||
|
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( QUrl( url ) ) );
|
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( QUrl( url ) ) );
|
||||||
@@ -75,7 +72,6 @@ ShortenedLinkParser::lengthenUrl( const QString& url )
|
|||||||
m_queries.insert( reply );
|
m_queries.insert( reply );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ShortenedLinkParser::lookupFinished()
|
ShortenedLinkParser::lookupFinished()
|
||||||
{
|
{
|
||||||
@@ -85,14 +81,19 @@ ShortenedLinkParser::lookupFinished()
|
|||||||
QVariant redir = r->attribute( QNetworkRequest::RedirectionTargetAttribute );
|
QVariant redir = r->attribute( QNetworkRequest::RedirectionTargetAttribute );
|
||||||
if ( redir.isValid() && !redir.toUrl().isEmpty() )
|
if ( redir.isValid() && !redir.toUrl().isEmpty() )
|
||||||
{
|
{
|
||||||
tLog() << "Got a redirected url:" << redir.toUrl().toString();
|
tDebug() << "RedirectionTargetAttribute set on " << redir;
|
||||||
m_links << redir.toUrl().toString();
|
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -55,7 +55,7 @@ signals:
|
|||||||
void urls( const QStringList& urls );
|
void urls( const QStringList& urls );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void lengthenUrl( const QString& url );
|
void lookupUrl( const QString& url );
|
||||||
void checkFinished();
|
void checkFinished();
|
||||||
|
|
||||||
QStringList m_links;
|
QStringList m_links;
|
||||||
|
Reference in New Issue
Block a user