mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-19 23:39:42 +01:00
* DRY: Cleaned up DropJob / ShortenedLinkParser & handling spoti.fi urls now.
This commit is contained in:
parent
1b09361c51
commit
cf771ae94b
@ -34,10 +34,12 @@
|
||||
#include "utils/xspfloader.h"
|
||||
#include "jobview/JobStatusView.h"
|
||||
#include "jobview/JobStatusModel.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
bool DropJob::s_canParseSpotifyPlaylists = false;
|
||||
|
||||
|
||||
DropJob::DropJob( QObject *parent )
|
||||
: QObject( parent )
|
||||
, m_queryCount( 0 )
|
||||
@ -50,11 +52,13 @@ DropJob::DropJob( QObject *parent )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DropJob::~DropJob()
|
||||
{
|
||||
qDebug() << "destryong DropJob";
|
||||
}
|
||||
|
||||
|
||||
/// QMIMEDATA HANDLING
|
||||
|
||||
QStringList
|
||||
@ -74,6 +78,7 @@ DropJob::mimeTypes()
|
||||
return mimeTypes;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType, DropJob::DropAction acceptedAction )
|
||||
{
|
||||
@ -144,14 +149,15 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
|
||||
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 ( url.contains( "bit.ly" ) || url.contains( "j.mp" ) || url.contains( "t.co" ) || url.contains( "rd.io" ) )
|
||||
// We whitelist certain url-shorteners since they do some link checking. Often playable (e.g. spotify) links hide behind them,
|
||||
// so we do an extra level of lookup
|
||||
if ( ShortenedLinkParser::handlesUrl( url ) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
DropJob::isDropType( DropJob::DropType desired, const QMimeData* data )
|
||||
{
|
||||
@ -168,11 +174,7 @@ DropJob::isDropType( DropJob::DropType desired, const QMimeData* data )
|
||||
if ( url.contains( "rdio.com" ) && url.contains( "people" ) && url.contains( "playlist" ) )
|
||||
return true;
|
||||
|
||||
// we don't know about these.. gotta say yes for now
|
||||
if ( url.contains( "bit.ly" ) ||
|
||||
url.contains( "j.mp" ) ||
|
||||
url.contains( "t.co" ) ||
|
||||
url.contains( "rd.io" ) )
|
||||
if ( ShortenedLinkParser::handlesUrl( url ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -186,6 +188,7 @@ DropJob::setGetWholeArtists( bool getWholeArtists )
|
||||
m_getWholeArtists = getWholeArtists;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DropJob::setGetWholeAlbums( bool getWholeAlbums )
|
||||
{
|
||||
@ -215,6 +218,7 @@ DropJob::tracksFromMimeData( const QMimeData* data, bool allowDuplicates, bool o
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DropJob::parseMimeData( const QMimeData *data )
|
||||
{
|
||||
@ -243,6 +247,7 @@ DropJob::parseMimeData( const QMimeData *data )
|
||||
m_resultList.append( results );
|
||||
}
|
||||
|
||||
|
||||
QList< query_ptr >
|
||||
DropJob::tracksFromQueryList( const QMimeData* data )
|
||||
{
|
||||
@ -282,6 +287,7 @@ DropJob::tracksFromQueryList( const QMimeData* data )
|
||||
return queries;
|
||||
}
|
||||
|
||||
|
||||
QList< query_ptr >
|
||||
DropJob::tracksFromResultList( const QMimeData* data )
|
||||
{
|
||||
@ -323,6 +329,7 @@ DropJob::tracksFromResultList( const QMimeData* data )
|
||||
return queries;
|
||||
}
|
||||
|
||||
|
||||
QList< query_ptr >
|
||||
DropJob::tracksFromAlbumMetaData( const QMimeData *data )
|
||||
{
|
||||
@ -347,6 +354,7 @@ DropJob::tracksFromAlbumMetaData( const QMimeData *data )
|
||||
return queries;
|
||||
}
|
||||
|
||||
|
||||
QList< query_ptr >
|
||||
DropJob::tracksFromArtistMetaData( const QMimeData *data )
|
||||
{
|
||||
@ -371,6 +379,7 @@ DropJob::tracksFromArtistMetaData( const QMimeData *data )
|
||||
return queries;
|
||||
}
|
||||
|
||||
|
||||
QList< query_ptr >
|
||||
DropJob::tracksFromMixedData( const QMimeData *data )
|
||||
{
|
||||
@ -419,6 +428,7 @@ DropJob::tracksFromMixedData( const QMimeData *data )
|
||||
return queries;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DropJob::handleXspfs( const QString& fileUrls )
|
||||
{
|
||||
@ -431,8 +441,7 @@ DropJob::handleXspfs( const QString& fileUrls )
|
||||
|
||||
foreach ( const QString& url, urls )
|
||||
{
|
||||
XSPFLoader* l;
|
||||
|
||||
XSPFLoader* l = 0;
|
||||
QFile xspfFile( QUrl::fromUserInput( url ).toLocalFile() );
|
||||
|
||||
if ( xspfFile.exists() )
|
||||
@ -441,9 +450,8 @@ DropJob::handleXspfs( const QString& fileUrls )
|
||||
tDebug( LOGINFO ) << "Loading local xspf " << xspfFile.fileName();
|
||||
l->load( xspfFile );
|
||||
}
|
||||
else if( QUrl( url ).isValid() )
|
||||
else if ( QUrl( url ).isValid() )
|
||||
{
|
||||
|
||||
l = new XSPFLoader( dropAction() == Create, this );
|
||||
tDebug( LOGINFO ) << "Loading remote xspf " << url;
|
||||
l->load( QUrl( url ) );
|
||||
@ -452,21 +460,18 @@ DropJob::handleXspfs( const QString& fileUrls )
|
||||
{
|
||||
error = true;
|
||||
tLog() << "Failed to load or parse dropped XSPF";
|
||||
|
||||
}
|
||||
|
||||
if ( dropAction() == Append && !error )
|
||||
if ( dropAction() == Append && !error && l )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Trying to append xspf";
|
||||
connect( l, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( onTracksAdded( QList< Tomahawk::query_ptr > ) ) );
|
||||
m_queryCount++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DropJob::handleSpotifyUrls( const QString& urlsRaw )
|
||||
{
|
||||
@ -492,6 +497,7 @@ DropJob::handleSpotifyUrls( const QString& urlsRaw )
|
||||
m_queryCount++;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DropJob::handleRdioUrls( const QString& urlsRaw )
|
||||
{
|
||||
@ -558,10 +564,8 @@ DropJob::handleTrackUrls( const QString& urls )
|
||||
m_queryCount++;
|
||||
|
||||
rdio->parse( tracks );
|
||||
} else if ( urls.contains( "bit.ly" ) ||
|
||||
urls.contains( "j.mp" ) ||
|
||||
urls.contains( "t.co" ) ||
|
||||
urls.contains( "rd.io" ) )
|
||||
}
|
||||
else if ( ShortenedLinkParser::handlesUrl( urls ) )
|
||||
{
|
||||
QStringList tracks = urls.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );
|
||||
|
||||
@ -572,6 +576,7 @@ DropJob::handleTrackUrls( const QString& urls )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DropJob::expandedUrls( QStringList urls )
|
||||
{
|
||||
@ -579,6 +584,7 @@ DropJob::expandedUrls( QStringList urls )
|
||||
handleAllUrls( urls.join( "\n" ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DropJob::onTracksAdded( const QList<Tomahawk::query_ptr>& tracksList )
|
||||
{
|
||||
@ -603,6 +609,7 @@ DropJob::onTracksAdded( const QList<Tomahawk::query_ptr>& tracksList )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DropJob::removeDuplicates()
|
||||
{
|
||||
@ -621,6 +628,7 @@ DropJob::removeDuplicates()
|
||||
m_resultList = list;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DropJob::removeRemoteSources()
|
||||
{
|
||||
@ -639,6 +647,7 @@ DropJob::removeRemoteSources()
|
||||
m_resultList = list;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DropJob::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
|
||||
{
|
||||
@ -668,6 +677,7 @@ DropJob::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVar
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QList< query_ptr >
|
||||
DropJob::getArtist( const QString &artist )
|
||||
{
|
||||
@ -683,6 +693,7 @@ DropJob::getArtist( const QString &artist )
|
||||
return artistPtr->tracks();
|
||||
}
|
||||
|
||||
|
||||
QList< query_ptr >
|
||||
DropJob::getAlbum(const QString &artist, const QString &album)
|
||||
{
|
||||
@ -706,6 +717,7 @@ DropJob::getAlbum(const QString &artist, const QString &album)
|
||||
return albumPtr->tracks();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DropJob::getTopTen( const QString &artist )
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.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
|
||||
@ -29,6 +30,7 @@
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
|
||||
ShortenedLinkParser::ShortenedLinkParser ( const QStringList& urls, QObject* parent )
|
||||
: QObject( parent )
|
||||
{
|
||||
@ -36,16 +38,28 @@ ShortenedLinkParser::ShortenedLinkParser ( const QStringList& urls, QObject* par
|
||||
lengthenUrl( url );
|
||||
}
|
||||
|
||||
ShortenedLinkParser::~ShortenedLinkParser() {}
|
||||
|
||||
ShortenedLinkParser::~ShortenedLinkParser()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
ShortenedLinkParser::handlesUrl( const QString& url )
|
||||
{
|
||||
// Whitelisted links
|
||||
return ( url.contains( "t.co" ) ||
|
||||
url.contains( "bit.ly" ) ||
|
||||
url.contains( "j.mp" ) ||
|
||||
url.contains( "spoti.fi" ) ||
|
||||
url.contains( "rd.io" ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ShortenedLinkParser::lengthenUrl( const QString& url )
|
||||
{
|
||||
// Whitelisted links
|
||||
if ( !( url.contains( "t.co" ) ||
|
||||
url.contains( "bit.ly" ) ||
|
||||
url.contains( "j.mp" ) ||
|
||||
url.contains( "rd.io" ) ) )
|
||||
if ( !handlesUrl( url ) )
|
||||
return;
|
||||
|
||||
tDebug() << "Looking up..." << url;
|
||||
@ -56,6 +70,7 @@ ShortenedLinkParser::lengthenUrl( const QString& url )
|
||||
m_queries.insert( reply );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ShortenedLinkParser::lookupFinished()
|
||||
{
|
||||
@ -86,5 +101,4 @@ ShortenedLinkParser::checkFinished()
|
||||
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.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
|
||||
@ -24,9 +25,10 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QSet>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QStringList>
|
||||
|
||||
class QNetworkReply;
|
||||
|
||||
namespace Tomahawk
|
||||
{
|
||||
|
||||
@ -39,10 +41,13 @@ namespace Tomahawk
|
||||
class DLLEXPORT ShortenedLinkParser : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ShortenedLinkParser( const QStringList& urls, QObject* parent = 0 );
|
||||
virtual ~ShortenedLinkParser();
|
||||
|
||||
static bool handlesUrl( const QString& url );
|
||||
|
||||
public slots:
|
||||
void lookupFinished();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user