mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 16:29:43 +01:00
add rdio link parsing
This commit is contained in:
parent
2a061b5bf1
commit
78d867b16f
@ -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
|
||||
|
@ -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<Tomahawk::query_ptr> ) ), this, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ) );
|
||||
} 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<Tomahawk::query_ptr> ) ), this, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ) );
|
||||
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;
|
||||
}
|
||||
|
101
src/libtomahawk/utils/rdioparser.cpp
Normal file
101
src/libtomahawk/utils/rdioparser.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "rdioparser.h"
|
||||
|
||||
#include <QUrl>
|
||||
#include <QStringList>
|
||||
|
||||
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 );
|
||||
}
|
||||
|
62
src/libtomahawk/utils/rdioparser.h
Normal file
62
src/libtomahawk/utils/rdioparser.h
Normal file
@ -0,0 +1,62 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef RDIOPARSER_H
|
||||
#define RDIOPARSER_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QStringList>
|
||||
|
||||
#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
|
@ -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 );
|
||||
|
Loading…
x
Reference in New Issue
Block a user