1
0
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:
Dominik Schmidt 2016-09-19 23:08:26 +02:00 committed by GitHub
commit 3e2d74128d
8 changed files with 54 additions and 13 deletions

View File

@ -275,6 +275,9 @@ Tomahawk.Resolver = {
getStreamUrl: function (params) { getStreamUrl: function (params) {
return params; return params;
}, },
getDownloadUrl: function (params) {
return params;
},
resolve: function() { resolve: function() {
}, },
_adapter_resolve: function (params) { _adapter_resolve: function (params) {
@ -1771,6 +1774,14 @@ Tomahawk.Collection = {
return this.resolver.getStreamUrl(params); return this.resolver.getStreamUrl(params);
} }
return params;
},
getDownloadUrl: function(params) {
if(this.resolver) {
return this.resolver.getDownloadUrl(params);
}
return params; return params;
} }
}; };

View File

@ -206,22 +206,17 @@ DownloadJob::download()
{ {
if ( m_state == Running ) if ( m_state == Running )
return true; return true;
setState( Running ); setState( Running );
if ( m_result->resolvedByCollection() ) if (m_result->resolvedBy() != nullptr) {
{ Tomahawk::ScriptJob *job = m_result->resolvedBy()->getDownloadUrl( m_result, m_format );
Tomahawk::ScriptCollection* collection = qobject_cast<Tomahawk::ScriptCollection*>( m_result->resolvedByCollection().data() ); connect( job, SIGNAL( done(QVariantMap) ), SLOT( onUrlRetrieved(QVariantMap) ) );
if ( collection ) job->start();
{ } else {
QVariantMap arguments; onUrlRetrieved({{"url", m_format.url}});
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();
}
} }
return true; return true;
} }

View File

@ -711,3 +711,14 @@ JSResolver::getStreamUrl( const result_ptr& result )
return scriptObject()->invoke( "getStreamUrl", arguments ); 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 );
}

View File

@ -76,6 +76,8 @@ public:
ScriptAccount* scriptAccount() const; ScriptAccount* scriptAccount() const;
ScriptJob* getStreamUrl( const result_ptr& result ) override; ScriptJob* getStreamUrl( const result_ptr& result ) override;
ScriptJob* getDownloadUrl( const result_ptr& result, const DownloadFormat &format ) override;
public slots: public slots:
void resolve( const Tomahawk::query_ptr& query ) override; void resolve( const Tomahawk::query_ptr& query ) override;

View File

@ -45,3 +45,12 @@ Tomahawk::Resolver::getStreamUrl( const result_ptr& result )
return new SyncScriptJob( data ); 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 );
}

View File

@ -21,6 +21,7 @@
#include "Typedefs.h" #include "Typedefs.h"
#include "DllMacro.h" #include "DllMacro.h"
#include "../DownloadJob.h"
#include <QObject> #include <QObject>
@ -52,6 +53,7 @@ public:
virtual void resolve( const Tomahawk::query_ptr& query ) = 0; virtual void resolve( const Tomahawk::query_ptr& query ) = 0;
virtual ScriptJob* getStreamUrl( const result_ptr& result ); virtual ScriptJob* getStreamUrl( const result_ptr& result );
virtual ScriptJob* getDownloadUrl( const result_ptr& result, const DownloadFormat& format );
}; };
} //ns } //ns

View File

@ -235,6 +235,16 @@ ScriptCollection::getStreamUrl( const result_ptr& result )
return scriptObject()->invoke( "getStreamUrl", arguments ); 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 void
ScriptCollection::parseMetaData( const QVariantMap& metadata ) ScriptCollection::parseMetaData( const QVariantMap& metadata )

View File

@ -96,6 +96,7 @@ public:
unsigned int timeout() const override; unsigned int timeout() const override;
void resolve( const Tomahawk::query_ptr& query ) override; void resolve( const Tomahawk::query_ptr& query ) override;
ScriptJob* getStreamUrl( const result_ptr& result ) override; ScriptJob* getStreamUrl( const result_ptr& result ) override;
ScriptJob* getDownloadUrl( const result_ptr& result, const DownloadFormat &format ) override;
private slots: private slots:
void onIconFetched(); void onIconFetched();