mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-11 08:34:34 +02:00
Add JavaScript InfoPlugins
This commit is contained in:
18
data/js/es6-promise-2.0.0.min.js
vendored
Normal file
18
data/js/es6-promise-2.0.0.min.js
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
/*!
|
||||
* @overview es6-promise - a tiny implementation of Promises/A+.
|
||||
* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
|
||||
* @license Licensed under MIT license
|
||||
* See https://raw.githubusercontent.com/jakearchibald/es6-promise/master/LICENSE
|
||||
* @version 2.0.0
|
||||
*/
|
||||
|
||||
(function(){function r(a,b){n[l]=a;n[l+1]=b;l+=2;2===l&&A()}function s(a){return"function"===typeof a}function F(){return function(){process.nextTick(t)}}function G(){var a=0,b=new B(t),c=document.createTextNode("");b.observe(c,{characterData:!0});return function(){c.data=a=++a%2}}function H(){var a=new MessageChannel;a.port1.onmessage=t;return function(){a.port2.postMessage(0)}}function I(){return function(){setTimeout(t,1)}}function t(){for(var a=0;a<l;a+=2)(0,n[a])(n[a+1]),n[a]=void 0,n[a+1]=void 0;
|
||||
l=0}function p(){}function J(a,b,c,d){try{a.call(b,c,d)}catch(e){return e}}function K(a,b,c){r(function(a){var e=!1,f=J(c,b,function(c){e||(e=!0,b!==c?q(a,c):m(a,c))},function(b){e||(e=!0,g(a,b))});!e&&f&&(e=!0,g(a,f))},a)}function L(a,b){1===b.a?m(a,b.b):2===a.a?g(a,b.b):u(b,void 0,function(b){q(a,b)},function(b){g(a,b)})}function q(a,b){if(a===b)g(a,new TypeError("You cannot resolve a promise with itself"));else if("function"===typeof b||"object"===typeof b&&null!==b)if(b.constructor===a.constructor)L(a,
|
||||
b);else{var c;try{c=b.then}catch(d){v.error=d,c=v}c===v?g(a,v.error):void 0===c?m(a,b):s(c)?K(a,b,c):m(a,b)}else m(a,b)}function M(a){a.d&&a.d(a.b);x(a)}function m(a,b){void 0===a.a&&(a.b=b,a.a=1,0!==a.f.length&&r(x,a))}function g(a,b){void 0===a.a&&(a.a=2,a.b=b,r(M,a))}function u(a,b,c,d){var e=a.f,f=e.length;a.d=null;e[f]=b;e[f+1]=c;e[f+2]=d;0===f&&a.a&&r(x,a)}function x(a){var b=a.f,c=a.a;if(0!==b.length){for(var d,e,f=a.b,g=0;g<b.length;g+=3)d=b[g],e=b[g+c],d?C(c,d,e,f):e(f);a.f.length=0}}function D(){this.error=
|
||||
null}function C(a,b,c,d){var e=s(c),f,k,h,l;if(e){try{f=c(d)}catch(n){y.error=n,f=y}f===y?(l=!0,k=f.error,f=null):h=!0;if(b===f){g(b,new TypeError("A promises callback cannot return that same promise."));return}}else f=d,h=!0;void 0===b.a&&(e&&h?q(b,f):l?g(b,k):1===a?m(b,f):2===a&&g(b,f))}function N(a,b){try{b(function(b){q(a,b)},function(b){g(a,b)})}catch(c){g(a,c)}}function k(a,b,c,d){this.n=a;this.c=new a(p,d);this.i=c;this.o(b)?(this.m=b,this.e=this.length=b.length,this.l(),0===this.length?m(this.c,
|
||||
this.b):(this.length=this.length||0,this.k(),0===this.e&&m(this.c,this.b))):g(this.c,this.p())}function h(a){O++;this.b=this.a=void 0;this.f=[];if(p!==a){if(!s(a))throw new TypeError("You must pass a resolver function as the first argument to the promise constructor");if(!(this instanceof h))throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");N(this,a)}}var E=Array.isArray?Array.isArray:function(a){return"[object Array]"===
|
||||
Object.prototype.toString.call(a)},l=0,w="undefined"!==typeof window?window:{},B=w.MutationObserver||w.WebKitMutationObserver,w="undefined"!==typeof Uint8ClampedArray&&"undefined"!==typeof importScripts&&"undefined"!==typeof MessageChannel,n=Array(1E3),A;A="undefined"!==typeof process&&"[object process]"==={}.toString.call(process)?F():B?G():w?H():I();var v=new D,y=new D;k.prototype.o=function(a){return E(a)};k.prototype.p=function(){return Error("Array Methods must be provided an Array")};k.prototype.l=
|
||||
function(){this.b=Array(this.length)};k.prototype.k=function(){for(var a=this.length,b=this.c,c=this.m,d=0;void 0===b.a&&d<a;d++)this.j(c[d],d)};k.prototype.j=function(a,b){var c=this.n;"object"===typeof a&&null!==a?a.constructor===c&&void 0!==a.a?(a.d=null,this.g(a.a,b,a.b)):this.q(c.resolve(a),b):(this.e--,this.b[b]=this.h(a))};k.prototype.g=function(a,b,c){var d=this.c;void 0===d.a&&(this.e--,this.i&&2===a?g(d,c):this.b[b]=this.h(c));0===this.e&&m(d,this.b)};k.prototype.h=function(a){return a};
|
||||
k.prototype.q=function(a,b){var c=this;u(a,void 0,function(a){c.g(1,b,a)},function(a){c.g(2,b,a)})};var O=0;h.all=function(a,b){return(new k(this,a,!0,b)).c};h.race=function(a,b){function c(a){q(e,a)}function d(a){g(e,a)}var e=new this(p,b);if(!E(a))return (g(e,new TypeError("You must pass an array to race.")), e);for(var f=a.length,h=0;void 0===e.a&&h<f;h++)u(this.resolve(a[h]),void 0,c,d);return e};h.resolve=function(a,b){if(a&&"object"===typeof a&&a.constructor===this)return a;var c=new this(p,b);
|
||||
q(c,a);return c};h.reject=function(a,b){var c=new this(p,b);g(c,a);return c};h.prototype={constructor:h,then:function(a,b,c){var d=this.a;if(1===d&&!a||2===d&&!b)return this;this.d=null;var e=new this.constructor(p,c),f=this.b;if(d){var g=arguments[d-1];r(function(){C(d,e,g,f)})}else u(this,e,a,b);return e},"catch":function(a,b){return this.then(null,a,b)}};var z={Promise:h,r:function(){var a;a="undefined"!==typeof global?global:"undefined"!==typeof window&&window.document?window:self;"Promise"in
|
||||
a&&"resolve"in a.Promise&&"reject"in a.Promise&&"all"in a.Promise&&"race"in a.Promise&&function(){var b;new a.Promise(function(a){b=a});return s(b)}()||(a.Promise=h)}};"function"===typeof define&&define.amd?define(function(){return z}):"undefined"!==typeof module&&module.exports?module.exports=z:"undefined"!==typeof this&&(this.ES6Promise=z)}).call(this);
|
160
data/js/tomahawk-infosystem.js
Normal file
160
data/js/tomahawk-infosystem.js
Normal file
@@ -0,0 +1,160 @@
|
||||
// install ES6Promise as global Promise
|
||||
if(window.Promise === undefined) {
|
||||
window.Promise = window.ES6Promise.Promise;
|
||||
}
|
||||
|
||||
// TODO: find a way to enumerate TypeInfo instead of copying this manually
|
||||
|
||||
Tomahawk.InfoSystem.InfoType = Object.create(null);
|
||||
|
||||
Tomahawk.InfoSystem.InfoType.InfoNoInfo = 0; //WARNING: *ALWAYS* keep this first!
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackID = 1;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackArtist = 2;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackAlbum = 3;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackGenre = 4;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackComposer = 5;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackDate = 6;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackNumber = 7;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackDiscNumber = 8;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackBitRate = 9;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackLength = 10;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackSampleRate = 11;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackFileSize = 12;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackBPM = 13;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackReplayGain = 14;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackReplayPeakGain = 15;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackLyrics = 16;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackLocation = 17;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackProfile = 18;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackEnergy = 19;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackDanceability = 20;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackTempo = 21;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackLoudness = 22;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackSimilars = 23; // cached -- do not change
|
||||
|
||||
Tomahawk.InfoSystem.InfoType.InfoArtistID = 25;
|
||||
Tomahawk.InfoSystem.InfoType.InfoArtistName = 26;
|
||||
Tomahawk.InfoSystem.InfoType.InfoArtistBiography = 27;
|
||||
Tomahawk.InfoSystem.InfoType.InfoArtistImages = 28; //cached -- do not change
|
||||
Tomahawk.InfoSystem.InfoType.InfoArtistBlog = 29;
|
||||
Tomahawk.InfoSystem.InfoType.InfoArtistFamiliarity = 30;
|
||||
Tomahawk.InfoSystem.InfoType.InfoArtistHotttness = 31;
|
||||
Tomahawk.InfoSystem.InfoType.InfoArtistSongs = 32; //cached -- do not change
|
||||
Tomahawk.InfoSystem.InfoType.InfoArtistSimilars = 33; //cached -- do not change
|
||||
Tomahawk.InfoSystem.InfoType.InfoArtistNews = 34;
|
||||
Tomahawk.InfoSystem.InfoType.InfoArtistProfile = 35;
|
||||
Tomahawk.InfoSystem.InfoType.InfoArtistReviews = 36;
|
||||
Tomahawk.InfoSystem.InfoType.InfoArtistTerms = 37;
|
||||
Tomahawk.InfoSystem.InfoType.InfoArtistLinks = 38;
|
||||
Tomahawk.InfoSystem.InfoType.InfoArtistVideos = 39;
|
||||
Tomahawk.InfoSystem.InfoType.InfoArtistReleases = 40;
|
||||
|
||||
Tomahawk.InfoSystem.InfoType.InfoAlbumID = 42;
|
||||
Tomahawk.InfoSystem.InfoType.InfoAlbumCoverArt = 43; //cached -- do not change
|
||||
Tomahawk.InfoSystem.InfoType.InfoAlbumName = 44;
|
||||
Tomahawk.InfoSystem.InfoType.InfoAlbumArtist = 45;
|
||||
Tomahawk.InfoSystem.InfoType.InfoAlbumDate = 46;
|
||||
Tomahawk.InfoSystem.InfoType.InfoAlbumGenre = 47;
|
||||
Tomahawk.InfoSystem.InfoType.InfoAlbumComposer = 48;
|
||||
Tomahawk.InfoSystem.InfoType.InfoAlbumSongs = 49;
|
||||
|
||||
Tomahawk.InfoSystem.InfoType.InfoChartCapabilities = 50;
|
||||
|
||||
Tomahawk.InfoSystem.InfoType.InfoChart = 51;
|
||||
|
||||
Tomahawk.InfoSystem.InfoType.InfoNewReleaseCapabilities = 52;
|
||||
Tomahawk.InfoSystem.InfoType.InfoNewRelease = 53;
|
||||
|
||||
Tomahawk.InfoSystem.InfoType.InfoMiscTopHotttness = 60;
|
||||
Tomahawk.InfoSystem.InfoType.InfoMiscTopTerms = 61;
|
||||
|
||||
Tomahawk.InfoSystem.InfoType.InfoSubmitNowPlaying = 70;
|
||||
Tomahawk.InfoSystem.InfoType.InfoSubmitScrobble = 71;
|
||||
|
||||
Tomahawk.InfoSystem.InfoType.InfoNowPlaying = 80;
|
||||
Tomahawk.InfoSystem.InfoType.InfoNowPaused = 81;
|
||||
Tomahawk.InfoSystem.InfoType.InfoNowResumed = 82;
|
||||
Tomahawk.InfoSystem.InfoType.InfoNowStopped = 83;
|
||||
Tomahawk.InfoSystem.InfoType.InfoTrackUnresolved = 84;
|
||||
|
||||
Tomahawk.InfoSystem.InfoType.InfoLove = 90;
|
||||
Tomahawk.InfoSystem.InfoType.InfoUnLove = 91;
|
||||
Tomahawk.InfoSystem.InfoType.InfoShareTrack = 92;
|
||||
|
||||
Tomahawk.InfoSystem.InfoType.InfoNotifyUser = 100;
|
||||
|
||||
Tomahawk.InfoSystem.InfoType.InfoInboxReceived = 101;
|
||||
|
||||
Tomahawk.InfoSystem.InfoType.InfoLastInfo = 102; //WARNING: *ALWAYS* keep this last!
|
||||
|
||||
// PushInfoFlags
|
||||
Tomahawk.InfoSystem.PushInfoFlags = Object.create(null);
|
||||
Tomahawk.InfoSystem.PushInfoFlags.PushNoFlag = 1;
|
||||
Tomahawk.InfoSystem.PushInfoFlags.PushShortUrlFlag = 2;
|
||||
|
||||
|
||||
Tomahawk.InfoSystem._infoPluginIdCounter = 0;
|
||||
Tomahawk.InfoSystem._infoPluginHash = Object.create(null);
|
||||
|
||||
Tomahawk.InfoSystem.addInfoPlugin = function(infoPlugin) {
|
||||
var infoPluginId = Tomahawk.InfoSystem._infoPluginIdCounter++;
|
||||
Tomahawk.InfoSystem._infoPluginHash[infoPluginId] = infoPlugin;
|
||||
Tomahawk.log("Call nativeAddInfoPlugin");
|
||||
Tomahawk.InfoSystem.nativeAddInfoPlugin(infoPluginId);
|
||||
};
|
||||
|
||||
Tomahawk.InfoSystem.getInfoPlugin = function (infoPluginId) {
|
||||
return Tomahawk.InfoSystem._infoPluginHash[infoPluginId];
|
||||
};
|
||||
|
||||
Tomahawk.InfoSystem.removeInfoPlugin = function (infoPluginId) {
|
||||
Tomahawk.log('Removing info plugins from JS is not implemented yet');
|
||||
Tomahawk.assert(false);
|
||||
};
|
||||
|
||||
Tomahawk.InfoSystem.InfoPlugin = {
|
||||
infoTypeString: function(infoType) {
|
||||
for (var currentInfoTypeString in Tomahawk.InfoSystem.InfoType) {
|
||||
if (Tomahawk.InfoSystem.InfoType[currentInfoTypeString] === infoType) {
|
||||
return currentInfoTypeString;
|
||||
}
|
||||
}
|
||||
},
|
||||
// we can get around infoPluginId here probably ... but internal either way
|
||||
_notInCache: function (infoPluginId, requestId, requestType, criteria) {
|
||||
this.notInCache(requestType, criteria).then(function(result) {
|
||||
Tomahawk.log("Call nativeAddInfoRequestResult");
|
||||
Tomahawk.InfoSystem.nativeAddInfoRequestResult(infoPluginId, requestId, result.maxAge, result.data);
|
||||
}).catch(function() {
|
||||
// TODO: how to handle errors here?!
|
||||
});
|
||||
},
|
||||
notInCache: function (infoType, criteria) {
|
||||
var requestMethod = 'request' + this.infoTypeString(infoType);
|
||||
Tomahawk.log('Calling requestMethod: ' + requestMethod);
|
||||
|
||||
return Promise.resolve(this[requestMethod](criteria));
|
||||
},
|
||||
pushInfo: function (pushData) {
|
||||
var pushMethod = 'push' + this.infoTypeString(pushData.type);
|
||||
return this[pushMethod](pushData);
|
||||
},
|
||||
// we can get around infoPluginId here probably ... but internal either way
|
||||
_getInfo: function (infoPluginId, requestId, type, infoHash) {
|
||||
Tomahawk.log("currentInfoPlugin._getInfo");
|
||||
window.getInfo = arguments;
|
||||
this.getInfo(type, infoHash).then(function(result) {
|
||||
Tomahawk.log("Call nativeGetCachedInfo");
|
||||
Tomahawk.InfoSystem.nativeGetCachedInfo(infoPluginId, requestId, result.newMaxAge, result.criteria)
|
||||
}, function() {
|
||||
Tomahawk.log("Call nativeDataError");
|
||||
Tomahawk.InfoSystem.nativeDataError();
|
||||
});
|
||||
},
|
||||
getInfo: function (type, infoHash) {
|
||||
Tomahawk.log("currentInfoPlugin.getInfo");
|
||||
var getInfoMethod = 'get' + this.infoTypeString(type);
|
||||
|
||||
return Promise.resolve(this[getInfoMethod](infoHash));
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user