1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-09 07:36:48 +02:00

* All our link parsers now use our own NetworkReply instead of QNetworkReply.

This commit is contained in:
Christian Muehlhaeuser
2012-11-14 05:47:44 +01:00
parent f79468484b
commit 082f46f242
14 changed files with 207 additions and 246 deletions

View File

@@ -18,20 +18,20 @@
#include "ExfmParser.h" #include "ExfmParser.h"
#include "utils/Logger.h" #include <QtNetwork/QNetworkAccessManager>
#include "utils/TomahawkUtils.h"
#include "Query.h"
#include "SourceList.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#include "DropJobNotifier.h"
#include "ViewManager.h"
#include <qjson/parser.h> #include <qjson/parser.h>
#include <QtNetwork/QNetworkAccessManager> #include "Query.h"
#include <QtNetwork/QNetworkReply> #include "SourceList.h"
#include "DropJobNotifier.h"
#include "ViewManager.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#include "utils/NetworkReply.h"
#include "utils/TomahawkUtils.h"
#include "utils/Logger.h"
using namespace Tomahawk; using namespace Tomahawk;
@@ -72,7 +72,6 @@ ExfmParser::~ExfmParser()
void void
ExfmParser::lookupUrl( const QString& link ) ExfmParser::lookupUrl( const QString& link )
{ {
const QString apiBase = "http://ex.fm/api/v3"; const QString apiBase = "http://ex.fm/api/v3";
QString url( link ); QString url( link );
QStringList paths; QStringList paths;
@@ -117,34 +116,29 @@ ExfmParser::lookupUrl( const QString& link )
{ {
url.replace( "/genre/", "/tag/" ); url.replace( "/genre/", "/tag/" );
url.replace( "/search/", "/song/search/" ); // We can only search for tracks, even though we want an artist or whatever url.replace( "/search/", "/song/search/" ); // We can only search for tracks, even though we want an artist or whatever
} }
url.replace( "http://ex.fm", apiBase ); url.replace( "http://ex.fm", apiBase );
} }
tDebug() << "Looking up URL..." << url; tDebug() << "Looking up URL..." << url;
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( QUrl( url ) ) ); NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( QUrl( url ) ) ) );
if ( m_createNewPlaylist ) if ( m_createNewPlaylist )
connect( reply, SIGNAL( finished() ), this, SLOT( exfmLookupFinished() ) ); connect( reply, SIGNAL( finished() ), SLOT( exfmLookupFinished() ) );
else else
connect( reply, SIGNAL( finished() ), this, SLOT( exfmBrowseFinished() ) ); connect( reply, SIGNAL( finished() ), SLOT( exfmBrowseFinished() ) );
m_browseJob = new DropJobNotifier( pixmap(), "Exfm", m_type, reply ); m_browseJob = new DropJobNotifier( pixmap(), "Exfm", m_type, reply );
JobStatusView::instance()->model()->addJob( m_browseJob ); JobStatusView::instance()->model()->addJob( m_browseJob );
m_queries.insert( reply ); m_queries.insert( reply );
} }
void void
ExfmParser::parseTrack( const QVariantMap& res ) ExfmParser::parseTrack( const QVariantMap& res )
{ {
QString title, artist, album; QString title, artist, album;
album = res.value( "album", QString() ).toString(); album = res.value( "album", QString() ).toString();
title = res.value( "title", QString() ).toString(); title = res.value( "title", QString() ).toString();
@@ -165,34 +159,35 @@ ExfmParser::parseTrack( const QVariantMap& res )
q->setProperty( "annotation", res.value( "url" ).toString() ); q->setProperty( "annotation", res.value( "url" ).toString() );
m_tracks << q; m_tracks << q;
} }
} }
void void
ExfmParser::exfmLookupFinished() ExfmParser::exfmLookupFinished()
{ {
NetworkReply* r = qobject_cast< NetworkReply* >( sender() );
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() );
Q_ASSERT( r ); Q_ASSERT( r );
m_queries.remove( r ); m_queries.remove( r );
r->deleteLater(); r->deleteLater();
if ( r->error() == QNetworkReply::NoError ) if ( r->reply()->error() == QNetworkReply::NoError )
{ {
QJson::Parser p; QJson::Parser p;
bool ok; bool ok;
QVariantMap res = p.parse( r, &ok ).toMap(); QVariantMap res = p.parse( r->reply(), &ok ).toMap();
if ( !ok ) if ( !ok )
{ {
tLog() << "Failed to parse json from Exfm browse item :" << p.errorString() << "On line" << p.errorLine(); tLog() << "Failed to parse json from Exfm browse item:" << p.errorString() << "On line" << p.errorLine();
return; return;
} }
QStringList paths; QStringList paths;
foreach( const QString& path, r->url().path().split( "/" ) ) foreach ( const QString& path, r->reply()->url().path().split( "/" ) )
{
if ( !path.isEmpty() ) if ( !path.isEmpty() )
paths << path; paths << path;
}
QString title, artist, desc; QString title, artist, desc;
QVariantList tracks; QVariantList tracks;
@@ -243,30 +238,31 @@ ExfmParser::exfmLookupFinished()
connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistCreated() ) ); connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistCreated() ) );
return; return;
} }
} }
void void
ExfmParser::playlistCreated() ExfmParser::playlistCreated()
{ {
ViewManager::instance()->show( m_playlist ); ViewManager::instance()->show( m_playlist );
deleteLater(); deleteLater();
} }
void void
ExfmParser::exfmBrowseFinished() ExfmParser::exfmBrowseFinished()
{ {
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() ); NetworkReply* r = qobject_cast< NetworkReply* >( sender() );
Q_ASSERT( r ); Q_ASSERT( r );
r->deleteLater(); r->deleteLater();
if ( r->error() == QNetworkReply::NoError ) if ( r->reply()->error() == QNetworkReply::NoError )
{ {
QJson::Parser p; QJson::Parser p;
bool ok; bool ok;
QVariantMap res = p.parse( r, &ok ).toMap(); QVariantMap res = p.parse( r->reply(), &ok ).toMap();
if ( !ok ) if ( !ok )
{ {
@@ -295,9 +291,9 @@ ExfmParser::exfmBrowseFinished()
deleteLater(); deleteLater();
} }
} }
QPixmap QPixmap
ExfmParser::pixmap() const ExfmParser::pixmap() const
{ {

View File

@@ -34,7 +34,7 @@
* Connect to the signals to get the results * Connect to the signals to get the results
*/ */
class QNetworkReply; class NetworkReply;
namespace Tomahawk namespace Tomahawk
{ {
@@ -77,7 +77,7 @@ private:
int m_subscribers; int m_subscribers;
QList< query_ptr > m_tracks; QList< query_ptr > m_tracks;
QSet< QNetworkReply* > m_queries; QSet< NetworkReply* > m_queries;
Tomahawk::playlist_ptr m_playlist; Tomahawk::playlist_ptr m_playlist;
DropJobNotifier* m_browseJob; DropJobNotifier* m_browseJob;
DropJob::DropType m_type; DropJob::DropType m_type;

View File

@@ -20,29 +20,29 @@
#include "GroovesharkParser.h" #include "GroovesharkParser.h"
#include "utils/Logger.h"
#include "utils/TomahawkUtils.h"
#include "Query.h"
#include "SourceList.h"
#include "DropJob.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#include "DropJobNotifier.h"
#include "ViewManager.h"
#include <qjson/parser.h>
#include <QtCrypto> #include <QtCrypto>
#include <QCoreApplication> #include <QCoreApplication>
#include <QtNetwork/QNetworkAccessManager> #include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QWebPage> #include <QWebPage>
#include <QWebFrame> #include <QWebFrame>
#include <QWebElement> #include <QWebElement>
#include <qjson/parser.h>
#include "Query.h"
#include "SourceList.h"
#include "DropJob.h"
#include "DropJobNotifier.h"
#include "ViewManager.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#include "utils/NetworkReply.h"
#include "utils/TomahawkUtils.h"
#include "utils/Logger.h"
using namespace Tomahawk; using namespace Tomahawk;
QPixmap* GroovesharkParser::s_pixmap = 0; QPixmap* GroovesharkParser::s_pixmap = 0;
@@ -68,11 +68,12 @@ GroovesharkParser::GroovesharkParser( const QStringList& trackUrls, bool createN
lookupUrl( url ); lookupUrl( url );
} }
GroovesharkParser::~GroovesharkParser() GroovesharkParser::~GroovesharkParser()
{ {
} }
void void
GroovesharkParser::lookupUrl( const QString& link ) GroovesharkParser::lookupUrl( const QString& link )
{ {
@@ -89,7 +90,6 @@ GroovesharkParser::lookupUrl( const QString& link )
lookupGroovesharkTrack( link ); lookupGroovesharkTrack( link );
else else
return; return;
} }
@@ -104,41 +104,26 @@ GroovesharkParser::lookupGroovesharkPlaylist( const QString& linkRaw )
urlFragment = QUrl(linkRaw).path(); urlFragment = QUrl(linkRaw).path();
} }
tDebug() << urlFragment;
int paramStartingPostition = urlFragment.indexOf( "?" ); int paramStartingPostition = urlFragment.indexOf( "?" );
if ( paramStartingPostition != -1 ) if ( paramStartingPostition != -1 )
urlFragment.truncate( paramStartingPostition ); urlFragment.truncate( paramStartingPostition );
bool ok;
QStringList urlParts = urlFragment.split( "/", QString::SkipEmptyParts ); QStringList urlParts = urlFragment.split( "/", QString::SkipEmptyParts );
tDebug() << urlParts; bool ok;
int playlistID = urlParts.at( 2 ).toInt( &ok, 10 ); 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( 1 ); m_title = urlParts.at( 1 );
tDebug() << "should get playlist " << playlistID;
DropJob::DropType type; DropJob::DropType type;
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 );
@@ -148,10 +133,8 @@ GroovesharkParser::lookupGroovesharkPlaylist( const QString& linkRaw )
QString hash = QCA::arrayToHex( resultArray.toByteArray() ); QString hash = QCA::arrayToHex( resultArray.toByteArray() );
QUrl url = QUrl( base_url + hash ); QUrl url = QUrl( base_url + hash );
tDebug() << "Looking up URL..." << url.toString(); NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->post( QNetworkRequest( url ), data ) );
connect( reply, SIGNAL( finished() ), SLOT( groovesharkLookupFinished() ) );
QNetworkReply* reply = TomahawkUtils::nam()->post( QNetworkRequest( url ), data );
connect( reply, SIGNAL( finished() ), this, SLOT( groovesharkLookupFinished() ) );
m_browseJob = new DropJobNotifier( pixmap(), "Grooveshark", type, reply ); m_browseJob = new DropJobNotifier( pixmap(), "Grooveshark", type, reply );
JobStatusView::instance()->model()->addJob( m_browseJob ); JobStatusView::instance()->model()->addJob( m_browseJob );
@@ -165,8 +148,8 @@ GroovesharkParser::lookupGroovesharkTrack( const QString& track )
{ {
tLog() << "Parsing Grooveshark Track Page:" << track; tLog() << "Parsing Grooveshark Track Page:" << track;
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( QUrl( track ) ) ); NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( QUrl( track ) ) ) );
connect( reply, SIGNAL( finished() ), this, SLOT( trackPageFetchFinished() ) ); connect( reply, SIGNAL( finished() ), SLOT( trackPageFetchFinished() ) );
m_browseJob = new DropJobNotifier( pixmap(), "Grooveshark", DropJob::Track, reply ); m_browseJob = new DropJobNotifier( pixmap(), "Grooveshark", DropJob::Track, reply );
JobStatusView::instance()->model()->addJob( m_browseJob ); JobStatusView::instance()->model()->addJob( m_browseJob );
@@ -178,7 +161,7 @@ GroovesharkParser::lookupGroovesharkTrack( const QString& track )
void void
GroovesharkParser::trackPageFetchFinished() GroovesharkParser::trackPageFetchFinished()
{ {
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() ); NetworkReply* r = qobject_cast< NetworkReply* >( sender() );
Q_ASSERT( r ); Q_ASSERT( r );
m_queries.remove( r ); m_queries.remove( r );
@@ -189,7 +172,7 @@ GroovesharkParser::trackPageFetchFinished()
page.settings()->setAttribute( QWebSettings::PluginsEnabled, false ); page.settings()->setAttribute( QWebSettings::PluginsEnabled, false );
page.settings()->setAttribute( QWebSettings::JavaEnabled, false ); page.settings()->setAttribute( QWebSettings::JavaEnabled, false );
page.settings()->setAttribute( QWebSettings::AutoLoadImages, false ); page.settings()->setAttribute( QWebSettings::AutoLoadImages, false );
page.mainFrame()->setHtml( QString::fromUtf8( r->readAll() ) ); page.mainFrame()->setHtml( QString::fromUtf8( r->reply()->readAll() ) );
QWebElement title = page.mainFrame()->findFirstElement("span[itemprop='name']"); QWebElement title = page.mainFrame()->findFirstElement("span[itemprop='name']");
QWebElement artist = page.mainFrame()->findFirstElement("noscript span[itemprop='byArtist']"); QWebElement artist = page.mainFrame()->findFirstElement("noscript span[itemprop='byArtist']");
QWebElement album = page.mainFrame()->findFirstElement("noscript span[itemprop='inAlbum']"); QWebElement album = page.mainFrame()->findFirstElement("noscript span[itemprop='inAlbum']");
@@ -210,27 +193,27 @@ GroovesharkParser::trackPageFetchFinished()
void void
GroovesharkParser::groovesharkLookupFinished() GroovesharkParser::groovesharkLookupFinished()
{ {
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() ); NetworkReply* r = qobject_cast< NetworkReply* >( sender() );
Q_ASSERT( r ); Q_ASSERT( r );
m_queries.remove( r ); m_queries.remove( r );
r->deleteLater(); r->deleteLater();
if ( r->error() == QNetworkReply::NoError ) if ( r->reply()->error() == QNetworkReply::NoError )
{ {
QJson::Parser p; QJson::Parser p;
bool ok; bool ok;
QVariantMap res = p.parse( r, &ok ).toMap(); QVariantMap res = p.parse( r->reply(), &ok ).toMap();
if ( !ok ) if ( !ok )
{ {
tLog() << "Failed to parse json from Grooveshark browse item :" << p.errorString() << "On line" << p.errorLine(); tLog() << "Failed to parse json from Grooveshark browse item:" << p.errorString() << "On line" << p.errorLine();
checkTrackFinished(); checkTrackFinished();
return; return;
} }
QVariantList list = res.value( "result" ).toMap().value( "songs" ).toList(); QVariantList list = res.value( "result" ).toMap().value( "songs" ).toList();
foreach (const QVariant& var, list) foreach ( const QVariant& var, list )
{ {
QVariantMap trackResult = var.toMap(); QVariantMap trackResult = var.toMap();
@@ -249,12 +232,11 @@ GroovesharkParser::groovesharkLookupFinished()
Tomahawk::query_ptr q = Tomahawk::Query::get( artist, title, album, uuid(), m_trackMode ); Tomahawk::query_ptr q = Tomahawk::Query::get( artist, title, album, uuid(), m_trackMode );
m_tracks << q; m_tracks << q;
} }
}
else
} else
{ {
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Error fetching Grooveshark information from the network!" ) ) ); JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Error fetching Grooveshark information from the network!" ) ) );
tLog() << "Error in network request to grooveshark for track decoding:" << r->errorString(); tLog() << "Error in network request to grooveshark for track decoding:" << r->reply()->errorString();
} }
if ( m_trackMode ) if ( m_trackMode )
@@ -263,6 +245,7 @@ GroovesharkParser::groovesharkLookupFinished()
checkPlaylistFinished(); checkPlaylistFinished();
} }
void void
GroovesharkParser::checkPlaylistFinished() GroovesharkParser::checkPlaylistFinished()
{ {
@@ -285,13 +268,12 @@ GroovesharkParser::checkPlaylistFinished()
return; return;
} }
emit tracks( m_tracks ); emit tracks( m_tracks );
deleteLater(); deleteLater();
} }
} }
void void
GroovesharkParser::checkTrackFinished() GroovesharkParser::checkTrackFinished()
{ {
@@ -305,13 +287,12 @@ GroovesharkParser::checkTrackFinished()
deleteLater(); deleteLater();
} }
} }
void void
GroovesharkParser::playlistCreated() GroovesharkParser::playlistCreated()
{ {
ViewManager::instance()->show( m_playlist ); ViewManager::instance()->show( m_playlist );
deleteLater(); deleteLater();

View File

@@ -38,7 +38,7 @@
* Connect to the signals to get the results * Connect to the signals to get the results
*/ */
class QNetworkReply; class NetworkReply;
namespace Tomahawk namespace Tomahawk
{ {
@@ -74,7 +74,7 @@ private:
bool m_trackMode; bool m_trackMode;
bool m_createNewPlaylist; bool m_createNewPlaylist;
QList< query_ptr > m_tracks; QList< query_ptr > m_tracks;
QSet< QNetworkReply* > m_queries; QSet< NetworkReply* > m_queries;
QString m_title, m_info, m_creator; QString m_title, m_info, m_creator;
Tomahawk::playlist_ptr m_playlist; Tomahawk::playlist_ptr m_playlist;
DropJobNotifier* m_browseJob; DropJobNotifier* m_browseJob;
@@ -82,7 +82,6 @@ private:
QCA::SymmetricKey m_apiKey; QCA::SymmetricKey m_apiKey;
static QPixmap* s_pixmap; static QPixmap* s_pixmap;
}; };
} }

