mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
[0.9 api]always register custom url handler for resolver
This commit is contained in:
@@ -228,6 +228,9 @@ var TomahawkResolver = {
|
|||||||
collection: function () {
|
collection: function () {
|
||||||
return {};
|
return {};
|
||||||
},
|
},
|
||||||
|
getStreamUrl: function(params) {
|
||||||
|
Tomahawk.reportStreamUrl(params.qid, params.url);
|
||||||
|
},
|
||||||
_testConfig: function (config) {
|
_testConfig: function (config) {
|
||||||
return Promise.resolve(this.testConfig(config)).then(function() {
|
return Promise.resolve(this.testConfig(config)).then(function() {
|
||||||
return { result: Tomahawk.ConfigTestResultType.Success };
|
return { result: Tomahawk.ConfigTestResultType.Success };
|
||||||
@@ -243,6 +246,17 @@ Tomahawk.Resolver = Tomahawk.extend(TomahawkResolver, {
|
|||||||
window.localStorage[this.scriptPath()] = JSON.stringify(Tomahawk.resolverData().config);
|
window.localStorage[this.scriptPath()] = JSON.stringify(Tomahawk.resolverData().config);
|
||||||
this.newConfigSaved(Tomahawk.resolverData().config);
|
this.newConfigSaved(Tomahawk.resolverData().config);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_convertUrls: function(results) {
|
||||||
|
var that = this;
|
||||||
|
return results.map(function(r){
|
||||||
|
if(r.url) {
|
||||||
|
r.url = that._urlProtocol + '://' + r.url;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
_adapter_resolve: function (qid, artist, album, title) {
|
_adapter_resolve: function (qid, artist, album, title) {
|
||||||
var that = this;
|
var that = this;
|
||||||
var collectionPromises = [];
|
var collectionPromises = [];
|
||||||
@@ -257,13 +271,22 @@ Tomahawk.Resolver = Tomahawk.extend(TomahawkResolver, {
|
|||||||
Promise.resolve(that.resolve({artist: artist, album: album, track:title})).then(function(results){
|
Promise.resolve(that.resolve({artist: artist, album: album, track:title})).then(function(results){
|
||||||
Tomahawk.addTrackResults({
|
Tomahawk.addTrackResults({
|
||||||
'qid': qid,
|
'qid': qid,
|
||||||
'results': results.concat(collectionResults)
|
'results': that._convertUrls(results.concat(collectionResults))
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_adapter_init: function ()
|
||||||
|
{
|
||||||
|
this._urlProtocol = this.settings.name.replace(/\s+/g, '').toLowerCase();
|
||||||
|
Tomahawk.addCustomUrlHandler( this._urlProtocol, 'getStreamUrl', true );
|
||||||
|
Tomahawk.log('Registered custom url handler for protocol "' + this._urlProtocol + '"');
|
||||||
|
this.init();
|
||||||
|
},
|
||||||
|
|
||||||
_adapter_getStreamUrl: function (params) {
|
_adapter_getStreamUrl: function (params) {
|
||||||
|
params.url = params.url.slice(this._urlProtocol.length + 3);
|
||||||
Promise.resolve(this.getStreamUrl(params)).then(function(result){
|
Promise.resolve(this.getStreamUrl(params)).then(function(result){
|
||||||
Tomahawk.reportStreamUrl(params.qid, result.url, result.headers);
|
Tomahawk.reportStreamUrl(params.qid, result.url, result.headers);
|
||||||
});
|
});
|
||||||
@@ -271,13 +294,15 @@ Tomahawk.Resolver = Tomahawk.extend(TomahawkResolver, {
|
|||||||
|
|
||||||
_adapter_search: function (qid, query)
|
_adapter_search: function (qid, query)
|
||||||
{
|
{
|
||||||
|
var that = this;
|
||||||
Promise.resolve(this.search({query:query})).then(function(results){
|
Promise.resolve(this.search({query:query})).then(function(results){
|
||||||
Tomahawk.addTrackResults({
|
Tomahawk.addTrackResults({
|
||||||
'qid': qid,
|
'qid': qid,
|
||||||
'results': results
|
'results': that._convertUrls(results)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_adapter_testConfig: function (config) {
|
_adapter_testConfig: function (config) {
|
||||||
return Promise.resolve(this.testConfig(config)).then(function() {
|
return Promise.resolve(this.testConfig(config)).then(function() {
|
||||||
return { result: Tomahawk.ConfigTestResultType.Success };
|
return { result: Tomahawk.ConfigTestResultType.Success };
|
||||||
@@ -1337,6 +1362,7 @@ Tomahawk.Collection = {
|
|||||||
|
|
||||||
},
|
},
|
||||||
addTracks: function (params) {
|
addTracks: function (params) {
|
||||||
|
var that = this;
|
||||||
var id = params.id;
|
var id = params.id;
|
||||||
var tracks = params.tracks;
|
var tracks = params.tracks;
|
||||||
|
|
||||||
@@ -1639,7 +1665,7 @@ Tomahawk.Collection = {
|
|||||||
);
|
);
|
||||||
return t.execDefferedStatements();
|
return t.execDefferedStatements();
|
||||||
}).then(function (results) {
|
}).then(function (results) {
|
||||||
return {results: results[0]};
|
return {results: Tomahawk.resolver.instance._convertUrls(results[0])};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user