1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 15:59:42 +01:00

TWK-459: More rdio unbreaking and add support in rdioURI/rdioURL tomahawk urls

This commit is contained in:
Leo Franchi 2011-08-24 19:13:54 -04:00
parent b7db4e0e6b
commit def10a2e2b
4 changed files with 65 additions and 3 deletions

View File

@ -357,6 +357,8 @@ GlobalActionManager::doQueueAdd( const QStringList& parts, const QList< QPair< Q
if( queueSpotify( parts, queryItems ) )
return true;
else if( queueRdio( parts, queryItems ) )
return true;
QPair< QString, QString > pair;
@ -427,6 +429,26 @@ GlobalActionManager::queueSpotify( const QStringList& , const QList< QPair< QStr
return true;
}
bool
GlobalActionManager::queueRdio( const QStringList& , const QList< QPair< QString, QString > >& queryItems )
{
QString url;
QPair< QString, QString > pair;
foreach( pair, queryItems ) {
if( pair.first == "rdioURL" )
url = pair.second;
else if( pair.first == "rdioURI" )
url = pair.second;
}
if( url.isEmpty() )
return false;
openRdioLink( url );
return true;
}
bool
GlobalActionManager::handleSearchCommand( const QUrl& url )
@ -617,6 +639,8 @@ GlobalActionManager::handlePlayCommand( const QUrl& url )
if( parts[ 0 ] == "track" ) {
if( playSpotify( url ) )
return true;
else if( playRdio( url ) )
return true;
QPair< QString, QString > pair;
QString title, artist, album, urlStr;
@ -652,13 +676,13 @@ GlobalActionManager::playSpotify( const QUrl& url )
QString spotifyUrl = url.hasQueryItem( "spotifyURI" ) ? url.queryItemValue( "spotifyURI" ) : url.queryItemValue( "spotifyURL" );
SpotifyParser* p = new SpotifyParser( spotifyUrl, this );
connect( p, SIGNAL( track( Tomahawk::query_ptr ) ), this, SLOT( spotifyToPlay( Tomahawk::query_ptr ) ) );
connect( p, SIGNAL( track( Tomahawk::query_ptr ) ), this, SLOT( playNow( Tomahawk::query_ptr ) ) );
return true;
}
void
GlobalActionManager::spotifyToPlay( const query_ptr& q )
GlobalActionManager::playNow( const query_ptr& q )
{
Pipeline::instance()->resolve( q, true );
@ -666,6 +690,21 @@ GlobalActionManager::spotifyToPlay( const query_ptr& q )
connect( q.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( waitingForResolved( bool ) ) );
}
bool
GlobalActionManager::playRdio( const QUrl& url )
{
if( !url.hasQueryItem( "rdioURI" ) && !url.hasQueryItem( "rdioURL" ) )
return false;
QString rdioUrl = url.hasQueryItem( "rdioURI" ) ? url.queryItemValue( "spotifyURI" ) : url.queryItemValue( "rdioURL" );
RdioParser* p = new RdioParser( this );
p->parse( rdioUrl );
connect( p, SIGNAL( track( Tomahawk::query_ptr ) ), this, SLOT( playNow( Tomahawk::query_ptr ) ) );
return true;
}
bool GlobalActionManager::handleBookmarkCommand(const QUrl& url)
{

View File

@ -65,7 +65,7 @@ private slots:
void xspfCreated( const QByteArray& xspf );
void spotifyToPlay( const Tomahawk::query_ptr& );
void playNow( const Tomahawk::query_ptr& );
private:
explicit GlobalActionManager( QObject* parent = 0 );
void doBookmark( const Tomahawk::playlist_ptr& pl, const Tomahawk::query_ptr& q );
@ -84,6 +84,8 @@ private:
bool playSpotify( const QUrl& url );
bool queueSpotify( const QStringList& parts, const QList< QPair< QString, QString > >& queryItems );
bool playRdio( const QUrl& url );
bool queueRdio( const QStringList& parts, const QList< QPair< QString, QString > >& queryItems );
QString hostname() const;

View File

@ -20,6 +20,7 @@
#include <QUrl>
#include <QStringList>
#include "shortenedlinkparser.h"
using namespace Tomahawk;
@ -55,6 +56,13 @@ RdioParser::parse( const QStringList& urls )
void
RdioParser::parseUrl( const QString& url )
{
if ( url.contains( "rd.io" ) ) // shortened
{
ShortenedLinkParser* p = new ShortenedLinkParser( QStringList() << url, this );
connect( p, SIGNAL( urls( QStringList ) ), this, SLOT( expandedLinks( QStringList ) ) );
return;
}
query_ptr query;
m_count++;
@ -99,3 +107,13 @@ RdioParser::parseUrl( const QString& url )
emit track( query );
}
void
RdioParser::expandedLinks( const QStringList& urls )
{
foreach( const QString& url, urls )
{
if ( url.contains( "rdio.com" ) || url.contains( "rd.io" ) )
parseUrl( url );
}
}

View File

@ -49,6 +49,9 @@ signals:
void track( const Tomahawk::query_ptr& track );
void tracks( const QList< Tomahawk::query_ptr > tracks );
private slots:
void expandedLinks( const QStringList& );
private:
void parseUrl( const QString& url );