diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 574c29ad5..b9b740b97 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -173,6 +173,7 @@ set( libSources utils/xspfgenerator.cpp utils/jspfloader.cpp utils/spotifyparser.cpp + utils/rdioparser.cpp utils/shortenedlinkparser.cpp widgets/newplaylistwidget.cpp @@ -352,6 +353,7 @@ set( libHeaders utils/xspfgenerator.h utils/jspfloader.h utils/spotifyparser.h + utils/rdioparser.h utils/shortenedlinkparser.h widgets/newplaylistwidget.h diff --git a/src/libtomahawk/globalactionmanager.cpp b/src/libtomahawk/globalactionmanager.cpp index 5b79b9c3a..ffd7fd253 100644 --- a/src/libtomahawk/globalactionmanager.cpp +++ b/src/libtomahawk/globalactionmanager.cpp @@ -46,6 +46,7 @@ #include "utils/jspfloader.h" #include "utils/spotifyparser.h" #include "utils/shortenedlinkparser.h" +#include "utils/rdioparser.h" GlobalActionManager* GlobalActionManager::s_instance = 0; @@ -791,9 +792,14 @@ GlobalActionManager::acceptsMimeData( const QMimeData* data, bool tracksOnly ) // crude check for spotify tracks if ( data->hasFormat( "text/plain" ) && data->data( "text/plain" ).contains( "spotify" ) && - ( tracksOnly ? data->data( "text/plain" ).contains( "track" ) : true ) ) + ( tracksOnly ? data->data( "text/plain" ).contains( "track" ) : true ) ) return true; + // crude check for rdio tracks + if ( data->hasFormat( "text/plain" ) && data->data( "text/plain" ).contains( "rdio.com" ) && + ( tracksOnly ? data->data( "text/plain" ).contains( "track" ) : true ) ) + return true; + // We whitelist t.co and bit.ly (and j.mp) since they do some link checking. Often playable (e.g. spotify..) links hide behind them, // so we do an extra level of lookup if ( ( data->hasFormat( "text/plain" ) && data->data( "text/plain" ).contains( "bit.ly" ) ) || @@ -831,6 +837,14 @@ GlobalActionManager::handleTrackUrls( const QString& urls ) tDebug() << "Got a list of spotify urls!" << tracks; SpotifyParser* spot = new SpotifyParser( tracks, this ); connect( spot, SIGNAL( tracks( QList ) ), this, SIGNAL( tracks( QList ) ) ); + } else if ( urls.contains( "rdio.com" ) ) + { + QStringList tracks = urls.split( "\n" ); + + tDebug() << "Got a list of rdio urls!" << tracks; + RdioParser* rdio = new RdioParser( this ); + connect( rdio, SIGNAL( tracks( QList ) ), this, SIGNAL( tracks( QList ) ) ); + rdio->parse( tracks ); } else if ( urls.contains( "bit.ly" ) || urls.contains( "j.mp" ) || urls.contains( "t.co" ) ) @@ -913,8 +927,9 @@ GlobalActionManager::openSpotifyLink( const QString& link ) bool GlobalActionManager::openRdioLink( const QString& link ) { -// RdioParser* rdio = new RdioParser( link, this ); -// connect( spot, SIGNAL( track( Tomahawk::query_ptr ) ), this, SLOT( handleOpenTrack( Tomahawk::query_ptr ) ) ); + RdioParser* rdio = new RdioParser( this ); + connect( rdio, SIGNAL( track( Tomahawk::query_ptr ) ), this, SLOT( handleOpenTrack( Tomahawk::query_ptr ) ) ); + rdio->parse( link ); return true; } diff --git a/src/libtomahawk/utils/rdioparser.cpp b/src/libtomahawk/utils/rdioparser.cpp new file mode 100644 index 000000000..a10ab2462 --- /dev/null +++ b/src/libtomahawk/utils/rdioparser.cpp @@ -0,0 +1,101 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Leo Franchi + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "rdioparser.h" + +#include +#include + +using namespace Tomahawk; + +RdioParser::RdioParser( QObject* parent ) + : QObject( parent ) + , m_count( 0 ) +{ +} + +RdioParser::~RdioParser() +{ +} + +void +RdioParser::parse( const QString& url ) +{ + m_multi = false; + m_total = 1; + parseUrl( url ); +} + +void +RdioParser::parse( const QStringList& urls ) +{ + m_multi = true; + m_total = urls.count(); + + foreach( const QString& url, urls ) + parseUrl( url ); +} + + +void +RdioParser::parseUrl( const QString& url ) +{ + query_ptr query; + m_count++; + + if ( url.contains( "artist" ) && url.contains( "album" ) ) + { + // this is a "full" url, no redirection needed + QString realUrl = QUrl::fromUserInput( url ).toString().replace( "_", " " ); + + QString artist, trk, album; + QString matchStr = "/%1/([^/]*)/"; + QRegExp r( QString( matchStr ).arg( "artist" ) ); + + int loc = r.indexIn( realUrl ); + if ( loc >= 0 ) + artist = r.cap( 1 ); + + r = QRegExp( QString( matchStr ).arg( "album" ) ); + loc = r.indexIn( realUrl ); + if ( loc >= 0 ) + album = r.cap( 1 ); + + r = QRegExp( QString( matchStr ).arg( "track" ) ); + loc = r.indexIn( realUrl ); + if ( loc >= 0 ) + trk = r.cap( 1 ); + + if ( !trk.isEmpty() && !artist.isEmpty() ) + { + query = Query::get( artist, trk, album, uuid(), true ); + } + } + + if ( m_multi ) + { + if ( !query.isNull() ) + m_queries << query; + + if ( m_count == m_total ) + emit tracks( m_queries ); + } + if ( !m_multi && !query.isNull() ) + emit track( query ); +} + diff --git a/src/libtomahawk/utils/rdioparser.h b/src/libtomahawk/utils/rdioparser.h new file mode 100644 index 000000000..8d2cece5b --- /dev/null +++ b/src/libtomahawk/utils/rdioparser.h @@ -0,0 +1,62 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Leo Franchi + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef RDIOPARSER_H +#define RDIOPARSER_H + +#include +#include + +#include "query.h" +#include "source.h" + +class QNetworkReply; +namespace Tomahawk +{ + +/** + * Small class to parse spotify links into query_ptrs + * + * Connect to the signals to get the results + */ + +class RdioParser : public QObject +{ + Q_OBJECT +public: + explicit RdioParser( QObject* parent = 0 ); + virtual ~RdioParser(); + + void parse( const QString& url ); + void parse( const QStringList& urls ); + +signals: + void track( const Tomahawk::query_ptr& track ); + void tracks( const QList< Tomahawk::query_ptr > tracks ); + +private: + void parseUrl( const QString& url ); + + bool m_multi; + int m_count, m_total; + QList< query_ptr > m_queries; +}; + +} + +#endif // RDIOPARSER_H diff --git a/src/libtomahawk/widgets/welcomewidget.cpp b/src/libtomahawk/widgets/welcomewidget.cpp index 51db3b8f8..44757c076 100644 --- a/src/libtomahawk/widgets/welcomewidget.cpp +++ b/src/libtomahawk/widgets/welcomewidget.cpp @@ -245,7 +245,8 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, { descText = index.data( WelcomePlaylistModel::ArtistRole ).toString(); } - painter->drawText( option.rect.adjusted( 56, 26, -100, -8 ), descText ); + painter->setFont( italicFont ); + painter->drawText( option.rect.adjusted( 66, 26, -100, -8 ), descText ); QString trackCount = tr( "%1 tracks" ).arg( index.data( WelcomePlaylistModel::TrackCountRole ).toString() ); painter->drawText( option.rect.adjusted( option.rect.width() - 96, 12, 0, -2 - opt.rect.height() / 2 ), trackCount, to );