View File

@@ -19,19 +19,20 @@
*/ */
#include "ItunesParser.h" #include "ItunesParser.h"
#include "utils/Logger.h"
#include "utils/TomahawkUtils.h" #include <QtNetwork/QNetworkAccessManager>
#include <QRegExp>
#include <qjson/parser.h>
#include "Query.h" #include "Query.h"
#include "SourceList.h" #include "SourceList.h"
#include "jobview/JobStatusView.h" #include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h" #include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h" #include "jobview/ErrorStatusMessage.h"
#include "utils/NetworkReply.h"
#include <qjson/parser.h> #include "utils/TomahawkUtils.h"
#include "utils/Logger.h"
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QRegExp>
using namespace Tomahawk; using namespace Tomahawk;
@@ -91,7 +92,6 @@ ItunesParser::lookupItunesUri( const QString& link )
else else
return; return;
} }
tLog() << "Parsing itunes track:" << link;
QUrl url; QUrl url;
DropJob::DropType type; DropJob::DropType type;
@@ -105,10 +105,9 @@ ItunesParser::lookupItunesUri( const QString& link )
type = ( trackId.isEmpty() ? DropJob::Album : DropJob::Track ); type = ( trackId.isEmpty() ? DropJob::Album : DropJob::Track );
url = QUrl( QString( "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsLookup?id=%1&entity=song" ).arg( ( trackId.isEmpty() ? id : trackId ) ) ); url = QUrl( QString( "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsLookup?id=%1&entity=song" ).arg( ( trackId.isEmpty() ? id : trackId ) ) );
} }
qDebug() << "Looking up..." << url.toString();
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( url ) ) );
connect( reply, SIGNAL( finished() ), this, SLOT( itunesResponseLookupFinished() ) ); connect( reply, SIGNAL( finished() ), SLOT( itunesResponseLookupFinished() ) );
DropJobNotifier* j = new DropJobNotifier( pixmap(), QString( "Itunes" ), type, reply ); DropJobNotifier* j = new DropJobNotifier( pixmap(), QString( "Itunes" ), type, reply );
JobStatusView::instance()->model()->addJob( j ); JobStatusView::instance()->model()->addJob( j );
@@ -120,16 +119,16 @@ ItunesParser::lookupItunesUri( const QString& link )
void void
ItunesParser::itunesResponseLookupFinished() ItunesParser::itunesResponseLookupFinished()
{ {
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() ); NetworkReply* r = qobject_cast< NetworkReply* >( sender() );
Q_ASSERT( r ); Q_ASSERT( r );
m_queries.remove( r ); m_queries.remove( r );
r->deleteLater(); r->deleteLater();
if ( r->error() == QNetworkReply::NoError ) if ( r->reply()->error() == QNetworkReply::NoError )
{ {
QJson::Parser p; QJson::Parser p;
bool ok; bool ok;
QVariantMap res = p.parse( r, &ok ).toMap(); QVariantMap res = p.parse( r->reply(), &ok ).toMap();
if ( !ok ) if ( !ok )
{ {
@@ -173,7 +172,7 @@ ItunesParser::itunesResponseLookupFinished()
else else
{ {
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Error fetching iTunes information from the network!" ) ) ); JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Error fetching iTunes information from the network!" ) ) );
tLog() << "Error in network request to Itunes for track decoding:" << r->errorString(); tLog() << "Error in network request to Itunes for track decoding:" << r->reply()->errorString();
} }
checkTrackFinished(); checkTrackFinished();

View File

@@ -30,7 +30,7 @@
#include <QSet> #include <QSet>
#include <QtCore/QStringList> #include <QtCore/QStringList>
class QNetworkReply; class NetworkReply;
class TrackModel; class TrackModel;
namespace Tomahawk namespace Tomahawk
@@ -63,7 +63,7 @@ private:
bool m_single; bool m_single;
QList< query_ptr > m_tracks; QList< query_ptr > m_tracks;
QSet< QNetworkReply* > m_queries; QSet< NetworkReply* > m_queries;
QString m_title, m_info, m_creator; QString m_title, m_info, m_creator;
Tomahawk::playlist_ptr m_playlist; Tomahawk::playlist_ptr m_playlist;

View File

@@ -19,27 +19,28 @@
#include "RdioParser.h" #include "RdioParser.h"
#include "ShortenedLinkParser.h"
#include "config.h"
#include "utils/TomahawkUtils.h"
#include "utils/Logger.h"
#include "DropJob.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#include "DropJobNotifier.h"
#include "ViewManager.h"
#include "SourceList.h"
#include <qjson/parser.h>
#include <QDateTime> #include <QDateTime>
#include <QtNetwork/QNetworkAccessManager> #include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QUrl> #include <QUrl>
#include <QStringList> #include <QStringList>
#include <QtCore/QCryptographicHash> #include <QtCore/QCryptographicHash>
#include <qjson/parser.h>
#include "ShortenedLinkParser.h"
#include "config.h"
#include "DropJob.h"
#include "DropJobNotifier.h"
#include "ViewManager.h"
#include "SourceList.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#include "utils/NetworkReply.h"
#include "utils/TomahawkUtils.h"
#include "utils/Logger.h"
using namespace Tomahawk; using namespace Tomahawk;
QPixmap* RdioParser::s_pixmap = 0; QPixmap* RdioParser::s_pixmap = 0;
@@ -78,7 +79,7 @@ RdioParser::parse( const QStringList& urls )
m_multi = true; m_multi = true;
m_total = urls.count(); m_total = urls.count();
foreach( const QString& url, urls ) foreach ( const QString& url, urls )
parseUrl( url ); parseUrl( url );
} }
@@ -129,8 +130,8 @@ RdioParser::fetchObjectsFromUrl( const QString& url, DropJob::DropType type )
QNetworkRequest request = generateRequest( "getObjectFromUrl", cleanedUrl, params, &data ); QNetworkRequest request = generateRequest( "getObjectFromUrl", cleanedUrl, params, &data );
request.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1String( "application/x-www-form-urlencoded" ) ); request.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1String( "application/x-www-form-urlencoded" ) );
QNetworkReply* reply = TomahawkUtils::nam()->post( request, data ); NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->post( request, data ) );
connect( reply, SIGNAL( finished() ), this, SLOT( rdioReturned() ) ); connect( reply, SIGNAL( finished() ), SLOT( rdioReturned() ) );
m_browseJob = new DropJobNotifier( pixmap(), QString( "Rdio" ), type, reply ); m_browseJob = new DropJobNotifier( pixmap(), QString( "Rdio" ), type, reply );
JobStatusView::instance()->model()->addJob( m_browseJob ); JobStatusView::instance()->model()->addJob( m_browseJob );
@@ -142,22 +143,22 @@ RdioParser::fetchObjectsFromUrl( const QString& url, DropJob::DropType type )
void void
RdioParser::rdioReturned() RdioParser::rdioReturned()
{ {
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() ); NetworkReply* r = qobject_cast< NetworkReply* >( sender() );
Q_ASSERT( r ); Q_ASSERT( r );
m_reqQueries.remove( r ); m_reqQueries.remove( r );
m_count++; m_count++;
r->deleteLater(); r->deleteLater();
if ( r->error() == QNetworkReply::NoError ) if ( r->reply()->error() == QNetworkReply::NoError )
{ {
QJson::Parser p; QJson::Parser p;
bool ok; bool ok;
QVariantMap res = p.parse( r, &ok ).toMap(); QVariantMap res = p.parse( r->reply(), &ok ).toMap();
QVariantMap result = res.value( "result" ).toMap(); QVariantMap result = res.value( "result" ).toMap();
if ( !ok || result.isEmpty() ) if ( !ok || result.isEmpty() )
{ {
tLog() << "Failed to parse json from Rdio browse item :" << p.errorString() << "On line" << p.errorLine() << "With data:" << res; tLog() << "Failed to parse json from Rdio browse item:" << p.errorString() << "On line" << p.errorLine() << "With data:" << res;
return; return;
} }
@@ -198,7 +199,7 @@ RdioParser::rdioReturned()
else else
{ {
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Error fetching Rdio information from the network!" ) ) ); JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Error fetching Rdio information from the network!" ) ) );
tLog() << "Error in network request to Rdio for track decoding:" << r->errorString(); tLog() << "Error in network request to Rdio for track decoding:" << r->reply()->errorString();
} }
checkFinished(); checkFinished();
@@ -256,7 +257,7 @@ RdioParser::generateRequest( const QString& method, const QString& url, const QL
QUrl toSignUrl = fetchUrl; QUrl toSignUrl = fetchUrl;
QPair<QByteArray, QByteArray> param; QPair<QByteArray, QByteArray> param;
foreach( param, extraParams ) foreach ( param, extraParams )
{ {
toSignUrl.addEncodedQueryItem( param.first, param.second ); toSignUrl.addEncodedQueryItem( param.first, param.second );
} }
@@ -290,8 +291,6 @@ RdioParser::generateRequest( const QString& method, const QString& url, const QL
} }
data->truncate( data->size() - 1 ); // remove extra & data->truncate( data->size() - 1 ); // remove extra &
qDebug() << "POST data:" << *data;
QNetworkRequest request = QNetworkRequest( fetchUrl ); QNetworkRequest request = QNetworkRequest( fetchUrl );
request.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1String( "application/x-www-form-urlencoded" ) ); request.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1String( "application/x-www-form-urlencoded" ) );

