Skip to content

Commit

Permalink
Merge pull request #507 from mickael9/mickael9-patch-1
Browse files Browse the repository at this point in the history
Allow downloads from a non-collection resolver
  • Loading branch information
dschmidt committed Sep 19, 2016
2 parents 84ed59f + 7e54e50 commit 3e2d741
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 13 deletions.
11 changes: 11 additions & 0 deletions data/js/tomahawk.js
Expand Up @@ -275,6 +275,9 @@ Tomahawk.Resolver = {
getStreamUrl: function (params) {
return params;
},
getDownloadUrl: function (params) {
return params;
},
resolve: function() {
},
_adapter_resolve: function (params) {
Expand Down Expand Up @@ -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;
}
};
21 changes: 8 additions & 13 deletions src/libtomahawk/DownloadJob.cpp
Expand Up @@ -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;
setState( Running );

// 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;
}

Expand Down
11 changes: 11 additions & 0 deletions src/libtomahawk/resolvers/JSResolver.cpp
Expand Up @@ -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 );
}
2 changes: 2 additions & 0 deletions src/libtomahawk/resolvers/JSResolver.h
Expand Up @@ -76,6 +76,8 @@ friend class JSAccount;
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;
Expand Down
9 changes: 9 additions & 0 deletions src/libtomahawk/resolvers/Resolver.cpp
Expand Up @@ -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 );
}
2 changes: 2 additions & 0 deletions src/libtomahawk/resolvers/Resolver.h
Expand Up @@ -21,6 +21,7 @@

#include "Typedefs.h"
#include "DllMacro.h"
#include "../DownloadJob.h"

#include <QObject>

Expand Down Expand Up @@ -52,6 +53,7 @@ Q_OBJECT

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
Expand Down
10 changes: 10 additions & 0 deletions src/libtomahawk/resolvers/ScriptCollection.cpp
Expand Up @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions src/libtomahawk/resolvers/ScriptCollection.h
Expand Up @@ -96,6 +96,7 @@ Q_OBJECT
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();
Expand Down

0 comments on commit 3e2d741

Please sign in to comment.