mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-01-17 14:28:24 +01:00
Merge pull request #507 from mickael9/mickael9-patch-1
Allow downloads from a non-collection resolver
This commit is contained in:
commit
3e2d74128d
@ -275,6 +275,9 @@ Tomahawk.Resolver = {
|
||||
getStreamUrl: function (params) {
|
||||
return params;
|
||||
},
|
||||
getDownloadUrl: function (params) {
|
||||
return params;
|
||||
},
|
||||
resolve: function() {
|
||||
},
|
||||
_adapter_resolve: function (params) {
|
||||
@ -1771,6 +1774,14 @@ Tomahawk.Collection = {
|
||||
return this.resolver.getStreamUrl(params);
|
||||
}
|
||||
|
||||
return params;
|
||||
},
|
||||
|
||||
getDownloadUrl: function(params) {
|
||||
if(this.resolver) {
|
||||
return this.resolver.getDownloadUrl(params);
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
};
|
||||
|
@ -206,22 +206,17 @@ DownloadJob::download()
|
||||
{
|
||||
if ( m_state == Running )
|
||||
return true;
|
||||
|
||||
setState( Running );
|
||||
|
||||
if ( m_result->resolvedByCollection() )
|
||||
{
|
||||
Tomahawk::ScriptCollection* collection = qobject_cast<Tomahawk::ScriptCollection*>( m_result->resolvedByCollection().data() );
|
||||
if ( collection )
|
||||
{
|
||||
QVariantMap arguments;
|
||||
arguments[ "url" ] = m_format.url;
|
||||
|
||||
// HACK: *shrug* WIP.
|
||||
Tomahawk::ScriptJob* job = collection->scriptObject()->invoke( "getStreamUrl", arguments );
|
||||
connect( job, SIGNAL( done(QVariantMap) ), SLOT( onUrlRetrieved(QVariantMap) ) );
|
||||
job->start();
|
||||
}
|
||||
if (m_result->resolvedBy() != nullptr) {
|
||||
Tomahawk::ScriptJob *job = m_result->resolvedBy()->getDownloadUrl( m_result, m_format );
|
||||
connect( job, SIGNAL( done(QVariantMap) ), SLOT( onUrlRetrieved(QVariantMap) ) );
|
||||
job->start();
|
||||
} else {
|
||||
onUrlRetrieved({{"url", m_format.url}});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -711,3 +711,14 @@ JSResolver::getStreamUrl( const result_ptr& result )
|
||||
|
||||
return scriptObject()->invoke( "getStreamUrl", arguments );
|
||||
}
|
||||
|
||||
ScriptJob*
|
||||
JSResolver::getDownloadUrl( const result_ptr& result, const DownloadFormat& format )
|
||||
{
|
||||
QVariantMap arguments;
|
||||
arguments["url"] = format.url.toString();
|
||||
arguments["extension"] = format.extension;
|
||||
arguments["mimetype"] = format.mimetype;
|
||||
|
||||
return scriptObject()->invoke( "getDownloadUrl", arguments );
|
||||
}
|
||||
|
@ -76,6 +76,8 @@ public:
|
||||
ScriptAccount* scriptAccount() const;
|
||||
|
||||
ScriptJob* getStreamUrl( const result_ptr& result ) override;
|
||||
ScriptJob* getDownloadUrl( const result_ptr& result, const DownloadFormat &format ) override;
|
||||
|
||||
|
||||
public slots:
|
||||
void resolve( const Tomahawk::query_ptr& query ) override;
|
||||
|
@ -45,3 +45,12 @@ Tomahawk::Resolver::getStreamUrl( const result_ptr& result )
|
||||
|
||||
return new SyncScriptJob( data );
|
||||
}
|
||||
|
||||
Tomahawk::ScriptJob*
|
||||
Tomahawk::Resolver::getDownloadUrl( const result_ptr& result, const DownloadFormat& format )
|
||||
{
|
||||
QVariantMap data;
|
||||
data[ "url" ] = format.url.toString();
|
||||
|
||||
return new SyncScriptJob( data );
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "Typedefs.h"
|
||||
#include "DllMacro.h"
|
||||
#include "../DownloadJob.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
@ -52,6 +53,7 @@ public:
|
||||
|
||||
virtual void resolve( const Tomahawk::query_ptr& query ) = 0;
|
||||
virtual ScriptJob* getStreamUrl( const result_ptr& result );
|
||||
virtual ScriptJob* getDownloadUrl( const result_ptr& result, const DownloadFormat& format );
|
||||
};
|
||||
|
||||
} //ns
|
||||
|
@ -235,6 +235,16 @@ ScriptCollection::getStreamUrl( const result_ptr& result )
|
||||
return scriptObject()->invoke( "getStreamUrl", arguments );
|
||||
}
|
||||
|
||||
ScriptJob*
|
||||
ScriptCollection::getDownloadUrl( const result_ptr& result, const DownloadFormat& format )
|
||||
{
|
||||
QVariantMap arguments;
|
||||
arguments["url"] = format.url.toString();
|
||||
arguments["extension"] = format.extension;
|
||||
arguments["mimetype"] = format.mimetype;
|
||||
|
||||
return scriptObject()->invoke( "getDownloadUrl", arguments );
|
||||
}
|
||||
|
||||
void
|
||||
ScriptCollection::parseMetaData( const QVariantMap& metadata )
|
||||
|
@ -96,6 +96,7 @@ public:
|
||||
unsigned int timeout() const override;
|
||||
void resolve( const Tomahawk::query_ptr& query ) override;
|
||||
ScriptJob* getStreamUrl( const result_ptr& result ) override;
|
||||
ScriptJob* getDownloadUrl( const result_ptr& result, const DownloadFormat &format ) override;
|
||||
|
||||
private slots:
|
||||
void onIconFetched();
|
||||
|
Loading…
x
Reference in New Issue
Block a user