-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Fix url lookup by adding LinkParser plugins #395
Open
dschmidt
wants to merge
2
commits into
master
Choose a base branch
from
linkparsers
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
* Copyright 2011, Leo Franchi <[email protected]> | ||
* Copyright 2011-2012, Jeff Mitchell <[email protected]> | ||
* Copyright 2011-2012, Christian Muehlhaeuser <[email protected]> | ||
* Copyright 2016, Dominik Schmidt <[email protected]> | ||
* | ||
* Tomahawk is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -35,6 +36,7 @@ | |
#include "utils/Logger.h" | ||
#include "utils/TomahawkUtils.h" | ||
#include "utils/XspfLoader.h" | ||
#include "utils/LinkParser.h" | ||
|
||
#include "Artist.h" | ||
#include "Album.h" | ||
|
@@ -172,12 +174,7 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType | |
if ( url.contains( "grooveshark.com" ) && url.contains( "playlist" ) ) | ||
return true; | ||
|
||
// Check Scriptresolvers | ||
foreach ( QPointer<ExternalResolver> resolver, Pipeline::instance()->scriptResolvers() ) | ||
{ | ||
if ( resolver->canParseUrl( url, ExternalResolver::UrlTypePlaylist ) ) | ||
return true; | ||
} | ||
return Tomahawk::Utils::LinkParser::instance()->canParseUrl( url, Tomahawk::Utils::UrlTypePlaylist ); | ||
} | ||
|
||
if ( acceptedType.testFlag( Track ) ) | ||
|
@@ -198,12 +195,7 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType | |
|| url.contains( "playlists" ) ) ) ) | ||
return true; | ||
|
||
// Check Scriptresolvers | ||
foreach ( QPointer<ExternalResolver> resolver, Pipeline::instance()->scriptResolvers() ) | ||
{ | ||
if ( resolver->canParseUrl( url, ExternalResolver::UrlTypeTrack ) ) | ||
return true; | ||
} | ||
return Tomahawk::Utils::LinkParser::instance()->canParseUrl( url, Tomahawk::Utils::UrlTypeTrack ); | ||
} | ||
|
||
if ( acceptedType.testFlag( Album ) ) | ||
|
@@ -215,12 +207,7 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType | |
if ( url.contains( "rdio.com" ) && ( url.contains( "artist" ) && url.contains( "album" ) && !url.contains( "track" ) ) ) | ||
return true; | ||
|
||
// Check Scriptresolvers | ||
foreach ( QPointer<ExternalResolver> resolver, Pipeline::instance()->scriptResolvers() ) | ||
{ | ||
if ( resolver->canParseUrl( url, ExternalResolver::UrlTypeAlbum ) ) | ||
return true; | ||
} | ||
return Tomahawk::Utils::LinkParser::instance()->canParseUrl( url, Tomahawk::Utils::UrlTypeAlbum ); | ||
} | ||
|
||
if ( acceptedType.testFlag( Artist ) ) | ||
|
@@ -232,12 +219,7 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType | |
if ( url.contains( "rdio.com" ) && ( url.contains( "artist" ) && !url.contains( "album" ) && !url.contains( "track" ) ) ) | ||
return true; | ||
|
||
// Check Scriptresolvers | ||
foreach ( QPointer<ExternalResolver> resolver, Pipeline::instance()->scriptResolvers() ) | ||
{ | ||
if ( resolver->canParseUrl( url, ExternalResolver::UrlTypeArtist ) ) | ||
return true; | ||
} | ||
return Tomahawk::Utils::LinkParser::instance()->canParseUrl( url, Tomahawk::Utils::UrlTypeArtist ); | ||
} | ||
|
||
// We whitelist certain url-shorteners since they do some link checking. Often playable (e.g. spotify) links hide behind them, | ||
|
@@ -303,15 +285,7 @@ DropJob::isDropType( DropJob::DropType desired, const QMimeData* data ) | |
if ( ShortenedLinkParser::handlesUrl( url ) ) | ||
return true; | ||
|
||
// Check Scriptresolvers | ||
foreach ( QPointer<ExternalResolver> resolver, Pipeline::instance()->scriptResolvers() ) | ||
{ | ||
if ( resolver->canParseUrl( url, ExternalResolver::UrlTypePlaylist ) ) | ||
{ | ||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Accepting current drop as a playlist" << resolver->name(); | ||
return true; | ||
} | ||
} | ||
return Tomahawk::Utils::LinkParser::instance()->canParseUrl( url, Tomahawk::Utils::UrlTypePlaylist ); | ||
|
||
} | ||
|
||
|
@@ -761,16 +735,12 @@ DropJob::handleTrackUrls( const QString& urls ) | |
|
||
foreach ( QString track, tracks ) | ||
{ | ||
foreach ( QPointer<ExternalResolver> resolver, Pipeline::instance()->scriptResolvers() ) | ||
QList< QSharedPointer< Utils::LinkParserPlugin > > parserPlugins = Utils::LinkParser::instance()->parserPluginsForUrl( track, Utils::UrlTypeAny ); | ||
if( !parserPlugins.isEmpty() ) | ||
{ | ||
if ( resolver->canParseUrl( track, ExternalResolver::UrlTypeAny ) ) | ||
{ | ||
ScriptCommand_LookupUrl* cmd = new ScriptCommand_LookupUrl( resolver, track ); | ||
connect( cmd, SIGNAL( information( QString, QSharedPointer<QObject> ) ), this, SLOT( informationForUrl( QString, QSharedPointer<QObject> ) ) ); | ||
cmd->enqueue(); | ||
m_queryCount++; | ||
break; | ||
} | ||
Tomahawk::Utils::LinkParser::instance()->lookupUrl( track, parserPlugins ); | ||
connect( Tomahawk::Utils::LinkParser::instance(), SIGNAL( informationFound( QString, QSharedPointer<QObject> ) ), this, SLOT( informationForUrl( QString, QSharedPointer<QObject> ) ) ); | ||
m_queryCount++; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
* Copyright (C) 2011-2014, Christian Muehlhaeuser <[email protected]> | ||
* Copyright (C) 2013, Uwe L. Korn <[email protected]> | ||
* Copyright (C) 2013, Teo Mrnjavac <[email protected]> | ||
* Copyright (C) 2016, Dominik Schmidt <[email protected]> | ||
* | ||
* Tomahawk is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -35,13 +36,13 @@ | |
#include "playlist/TrackView.h" | ||
#include "playlist/PlayableModel.h" | ||
#include "resolvers/ExternalResolver.h" | ||
#include "resolvers/ScriptCommand_LookupUrl.h" | ||
#include "utils/JspfLoader.h" | ||
#include "utils/Logger.h" | ||
#include "utils/SpotifyParser.h" | ||
#include "utils/XspfLoader.h" | ||
#include "utils/XspfGenerator.h" | ||
#include "viewpages/SearchViewPage.h" | ||
#include "utils/LinkParser.h" | ||
|
||
#include "Pipeline.h" | ||
#include "TomahawkSettings.h" | ||
|
@@ -162,27 +163,12 @@ GlobalActionManager::openUrl( const QString& url ) | |
else if ( url.contains( "open.spotify.com" ) || url.startsWith( "spotify:" ) ) | ||
return openSpotifyLink( url ); | ||
|
||
// Can we parse the Url using a ScriptResolver? | ||
bool canParse = false; | ||
QList< QPointer< ExternalResolver > > possibleResolvers; | ||
foreach ( QPointer<ExternalResolver> resolver, Pipeline::instance()->scriptResolvers() ) | ||
// Can we parse the Url using LinkParser? | ||
QList< QSharedPointer< Utils::LinkParserPlugin > > parserPlugins = Utils::LinkParser::instance()->parserPluginsForUrl( url, Utils::UrlTypeAny ); | ||
if( !parserPlugins.isEmpty() ) | ||
{ | ||
if ( resolver->canParseUrl( url, ExternalResolver::UrlTypeAny ) ) | ||
{ | ||
canParse = true; | ||
possibleResolvers << resolver; | ||
} | ||
} | ||
if ( canParse ) | ||
{ | ||
m_queuedUrl = url; | ||
foreach ( QPointer<ExternalResolver> resolver, possibleResolvers ) | ||
{ | ||
ScriptCommand_LookupUrl* cmd = new ScriptCommand_LookupUrl( resolver, url ); | ||
connect( cmd, SIGNAL( information( QString, QSharedPointer<QObject> ) ), this, SLOT( informationForUrl( QString, QSharedPointer<QObject> ) ) ); | ||
cmd->enqueue(); | ||
} | ||
|
||
Tomahawk::Utils::LinkParser::instance()->lookupUrl( url, parserPlugins ); | ||
connect( Tomahawk::Utils::LinkParser::instance(), SIGNAL( informationFound( QString, QSharedPointer<QObject> ) ), this, SLOT( informationForUrl( QString, QSharedPointer<QObject> ) ), Qt::UniqueConnection ); | ||
return true; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
* Copyright 2010-2011, Christian Muehlhaeuser <[email protected]> | ||
* Copyright 2010-2011, Leo Franchi <[email protected]> | ||
* Copyright 2013, Teo Mrnjavac <[email protected]> | ||
* Copyright 2016, Dominik Schmidt <[email protected]> | ||
* | ||
* 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,8 +25,6 @@ | |
#include "Source.h" | ||
#include "DllMacro.h" | ||
#include "Resolver.h" | ||
#include "ScriptCommandQueue.h" | ||
#include "ScriptCommand_LookupUrl.h" | ||
#include "Typedefs.h" | ||
|
||
#include <QObject> | ||
|
@@ -45,7 +44,6 @@ class DLLEXPORT ExternalResolver : public Resolver | |
{ | ||
Q_OBJECT | ||
|
||
friend class ScriptCommandQueue; | ||
friend class ScriptCommand_LookupUrl; | ||
|
||
public: | ||
|
@@ -61,26 +59,13 @@ Q_OBJECT | |
Browsable = 0x1, // can be represented in one or more collection tree views | ||
PlaylistSync = 0x2, // can sync playlists | ||
AccountFactory = 0x4, // can configure multiple accounts at the same time | ||
UrlLookup = 0x8 // can be queried for information on an Url | ||
}; | ||
Q_DECLARE_FLAGS( Capabilities, Capability ) | ||
Q_FLAGS( Capabilities ) | ||
|
||
enum UrlType | ||
{ | ||
UrlTypeAny = 0x00, | ||
UrlTypePlaylist = 0x01, | ||
UrlTypeTrack = 0x02, | ||
UrlTypeAlbum = 0x04, | ||
UrlTypeArtist = 0x08, | ||
UrlTypeXspf = 0x10 | ||
}; | ||
Q_DECLARE_FLAGS( UrlTypes, UrlType ) | ||
Q_FLAGS( UrlTypes ) | ||
|
||
ExternalResolver( const QString& filePath ) | ||
: m_commandQueue( new ScriptCommandQueue( this ) ) | ||
{ m_filePath = filePath; } | ||
: m_filePath( filePath ) | ||
{} | ||
|
||
QString filePath() const { return m_filePath; } | ||
virtual void setIcon( const QPixmap& ) {} | ||
|
@@ -92,12 +77,6 @@ Q_OBJECT | |
virtual bool running() const = 0; | ||
virtual Capabilities capabilities() const = 0; | ||
|
||
// UrlLookup, sync call | ||
virtual bool canParseUrl( const QString& url, UrlType type ) = 0; | ||
|
||
virtual void enqueue( const QSharedPointer< ScriptCommand >& req ) | ||
{ m_commandQueue->enqueue( req ); } | ||
|
||
public slots: | ||
virtual void start() = 0; | ||
virtual void stop() = 0; | ||
|
@@ -112,11 +91,6 @@ public slots: | |
|
||
protected: | ||
void setFilePath( const QString& path ) { m_filePath = path; } | ||
ScriptCommandQueue* m_commandQueue; | ||
|
||
// Should only be called by ScriptCommands | ||
// UrlLookup | ||
virtual void lookupUrl( const QString& url ) = 0; | ||
|
||
private: | ||
QString m_filePath; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably remove this as well, as grooveshark is dead by now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough