1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-09 15:47:38 +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 "utils/Logger.h"
#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 <QtNetwork/QNetworkAccessManager>
#include <qjson/parser.h>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include "Query.h"
#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;
@@ -72,7 +72,6 @@ ExfmParser::~ExfmParser()
void
ExfmParser::lookupUrl( const QString& link )
{
const QString apiBase = "http://ex.fm/api/v3";
QString url( link );
QStringList paths;
@@ -117,34 +116,29 @@ ExfmParser::lookupUrl( const QString& link )
{
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( "http://ex.fm", apiBase );
}
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 )
connect( reply, SIGNAL( finished() ), this, SLOT( exfmLookupFinished() ) );
connect( reply, SIGNAL( finished() ), SLOT( exfmLookupFinished() ) );
else
connect( reply, SIGNAL( finished() ), this, SLOT( exfmBrowseFinished() ) );
connect( reply, SIGNAL( finished() ), SLOT( exfmBrowseFinished() ) );
m_browseJob = new DropJobNotifier( pixmap(), "Exfm", m_type, reply );
JobStatusView::instance()->model()->addJob( m_browseJob );
m_queries.insert( reply );
}
void
ExfmParser::parseTrack( const QVariantMap& res )
{
QString title, artist, album;
album = res.value( "album", QString() ).toString();
title = res.value( "title", QString() ).toString();
@@ -165,34 +159,35 @@ ExfmParser::parseTrack( const QVariantMap& res )
q->setProperty( "annotation", res.value( "url" ).toString() );
m_tracks << q;
}
}
void
ExfmParser::exfmLookupFinished()
{
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() );
NetworkReply* r = qobject_cast< NetworkReply* >( sender() );
Q_ASSERT( r );
m_queries.remove( r );
r->deleteLater();
if ( r->error() == QNetworkReply::NoError )
if ( r->reply()->error() == QNetworkReply::NoError )
{
QJson::Parser p;
bool ok;
QVariantMap res = p.parse( r, &ok ).toMap();
QVariantMap res = p.parse( r->reply(), &ok ).toMap();
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;
}
QStringList paths;
foreach( const QString& path, r->url().path().split( "/" ) )
foreach ( const QString& path, r->reply()->url().path().split( "/" ) )
{
if ( !path.isEmpty() )
paths << path;
}
QString title, artist, desc;
QVariantList tracks;
@@ -243,30 +238,31 @@ ExfmParser::exfmLookupFinished()
connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistCreated() ) );
return;
}
}
void
ExfmParser::playlistCreated()
{
ViewManager::instance()->show( m_playlist );
deleteLater();
}
void
ExfmParser::exfmBrowseFinished()
{
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() );
NetworkReply* r = qobject_cast< NetworkReply* >( sender() );
Q_ASSERT( r );
r->deleteLater();
if ( r->error() == QNetworkReply::NoError )
if ( r->reply()->error() == QNetworkReply::NoError )
{
QJson::Parser p;
bool ok;
QVariantMap res = p.parse( r, &ok ).toMap();
QVariantMap res = p.parse( r->reply(), &ok ).toMap();
if ( !ok )
{
@@ -295,9 +291,9 @@ ExfmParser::exfmBrowseFinished()
deleteLater();
}
}
QPixmap
ExfmParser::pixmap() const
{

View File

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

View File

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

View File

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

View File

@@ -19,19 +19,20 @@
*/
#include "ItunesParser.h"
#include "utils/Logger.h"
#include "utils/TomahawkUtils.h"
#include <QtNetwork/QNetworkAccessManager>
#include <QRegExp>
#include <qjson/parser.h>
#include "Query.h"
#include "SourceList.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
#include "jobview/ErrorStatusMessage.h"
#include <qjson/parser.h>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QRegExp>
#include "utils/NetworkReply.h"
#include "utils/TomahawkUtils.h"
#include "utils/Logger.h"
using namespace Tomahawk;
@@ -91,7 +92,6 @@ ItunesParser::lookupItunesUri( const QString& link )
else
return;
}
tLog() << "Parsing itunes track:" << link;
QUrl url;
DropJob::DropType type;
@@ -105,10 +105,9 @@ ItunesParser::lookupItunesUri( const QString& link )
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 ) ) );
}
qDebug() << "Looking up..." << url.toString();
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
connect( reply, SIGNAL( finished() ), this, SLOT( itunesResponseLookupFinished() ) );
NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( url ) ) );
connect( reply, SIGNAL( finished() ), SLOT( itunesResponseLookupFinished() ) );
DropJobNotifier* j = new DropJobNotifier( pixmap(), QString( "Itunes" ), type, reply );
JobStatusView::instance()->model()->addJob( j );
@@ -120,16 +119,16 @@ ItunesParser::lookupItunesUri( const QString& link )
void
ItunesParser::itunesResponseLookupFinished()
{
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() );
NetworkReply* r = qobject_cast< NetworkReply* >( sender() );
Q_ASSERT( r );
m_queries.remove( r );
r->deleteLater();
if ( r->error() == QNetworkReply::NoError )
if ( r->reply()->error() == QNetworkReply::NoError )
{
QJson::Parser p;
bool ok;
QVariantMap res = p.parse( r, &ok ).toMap();
QVariantMap res = p.parse( r->reply(), &ok ).toMap();
if ( !ok )
{
@@ -173,7 +172,7 @@ ItunesParser::itunesResponseLookupFinished()
else
{
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();

View File

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

View File

@@ -19,27 +19,28 @@
#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 <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QUrl>
#include <QStringList>
#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;
QPixmap* RdioParser::s_pixmap = 0;
@@ -78,7 +79,7 @@ RdioParser::parse( const QStringList& urls )
m_multi = true;
m_total = urls.count();
foreach( const QString& url, urls )
foreach ( const QString& url, urls )
parseUrl( url );
}
@@ -129,8 +130,8 @@ RdioParser::fetchObjectsFromUrl( const QString& url, DropJob::DropType type )
QNetworkRequest request = generateRequest( "getObjectFromUrl", cleanedUrl, params, &data );
request.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1String( "application/x-www-form-urlencoded" ) );
QNetworkReply* reply = TomahawkUtils::nam()->post( request, data );
connect( reply, SIGNAL( finished() ), this, SLOT( rdioReturned() ) );
NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->post( request, data ) );
connect( reply, SIGNAL( finished() ), SLOT( rdioReturned() ) );
m_browseJob = new DropJobNotifier( pixmap(), QString( "Rdio" ), type, reply );
JobStatusView::instance()->model()->addJob( m_browseJob );
@@ -142,22 +143,22 @@ RdioParser::fetchObjectsFromUrl( const QString& url, DropJob::DropType type )
void
RdioParser::rdioReturned()
{
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() );
NetworkReply* r = qobject_cast< NetworkReply* >( sender() );
Q_ASSERT( r );
m_reqQueries.remove( r );
m_count++;
r->deleteLater();
if ( r->error() == QNetworkReply::NoError )
if ( r->reply()->error() == QNetworkReply::NoError )
{
QJson::Parser p;
bool ok;
QVariantMap res = p.parse( r, &ok ).toMap();
QVariantMap res = p.parse( r->reply(), &ok ).toMap();
QVariantMap result = res.value( "result" ).toMap();
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;
}
@@ -198,7 +199,7 @@ RdioParser::rdioReturned()
else
{
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();
@@ -256,7 +257,7 @@ RdioParser::generateRequest( const QString& method, const QString& url, const QL
QUrl toSignUrl = fetchUrl;
QPair<QByteArray, QByteArray> param;
foreach( param, extraParams )
foreach ( param, extraParams )
{
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 &
qDebug() << "POST data:" << *data;
QNetworkRequest request = QNetworkRequest( fetchUrl );
request.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1String( "application/x-www-form-urlencoded" ) );

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -19,21 +19,21 @@
#include "SpotifyParser.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 <QtNetwork/QNetworkAccessManager>
#include <qjson/parser.h>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#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;
@@ -49,7 +49,6 @@ SpotifyParser::SpotifyParser( const QStringList& Urls, bool createNewPlaylist, Q
, m_createNewPlaylist( createNewPlaylist )
, m_browseJob( 0 )
, m_subscribers( 0 )
{
foreach ( const QString& url, Urls )
lookupUrl( url );
@@ -141,15 +140,14 @@ SpotifyParser::lookupSpotifyBrowse( const QString& linkRaw )
QUrl url;
if( type != DropJob::Artist )
if ( type != DropJob::Artist )
url = QUrl( QString( SPOTIFY_PLAYLIST_API_URL "/browse/%1" ).arg( m_browseUri ) );
else
url = QUrl( QString( SPOTIFY_PLAYLIST_API_URL "/browse/%1/%2" ).arg( m_browseUri )
.arg ( m_limit ) );
tDebug() << "Looking up URL..." << url.toString();
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
connect( reply, SIGNAL( finished() ), this, SLOT( spotifyBrowseFinished() ) );
NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( url ) ) );
connect( reply, SIGNAL( finished() ), SLOT( spotifyBrowseFinished() ) );
m_browseJob = new DropJobNotifier( pixmap(), "Spotify", type, reply );
JobStatusView::instance()->model()->addJob( m_browseJob );
@@ -161,8 +159,7 @@ SpotifyParser::lookupSpotifyBrowse( const QString& linkRaw )
void
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;
// 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 ) );
tDebug() << "Looking up URL..." << url.toString();
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
connect( reply, SIGNAL( finished() ), this, SLOT( spotifyTrackLookupFinished() ) );
NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->get( QNetworkRequest( url ) ) );
connect( reply, SIGNAL( finished() ), SLOT( spotifyTrackLookupFinished() ) );
DropJobNotifier* j = new DropJobNotifier( pixmap(), QString( "Spotify" ), DropJob::Track, reply );
JobStatusView::instance()->model()->addJob( j );
@@ -190,21 +186,21 @@ SpotifyParser::lookupTrack( const QString& link )
void
SpotifyParser::spotifyBrowseFinished()
{
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() );
NetworkReply* r = qobject_cast< NetworkReply* >( sender() );
Q_ASSERT( r );
m_queries.remove( r );
r->deleteLater();
if ( r->error() == QNetworkReply::NoError )
if ( r->reply()->error() == QNetworkReply::NoError )
{
QJson::Parser p;
bool ok;
QVariantMap res = p.parse( r, &ok ).toMap();
QVariantMap res = p.parse( r->reply(), &ok ).toMap();
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();
return;
}
@@ -250,7 +246,7 @@ SpotifyParser::spotifyBrowseFinished()
else
{
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 )
@@ -263,16 +259,16 @@ SpotifyParser::spotifyBrowseFinished()
void
SpotifyParser::spotifyTrackLookupFinished()
{
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() );
NetworkReply* r = qobject_cast< NetworkReply* >( sender() );
Q_ASSERT( r );
m_queries.remove( r );
r->deleteLater();
if ( r->error() == QNetworkReply::NoError )
if ( r->reply()->error() == QNetworkReply::NoError )
{
QJson::Parser p;
bool ok;
QVariantMap res = p.parse( r, &ok ).toMap();
QVariantMap res = p.parse( r->reply(), &ok ).toMap();
if ( !ok )
{
@@ -314,7 +310,7 @@ SpotifyParser::spotifyTrackLookupFinished()
}
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 )

View File

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