tomahawk-player/tomahawk — pull request #276 by dschmidt (2014-11-10 18:35:48+00:00)
Title: Add JavaScript InfoPlugins

Hey.

I'm submitting an almost ready implementation of javascript bindings for info plugins.

If you want your ```FoobarResolver``` resolver to provide info system functionality, you can simply add a ```FoobarInfoPlugin``` to the InfoSystem by calling ``Tomahawk.InfoSystem.addInfoPlugin(FoobarInfoPlugin);`` from the resolver's init method (or wherever you want really). Its implementation would look something like this:

``` javascript
var FoobarInfoPlugin = Tomahawk.extend(Tomahawk.InfoSystem.InfoPlugin, {
supportedGetTypes: [
Tomahawk.InfoSystem.InfoType.InfoArtistReleases
],
getInfoArtistReleases: function(infoHash) {
Tomahawk.log("currentInfoPlugin.getInfoArtistReleases");
return {
newMaxAge: 2419200000,
criteria: {
artist: infoHash.artist
}
};
},
requestInfoArtistReleases: function (criteria) {
Tomahawk.log("currentInfoPlugin.requestInfoArtistReleases");
return {
maxAge: 0,
data: {
albums: ['NO REAL ALBUM', 'Y U NO ALBUM']
}
};
},

supportedPushTypes: [
Tomahawk.InfoSystem.InfoType.InfoNowPlaying
],
pushInfoNowPlaying: function(pushData) {
// $.ajax({
// url: 'https://someserver/scrobble',
// data: {
// artist: pushData.input.artist,
// title: pushData.input.title
// }
// });
}
});
```

You can either return data synchronously or a promise. Your return value is automatically wrapped in a promise if you return synchronously. No chance for zalgo!

There's certainly room for improvement: for example the InfoSystem bindings could/should only be added to the javascript frame on demand if specified in the metadata.json.

I haven't done any Tomahawk development in a while, be nitpicky about coding style and everything.

Best regards,
Domme