View File

@@ -37,11 +37,13 @@
#include <QtCrypto> #include <QtCrypto>
#endif #endif
class QNetworkReply; class NetworkReply;
namespace Tomahawk namespace Tomahawk
{ {
class DropJobNotifier; class DropJobNotifier;
/** /**
* Small class to parse spotify links into query_ptrs * Small class to parse spotify links into query_ptrs
* *
@@ -82,7 +84,7 @@ private:
bool m_multi; bool m_multi;
int m_count, m_total; int m_count, m_total;
QSet< QNetworkReply* > m_reqQueries; QSet< NetworkReply* > m_reqQueries;
DropJobNotifier* m_browseJob; DropJobNotifier* m_browseJob;
QString m_title, m_creator; QString m_title, m_creator;

View File

@@ -19,24 +19,25 @@
#include "ShortenedLinkParser.h" #include "ShortenedLinkParser.h"
#include "utils/Logger.h"
#include "utils/TomahawkUtils.h"
#include "DropJobNotifier.h"
#include "Query.h"
#include "jobview/ErrorStatusMessage.h"
#include "jobview/JobStatusModel.h"
#include "jobview/JobStatusView.h"
#include "Source.h"
#include <qjson/parser.h> #include <qjson/parser.h>
#include <QtNetwork/QNetworkAccessManager> #include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include "DropJobNotifier.h"
#include "Query.h"
#include "Source.h"
#include "jobview/ErrorStatusMessage.h"
#include "jobview/JobStatusModel.h"
#include "jobview/JobStatusView.h"
#include "utils/NetworkReply.h"
#include "utils/TomahawkUtils.h"
#include "utils/Logger.h"
using namespace Tomahawk; using namespace Tomahawk;
QPixmap* ShortenedLinkParser::s_pixmap = 0; QPixmap* ShortenedLinkParser::s_pixmap = 0;
ShortenedLinkParser::ShortenedLinkParser ( const QStringList& urls, QObject* parent ) ShortenedLinkParser::ShortenedLinkParser ( const QStringList& urls, QObject* parent )
: QObject( parent ) : QObject( parent )
{ {
@@ -74,47 +75,36 @@ ShortenedLinkParser::handlesUrl( const QString& url )
void void
ShortenedLinkParser::lookupUrl( const QString& url ) ShortenedLinkParser::lookupUrl( const QString& url )
{ {
tDebug() << "Looking up..." << url; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Looking up..." << url;
QString cleaned = url; QString cleaned = url;
if ( cleaned.contains( "/#/s/" ) ) if ( cleaned.contains( "/#/s/" ) )
cleaned.replace( "/#", "" ); cleaned.replace( "/#", "" );
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( QUrl( cleaned ) ) ); NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( QUrl( cleaned ) ) ) );
connect( reply, SIGNAL( finished() ), this, SLOT( lookupFinished() ) ); connect( reply, SIGNAL( finished() ), SLOT( lookupFinished() ) );
m_queries.insert( reply ); m_queries.insert( reply );
m_expandJob = new DropJobNotifier( pixmap(), "shortened", DropJob::Track, reply ); m_expandJob = new DropJobNotifier( pixmap(), "shortened", DropJob::Track, reply );
JobStatusView::instance()->model()->addJob( m_expandJob ); JobStatusView::instance()->model()->addJob( m_expandJob );
} }
void void
ShortenedLinkParser::lookupFinished() ShortenedLinkParser::lookupFinished()
{ {
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() ); NetworkReply* r = qobject_cast< NetworkReply* >( sender() );
Q_ASSERT( r ); Q_ASSERT( r );
if ( r->error() != QNetworkReply::NoError ) if ( r->reply()->error() != QNetworkReply::NoError )
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Network error parsing shortened link!" ) ) ); JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Network error parsing shortened link!" ) ) );
QVariant redir = r->attribute( QNetworkRequest::RedirectionTargetAttribute ); tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Got an un-shortened url:" << r->reply()->url().toString();
if ( redir.isValid() && !redir.toUrl().isEmpty() ) m_links << r->reply()->url().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 ); m_queries.remove( r );
r->deleteLater(); r->deleteLater();
checkFinished(); checkFinished();
}
} }
@@ -123,7 +113,6 @@ ShortenedLinkParser::checkFinished()
{ {
if ( m_queries.isEmpty() ) // we're done if ( m_queries.isEmpty() ) // we're done
{ {
qDebug() << "DONE and found redirected urls:" << m_links;
emit urls( m_links ); emit urls( m_links );
deleteLater(); deleteLater();

View File

@@ -31,7 +31,7 @@
#include <QPixmap> #include <QPixmap>
#endif #endif
class QNetworkReply; class NetworkReply;
namespace Tomahawk namespace Tomahawk
{ {
@@ -70,7 +70,7 @@ private:
#endif #endif
QStringList m_links; QStringList m_links;
QSet< QNetworkReply* > m_queries; QSet< NetworkReply* > m_queries;
DropJobNotifier* m_expandJob; DropJobNotifier* m_expandJob;
}; };

View File

@@ -18,20 +18,20 @@
#include "SoundcloudParser.h" #include "SoundcloudParser.h"
#include "utils/Logger.h" #include <QtNetwork/QNetworkAccessManager>
#include "utils/TomahawkUtils.h"
#include "Query.h"
#include "SourceList.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#include "DropJobNotifier.h"
#include "ViewManager.h"
#include <qjson/parser.h> #include <qjson/parser.h>
#include <QtNetwork/QNetworkAccessManager> #include "Query.h"
#include <QtNetwork/QNetworkReply> #include "SourceList.h"
#include "DropJobNotifier.h"
#include "ViewManager.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#include "utils/NetworkReply.h"
#include "utils/TomahawkUtils.h"
#include "utils/Logger.h"
using namespace Tomahawk; using namespace Tomahawk;
@@ -74,21 +74,20 @@ SoundcloudParser::lookupUrl( const QString& link )
{ {
tDebug() << "Looking up URL..." << link; tDebug() << "Looking up URL..." << link;
QUrl scLink( QString( "http://api.soundcloud.com/resolve.json?client_id=TiNg2DRYhBnp01DA3zNag&url=" ) + link ); QUrl scLink( QString( "http://api.soundcloud.com/resolve.json?client_id=TiNg2DRYhBnp01DA3zNag&url=" ) + link );
qDebug() << scLink.toString();
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( scLink ) ); NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( scLink ) ) );
connect( reply, SIGNAL( finished() ), this, SLOT( soundcloudBrowseFinished() ) ); connect( reply, SIGNAL( finished() ), SLOT( soundcloudBrowseFinished() ) );
m_browseJob = new DropJobNotifier( pixmap(), "Soundcloud", DropJob::All, reply ); m_browseJob = new DropJobNotifier( pixmap(), "Soundcloud", DropJob::All, reply );
JobStatusView::instance()->model()->addJob( m_browseJob ); JobStatusView::instance()->model()->addJob( m_browseJob );
m_queries.insert( reply ); m_queries.insert( reply );
} }
void void
SoundcloudParser::parseTrack( const QVariantMap& res ) SoundcloudParser::parseTrack( const QVariantMap& res )
{ {
QString title, artist; QString title, artist;
title = res.value( "title", QString() ).toString(); title = res.value( "title", QString() ).toString();
artist = res.value( "user" ).toMap().value( "username", QString() ).toString(); artist = res.value( "user" ).toMap().value( "username", QString() ).toString();
@@ -110,27 +109,26 @@ SoundcloudParser::parseTrack( const QVariantMap& res )
q->setSaveHTTPResultHint( true ); q->setSaveHTTPResultHint( true );
m_tracks << q; m_tracks << q;
} }
} }
void void
SoundcloudParser::soundcloudLookupFinished() SoundcloudParser::soundcloudLookupFinished()
{ {
NetworkReply* r = qobject_cast< NetworkReply* >( sender() );
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() );
Q_ASSERT( r ); Q_ASSERT( r );
m_queries.remove( r ); m_queries.remove( r );
r->deleteLater(); r->deleteLater();
if ( r->error() == QNetworkReply::NoError ) if ( r->reply()->error() == QNetworkReply::NoError )
{ {
QJson::Parser p; QJson::Parser p;
bool ok; bool ok;
QVariantMap res = p.parse( r, &ok ).toMap(); QVariantMap res = p.parse( r->reply(), &ok ).toMap();
if ( !ok ) if ( !ok )
{ {
tLog() << "Failed to parse json from Soundcloud browse item :" << p.errorString() << "On line" << p.errorLine(); tLog() << "Failed to parse json from Soundcloud browse item:" << p.errorString() << "On line" << p.errorLine();
return; return;
} }
@@ -163,13 +161,11 @@ SoundcloudParser::soundcloudLookupFinished()
connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistCreated() ) ); connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistCreated() ) );
return; return;
} }
} }
else if ( m_type == DropJob::Artist ) else if ( m_type == DropJob::Artist )
{ {
// cant parse soundcloud json here atm. // cant parse soundcloud json here atm.
} }
} }
if ( m_single && !m_tracks.isEmpty() ) if ( m_single && !m_tracks.isEmpty() )
@@ -178,29 +174,31 @@ SoundcloudParser::soundcloudLookupFinished()
emit tracks( m_tracks ); emit tracks( m_tracks );
deleteLater(); deleteLater();
} }
void void
SoundcloudParser::playlistCreated() SoundcloudParser::playlistCreated()
{ {
ViewManager::instance()->show( m_playlist ); ViewManager::instance()->show( m_playlist );
deleteLater(); deleteLater();
} }
void void
SoundcloudParser::soundcloudBrowseFinished() SoundcloudParser::soundcloudBrowseFinished()
{ {
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() ); NetworkReply* r = qobject_cast< NetworkReply* >( sender() );
Q_ASSERT( r ); Q_ASSERT( r );
r->deleteLater(); r->deleteLater();
if ( r->error() == QNetworkReply::NoError ) if ( r->reply()->error() == QNetworkReply::NoError )
{ {
if ( r->rawHeaderList().contains( "Location" ) ) if ( r->reply()->rawHeaderList().contains( "Location" ) )
{ {
QString url = r->rawHeader("Location"); QString url = r->reply()->rawHeader( "Location" );
if ( url.contains( "tracks" ) ) if ( url.contains( "tracks" ) )
{ {
m_type = DropJob::Track; m_type = DropJob::Track;
@@ -210,8 +208,7 @@ SoundcloudParser::soundcloudBrowseFinished()
// For now, dont handle user tracklists // For now, dont handle user tracklists
m_type = DropJob::All; //DropJob::Artist; m_type = DropJob::All; //DropJob::Artist;
url = url.replace( ".json", "/tracks.json" ); url = url.replace( ".json", "/tracks.json" );
qDebug() << "Gots artist!" << url; }
}
else if ( url.contains( "playlists" ) ) else if ( url.contains( "playlists" ) )
{ {
m_type = DropJob::Playlist; m_type = DropJob::Playlist;
@@ -219,8 +216,8 @@ SoundcloudParser::soundcloudBrowseFinished()
if ( m_type != DropJob::All ) if ( m_type != DropJob::All )
{ {
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( QUrl(url) ) ); NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( QUrl( url ) ) ) );
connect( reply, SIGNAL( finished() ), this, SLOT( soundcloudLookupFinished() ) ); connect( reply, SIGNAL( finished() ), SLOT( soundcloudLookupFinished() ) );
} }
} }
} }
@@ -233,9 +230,9 @@ SoundcloudParser::soundcloudBrowseFinished()
m_browseJob->setFinished(); m_browseJob->setFinished();
return; return;
} }
} }
QPixmap QPixmap
SoundcloudParser::pixmap() const SoundcloudParser::pixmap() const
{ {

View File

@@ -20,14 +20,15 @@
#ifndef Soundcloud_PARSER_H #ifndef Soundcloud_PARSER_H
#define Soundcloud_PARSER_H #define Soundcloud_PARSER_H
#include "DllMacro.h" #include <QObject>
#include <QtCore/QStringList>
#include "Typedefs.h" #include "Typedefs.h"
#include "Query.h" #include "Query.h"
#include "DropJob.h" #include "DropJob.h"
#include "jobview/JobStatusItem.h" #include "jobview/JobStatusItem.h"
#include <QObject>
#include <QtCore/QStringList>
#include "DllMacro.h"
/** /**
* Small class to parse Soundcloud links into query_ptrs * Small class to parse Soundcloud links into query_ptrs
@@ -35,7 +36,8 @@
* Connect to the signals to get the results * Connect to the signals to get the results
*/ */
class QNetworkReply; class NetworkReply;
namespace Tomahawk namespace Tomahawk
{ {
@@ -77,7 +79,7 @@ private:
int m_subscribers; int m_subscribers;
QList< query_ptr > m_tracks; QList< query_ptr > m_tracks;
QSet< QNetworkReply* > m_queries; QSet< NetworkReply* > m_queries;
Tomahawk::playlist_ptr m_playlist; Tomahawk::playlist_ptr m_playlist;
DropJobNotifier* m_browseJob; DropJobNotifier* m_browseJob;
DropJob::DropType m_type; DropJob::DropType m_type;

View File

@@ -19,21 +19,21 @@
#include "SpotifyParser.h" #include "SpotifyParser.h"
#include "utils/Logger.h" #include <QtNetwork/QNetworkAccessManager>
#include "utils/TomahawkUtils.h"
#include "Query.h"
#include "SourceList.h"
#include "DropJob.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#include "DropJobNotifier.h"
#include "ViewManager.h"
#include <qjson/parser.h> #include <qjson/parser.h>
#include <QtNetwork/QNetworkAccessManager> #include "Query.h"
#include <QtNetwork/QNetworkReply> #include "SourceList.h"
#include "DropJob.h"
#include "DropJobNotifier.h"
#include "ViewManager.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#include "utils/NetworkReply.h"
#include "utils/TomahawkUtils.h"
#include "utils/Logger.h"
using namespace Tomahawk; using namespace Tomahawk;
@@ -49,7 +49,6 @@ SpotifyParser::SpotifyParser( const QStringList& Urls, bool createNewPlaylist, Q
, m_createNewPlaylist( createNewPlaylist ) , m_createNewPlaylist( createNewPlaylist )
, m_browseJob( 0 ) , m_browseJob( 0 )
, m_subscribers( 0 ) , m_subscribers( 0 )
{ {
foreach ( const QString& url, Urls ) foreach ( const QString& url, Urls )
lookupUrl( url ); lookupUrl( url );
@@ -141,15 +140,14 @@ SpotifyParser::lookupSpotifyBrowse( const QString& linkRaw )
QUrl url; QUrl url;
if( type != DropJob::Artist ) if ( type != DropJob::Artist )
url = QUrl( QString( SPOTIFY_PLAYLIST_API_URL "/browse/%1" ).arg( m_browseUri ) ); url = QUrl( QString( SPOTIFY_PLAYLIST_API_URL "/browse/%1" ).arg( m_browseUri ) );
else else
url = QUrl( QString( SPOTIFY_PLAYLIST_API_URL "/browse/%1/%2" ).arg( m_browseUri ) url = QUrl( QString( SPOTIFY_PLAYLIST_API_URL "/browse/%1/%2" ).arg( m_browseUri )
.arg ( m_limit ) ); .arg ( m_limit ) );
tDebug() << "Looking up URL..." << url.toString();
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( url ) ) );
connect( reply, SIGNAL( finished() ), this, SLOT( spotifyBrowseFinished() ) ); connect( reply, SIGNAL( finished() ), SLOT( spotifyBrowseFinished() ) );
m_browseJob = new DropJobNotifier( pixmap(), "Spotify", type, reply ); m_browseJob = new DropJobNotifier( pixmap(), "Spotify", type, reply );
JobStatusView::instance()->model()->addJob( m_browseJob ); JobStatusView::instance()->model()->addJob( m_browseJob );
@@ -161,8 +159,7 @@ SpotifyParser::lookupSpotifyBrowse( const QString& linkRaw )
void void
SpotifyParser::lookupTrack( const QString& link ) SpotifyParser::lookupTrack( const QString& link )
{ {
tDebug() << "Got a QString " << link; if ( !link.contains( "track" ) ) // we only support track links atm
if ( !link.contains( "track" )) // we only support track links atm
return; return;
// we need Spotify URIs such as spotify:track:XXXXXX, so if we by chance get a http://open.spotify.com url, convert it // we need Spotify URIs such as spotify:track:XXXXXX, so if we by chance get a http://open.spotify.com url, convert it
@@ -175,10 +172,9 @@ SpotifyParser::lookupTrack( const QString& link )
} }
QUrl url = QUrl( QString( "http://ws.spotify.com/lookup/1/.json?uri=%1" ).arg( uri ) ); QUrl url = QUrl( QString( "http://ws.spotify.com/lookup/1/.json?uri=%1" ).arg( uri ) );
tDebug() << "Looking up URL..." << url.toString();
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( url ) ) );
connect( reply, SIGNAL( finished() ), this, SLOT( spotifyTrackLookupFinished() ) ); connect( reply, SIGNAL( finished() ), SLOT( spotifyTrackLookupFinished() ) );
DropJobNotifier* j = new DropJobNotifier( pixmap(), QString( "Spotify" ), DropJob::Track, reply ); DropJobNotifier* j = new DropJobNotifier( pixmap(), QString( "Spotify" ), DropJob::Track, reply );
JobStatusView::instance()->model()->addJob( j ); JobStatusView::instance()->model()->addJob( j );
@@ -190,21 +186,21 @@ SpotifyParser::lookupTrack( const QString& link )
void void
SpotifyParser::spotifyBrowseFinished() SpotifyParser::spotifyBrowseFinished()
{ {
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() ); NetworkReply* r = qobject_cast< NetworkReply* >( sender() );
Q_ASSERT( r ); Q_ASSERT( r );
m_queries.remove( r ); m_queries.remove( r );
r->deleteLater(); r->deleteLater();
if ( r->error() == QNetworkReply::NoError ) if ( r->reply()->error() == QNetworkReply::NoError )
{ {
QJson::Parser p; QJson::Parser p;
bool ok; bool ok;
QVariantMap res = p.parse( r, &ok ).toMap(); QVariantMap res = p.parse( r->reply(), &ok ).toMap();
if ( !ok ) if ( !ok )
{ {
tLog() << "Failed to parse json from Spotify browse item :" << p.errorString() << "On line" << p.errorLine(); tLog() << "Failed to parse json from Spotify browse item:" << p.errorString() << "On line" << p.errorLine();
checkTrackFinished(); checkTrackFinished();
return; return;
} }
@@ -250,7 +246,7 @@ SpotifyParser::spotifyBrowseFinished()
else else
{ {
JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Error fetching Spotify information from the network!" ) ) ); JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "Error fetching Spotify information from the network!" ) ) );
tLog() << "Error in network request to Spotify for track decoding:" << r->errorString(); tLog() << "Error in network request to Spotify for track decoding:" << r->reply()->errorString();
} }
if ( m_trackMode ) if ( m_trackMode )
@@ -263,16 +259,16 @@ SpotifyParser::spotifyBrowseFinished()
void void
SpotifyParser::spotifyTrackLookupFinished() SpotifyParser::spotifyTrackLookupFinished()
{ {
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() ); NetworkReply* r = qobject_cast< NetworkReply* >( sender() );
Q_ASSERT( r ); Q_ASSERT( r );
m_queries.remove( r ); m_queries.remove( r );
r->deleteLater(); r->deleteLater();
if ( r->error() == QNetworkReply::NoError ) if ( r->reply()->error() == QNetworkReply::NoError )
{ {
QJson::Parser p; QJson::Parser p;
bool ok; bool ok;
QVariantMap res = p.parse( r, &ok ).toMap(); QVariantMap res = p.parse( r->reply(), &ok ).toMap();
if ( !ok ) if ( !ok )
{ {
@@ -314,7 +310,7 @@ SpotifyParser::spotifyTrackLookupFinished()
} }
else else
{ {
tLog() << "Error in network request to Spotify for track decoding:" << r->errorString(); tLog() << "Error in network request to Spotify for track decoding:" << r->reply()->errorString();
} }
if ( m_trackMode ) if ( m_trackMode )

View File

@@ -38,9 +38,10 @@
* Connect to the signals to get the results * Connect to the signals to get the results
*/ */
class QNetworkReply; class NetworkReply;
class SpotifyAccount; class SpotifyAccount;
class SpotifyPlaylistUpdater; class SpotifyPlaylistUpdater;
namespace Tomahawk namespace Tomahawk
{ {
@@ -88,7 +89,7 @@ private:
bool m_collaborative; bool m_collaborative;
int m_subscribers; int m_subscribers;
QList< query_ptr > m_tracks; QList< query_ptr > m_tracks;
QSet< QNetworkReply* > m_queries; QSet< NetworkReply* > m_queries;
QString m_title, m_info, m_creator; QString m_title, m_info, m_creator;
Tomahawk::playlist_ptr m_playlist; Tomahawk::playlist_ptr m_playlist;
DropJobNotifier* m_browseJob; DropJobNotifier* m_browseJob;