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