butter_remote.js is a javascript library that provides an easy way to make an application or whatever you want to control the interface of butter through the json rpc protocol.
The plugin is developed with simplicity in mind so the methods name are the same that you can find in the butter documention and there are many other conveniences. So despite that doc has been written with the json rpc protocol in mind, the information about the usage of the methods are compatible for this library too... actually you will not even notice that you're using this library.
You can get the plugin in two ways:
- Downloading the raw file in the dist folder choosing the clean or minified version.
- Go to the releases tab and download the Source code.zip
Actually the website that you can find on the gh-pages branch hosted on butter.giacomocerquone.com is the coolest thing in here. It's just a draft to prove the potential of this library and what you can do with it. I'll do my best to improve it but I haven't so much free time so if you want to contribute I would really appreciate that!
Firstly you should obviously include the library on the page you want to use it:
<script src="butter_remote.min.js"></script>
After initialize the plugin in this way:
butter_remote.init(
//If you don't need to change these settings you can remove this whole part
{
username: "popcorn",
password: "popcorn",
ip: "127.0.0.1",
port: "8008",
debug: "false"
}
//If you don't need to change these settings you can remove this whole part
);
As you can understand from the butter time documentation, there are "three kinds" of methods.
These are {listing methods}:
butter_remote.ping();
These are {listing methods}:
butter_remote.filtergenre(["Adventure"]);
Here you have a callback function and the data can be accessed in this way:
//This get the current volume in the player
butter_remote.volume(function(data) {
console.log(data);
});
//This set the current volume in the player
butter_remote.volume([2]);
I'd like to spend two words for this particular function. butter developers put this fundamental function in their API to know when something change on the desktop application. To listen these important events you need to use "setInterval" so you can call the function at specified intervals, here the example:
setInterval(function() {
pr.listennotifications(function(data) {
//Use the data object to read the notifications
//and do wathever you need with the notifications you just took (changing commands etc.)
})
}, 1000);
Released under the GNU 3 license.
If you distribute a copy or make a fork of the project, you have to credit this project as source.
Copyright © 2015, Giacomo cerquone.
All rights reserved.