mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Added itunes artist link support
This commit is contained in:
@@ -123,6 +123,16 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
|
|||||||
// crude check for itunes tracks
|
// crude check for itunes tracks
|
||||||
if ( data->hasFormat( "text/plain" ) && data->data( "text/plain" ).contains( "itunes" )
|
if ( data->hasFormat( "text/plain" ) && data->data( "text/plain" ).contains( "itunes" )
|
||||||
&& data->data( "text/plain" ).contains( "album" )
|
&& data->data( "text/plain" ).contains( "album" )
|
||||||
|
&& ( acceptedType.testFlag(DropJob::Track)
|
||||||
|
|| acceptedType.testFlag(DropJob::Album)
|
||||||
|
|| acceptedType.testFlag(DropJob::All)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// crude check for itunes artist
|
||||||
|
if ( data->hasFormat( "text/plain" ) && data->data( "text/plain" ).contains( "itunes" )
|
||||||
|
&& data->data( "text/plain" ).contains( "artist" )
|
||||||
&& ( acceptedType.testFlag(DropJob::Track) || acceptedType.testFlag(DropJob::All) )
|
&& ( acceptedType.testFlag(DropJob::Track) || acceptedType.testFlag(DropJob::All) )
|
||||||
)
|
)
|
||||||
return true;
|
return true;
|
||||||
|
@@ -19,7 +19,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "itunesparser.h"
|
#include "itunesparser.h"
|
||||||
|
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
#include "utils/tomahawkutils.h"
|
#include "utils/tomahawkutils.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
@@ -38,8 +37,10 @@ ItunesParser::ItunesParser( const QStringList& Urls, QObject* parent, bool creat
|
|||||||
|
|
||||||
{
|
{
|
||||||
m_createNewPlaylist = createNewPlaylist;
|
m_createNewPlaylist = createNewPlaylist;
|
||||||
foreach ( const QString& url, Urls )
|
foreach ( const QString& url, Urls ){
|
||||||
lookupUrl( url );
|
|
||||||
|
lookupItunesUri( url );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItunesParser::ItunesParser( const QString& Url, QObject* parent, bool createNewPlaylist )
|
ItunesParser::ItunesParser( const QString& Url, QObject* parent, bool createNewPlaylist )
|
||||||
@@ -47,7 +48,7 @@ ItunesParser::ItunesParser( const QString& Url, QObject* parent, bool createNewP
|
|||||||
, m_single( true )
|
, m_single( true )
|
||||||
{
|
{
|
||||||
m_createNewPlaylist = createNewPlaylist;
|
m_createNewPlaylist = createNewPlaylist;
|
||||||
lookupUrl( Url );
|
lookupItunesUri( Url );
|
||||||
}
|
}
|
||||||
|
|
||||||
ItunesParser::~ItunesParser()
|
ItunesParser::~ItunesParser()
|
||||||
@@ -55,64 +56,50 @@ ItunesParser::~ItunesParser()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ItunesParser::lookupUrl( const QString& link )
|
ItunesParser::lookupItunesUri( const QString& link )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
if( link.contains( "album" ) )// && link.contains( "?i="))
|
|
||||||
lookupTrack(link);
|
|
||||||
|
|
||||||
else return; // We only support tracks and playlists
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ItunesParser::lookupTrack( const QString& link )
|
|
||||||
{
|
|
||||||
|
|
||||||
tDebug() << "Got a QString " << link;
|
|
||||||
if ( !link.contains( "album" ) ) //&& !link.contains( "?i=" )) // we only support track links atm
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Itunes uri parsing, using regex
|
// Itunes uri parsing, using regex
|
||||||
// (\d+)(?:\?i=*)(\d+) = AlbumId and trackId
|
// (\d+)(?:\?i=*)(\d+) = AlbumId and trackId
|
||||||
// (\d+)(?:\s*) = albumId
|
// (\d+)(?:\s*) = id
|
||||||
QRegExp rxAlbumTrack( "(\\d+)(?:\\?i=*)(\\d+)" );
|
QRegExp rxAlbumTrack( "(\\d+)(?:\\?i=*)(\\d+)" );
|
||||||
QRegExp rxAlbum( "(\\d+)(?:\\s*)" );
|
QRegExp rxId( "(\\d+)(?:\\s*)" );
|
||||||
QString albumId, trackId;
|
QString id, trackId;
|
||||||
|
|
||||||
// Doing a parse on regex in 2 stages,
|
// Doing a parse on regex in 2 stages,
|
||||||
// first, look if we have both album and track id
|
// first, look if we have both album and track id
|
||||||
int pos = rxAlbumTrack.indexIn(link);
|
int pos = rxAlbumTrack.indexIn(link);
|
||||||
|
|
||||||
if (pos > -1) {
|
if (pos > -1) {
|
||||||
albumId = rxAlbumTrack.cap(1);
|
id = rxAlbumTrack.cap(1);
|
||||||
trackId = rxAlbumTrack.cap(2);
|
trackId = rxAlbumTrack.cap(2);
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
// Second, if we dont have trackId, check for just albumid
|
// Second, if we dont have trackId, check for just Id
|
||||||
int pos = rxAlbum.indexIn(link);
|
int pos = rxId.indexIn(link);
|
||||||
if (pos > -1) {
|
if (pos > -1) {
|
||||||
albumId = rxAlbum.cap(1);
|
id = rxId.cap(1);
|
||||||
}else return;
|
}else return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Got Itunes link with Albumid " << albumId << "and trackid " <<trackId;
|
qDebug() << "Got Itunes link with id " << id << "and trackid" <<trackId;
|
||||||
tLog() << "Parsing itunes track:" << link;
|
tLog() << "Parsing itunes track:" << link;
|
||||||
|
|
||||||
QUrl url = QUrl( QString( "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsLookup?id=%1&entity=song" ).arg( ( trackId.isEmpty() ? albumId : trackId ) ) );
|
QUrl url;
|
||||||
tDebug() << "Looking up..." << url.toString();
|
if( link.contains( "artist" ) )
|
||||||
|
url = QUrl( QString( "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsLookup?id=%1&entity=song&limit=30" ).arg( id ) );
|
||||||
|
else 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 ) );
|
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
||||||
connect( reply, SIGNAL( finished() ), this, SLOT( itunesTrackLookupFinished() ) );
|
connect( reply, SIGNAL( finished() ), this, SLOT( itunesResponseLookupFinished() ) );
|
||||||
|
|
||||||
m_queries.insert( reply );
|
m_queries.insert( reply );
|
||||||
|
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
ItunesParser::itunesTrackLookupFinished()
|
ItunesParser::itunesResponseLookupFinished()
|
||||||
{
|
{
|
||||||
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() );
|
QNetworkReply* r = qobject_cast< QNetworkReply* >( sender() );
|
||||||
Q_ASSERT( r );
|
Q_ASSERT( r );
|
||||||
@@ -140,8 +127,7 @@ ItunesParser::itunesTrackLookupFinished()
|
|||||||
|
|
||||||
foreach(QVariant itune, itunesResponse){
|
foreach(QVariant itune, itunesResponse){
|
||||||
QString title, artist, album;
|
QString title, artist, album;
|
||||||
if( !itune.toMap().value( "wrapperType" ).toString().contains( "track" ) )
|
if( itune.toMap().value( "wrapperType" ).toString().contains( "track" ) ){
|
||||||
continue;
|
|
||||||
|
|
||||||
title = itune.toMap().value( "trackName" ).toString();
|
title = itune.toMap().value( "trackName" ).toString();
|
||||||
artist = itune.toMap().value( "artistName" ).toString();
|
artist = itune.toMap().value( "artistName" ).toString();
|
||||||
@@ -156,11 +142,12 @@ ItunesParser::itunesTrackLookupFinished()
|
|||||||
m_tracks << q;
|
m_tracks << q;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
tLog() << "Error in network request to Spotify for track decoding:" << r->errorString();
|
tLog() << "Error in network request to Itunes for track decoding:" << r->errorString();
|
||||||
}
|
}
|
||||||
|
|
||||||
checkTrackFinished();
|
checkTrackFinished();
|
||||||
|
@@ -23,12 +23,12 @@
|
|||||||
|
|
||||||
#include "dllmacro.h"
|
#include "dllmacro.h"
|
||||||
#include "typedefs.h"
|
#include "typedefs.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
|
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
|
class TrackModel;
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -45,17 +45,17 @@ public:
|
|||||||
explicit ItunesParser( const QStringList& trackUrls, QObject* parent = 0, bool createNewPl = false);
|
explicit ItunesParser( const QStringList& trackUrls, QObject* parent = 0, bool createNewPl = false);
|
||||||
virtual ~ItunesParser();
|
virtual ~ItunesParser();
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void track( const Tomahawk::query_ptr& track );
|
void track( const Tomahawk::query_ptr& track );
|
||||||
void tracks( const QList< Tomahawk::query_ptr > tracks );
|
void tracks( const QList< Tomahawk::query_ptr > tracks );
|
||||||
void playlist( const Tomahawk::query_ptr& playlist );
|
void playlist( const Tomahawk::query_ptr& playlist );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void itunesTrackLookupFinished();
|
void itunesResponseLookupFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void lookupUrl( const QString& url );
|
void lookupItunesUri( const QString& track );
|
||||||
void lookupTrack( const QString& track );
|
|
||||||
void checkTrackFinished();
|
void checkTrackFinished();
|
||||||
|
|
||||||
bool m_single;
|
bool m_single;
|
||||||
|
Reference in New Issue
Block a user