nuvola-player-devel team mailing list archive
-
nuvola-player-devel team
-
Mailing list archive
-
Message #00025
[Merge] lp:~mims-michael/nuvola-player/amazon-api2 into lp:nuvola-player
Michael Mims has proposed merging lp:~mims-michael/nuvola-player/amazon-api2 into lp:nuvola-player.
Requested reviews:
Jiří Janoušek (fenryxo)
For more details, see:
https://code.launchpad.net/~mims-michael/nuvola-player/amazon-api2/+merge/117292
Updated the Amazon integration script to the 2.0 API.
--
https://code.launchpad.net/~mims-michael/nuvola-player/amazon-api2/+merge/117292
Your team Nuvola Player Development is subscribed to branch lp:nuvola-player.
=== modified file 'data/nuvolaplayer/services/amazon/integration.js'
--- data/nuvolaplayer/services/amazon/integration.js 2012-07-11 07:34:31 +0000
+++ data/nuvolaplayer/services/amazon/integration.js 2012-07-30 16:27:19 +0000
@@ -1,25 +1,26 @@
/*
- Nuvola Player :: Cloud music integration
-
- This script provides integration of the Amazon cloud player streaming service
- on the JavaScript side. It's executed when Amazon page is completely
- loaded.
-
-
- Copyright 2012 Michael Mims <mims.michael@xxxxxxxxx>
-
-This program is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License version 3, as published
-by the Free Software Foundation.
-
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranties of
-MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
-PURPOSE. See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along
-with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
+ * Copyright 2011-2012 Michael Mims <mims.michael@xxxxxxxxx>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
/* Anonymous function is used not to pollute environment */
(function(Nuvola){
@@ -27,16 +28,21 @@
* Creates Amazon integration binded to Nuvola JS API
*/
var Integration = function(){
- /* Overwrite default commnad function */
- Nuvola.command = Nuvola.bind(this, this.command);
+ /* Overwrite default command function */
+ Nuvola.onMessageReceived = Nuvola.bind(this, this.messageHandler);
/* For debug output */
- this.name = "Amazon";
+ this.name = "Amazon";
/* Let's run */
this.state = Nuvola.STATE_NONE;
+ this.can_thumbs_up = false;
+ this.can_thumbs_down = false;
+ this.can_favorite = false;
+ this.can_prev = null;
+ this.can_next = null;
this.update();
- this.timeout = setInterval(Nuvola.bind(this, this.update), 500);
+// this.extraFeatures();
};
/**
@@ -51,9 +57,6 @@
var song = null;
var can_prev;
var can_next;
- var can_thumbs_up = false;
- var can_thumbs_down = false;
- var can_favorite = false;
try{
var meta = window.amznMusic.widgets.queueManager.getCurrent().metadata;
@@ -87,40 +90,49 @@
this.state = state;
// Submit data to Nuvola backend
- Nuvola.dataChanged(
- song, artist, album, album_art,
- state, can_prev, can_next,
- can_thumbs_up, can_thumbs_down, can_favorite);
+ Nuvola.updateSong(song, artist, album, album_art, state);
+
+ if(this.can_prev !== can_prev){
+ this.can_prev = can_prev;
+ Nuvola.updateAction(Nuvola.ACTION_PREV_SONG, can_prev);
+ }
+ if(this.can_next !== can_next){
+ this.can_next = can_next;
+ Nuvola.updateAction(Nuvola.ACTION_NEXT_SONG, can_next);
+ }
+
+ setTimeout(Nuvola.bind(this, this.update), 500);
}
/**
* Command handler
* @param cmd command to execute
*/
- Integration.prototype.command = function(cmd){
- var player = window.amznMusic.widgets.player;
+ Integration.prototype.messageHandler = function(cmd){
try{
+ var player = window.amznMusic.widgets.player;
+
switch(cmd){
- case Nuvola.CMD_PLAY:
+ case Nuvola.ACTION_PLAY:
if(this.state != Nuvola.STATE_PLAYING) player.playHash("play/togglePlay", "");
break;
- case Nuvola.CMD_PAUSE:
+ case Nuvola.ACTION_PAUSE:
player.pause();
break;
- case Nuvola.CMD_TOGGLE:
+ case Nuvola.ACTION_TOGGLE_PLAY:
player.playHash("play/togglePlay", "");
break;
- case Nuvola.CMD_PREV_SONG:
+ case Nuvola.ACTION_PREV_SONG:
player.playHash("play/previous", "");
break;
- case Nuvola.CMD_NEXT_SONG:
+ case Nuvola.ACTION_NEXT_SONG:
player.playHash("play/next", "");
break;
default:
// Other commands are not supported
throw {"message": "Not supported."};
}
- console.log(this.name + ": comand '" + cmd + "' executed.");
+ console.log(this.name + ": command '" + cmd + "' executed.");
}
catch(e){
// API expects exception to be a string!
@@ -131,5 +143,6 @@
/* Store reference */
Nuvola.integration = new Integration(); // Singleton
-// Call anonymous function with Nuvola object as an argument
-})(window._Nuvola);
+// Immediately call the anonymous function with Nuvola JS API main object as an argument.
+// Note that "this" is set to the Nuvola JS API main object.
+})(this);
=== modified file 'data/nuvolaplayer/services/amazon/metadata.conf'
--- data/nuvolaplayer/services/amazon/metadata.conf 2012-07-28 18:54:08 +0000
+++ data/nuvolaplayer/services/amazon/metadata.conf 2012-07-30 16:27:19 +0000
@@ -3,5 +3,6 @@
sandbox_pattern = https?://((www\.)?amazon\.com/ap/signin|(www\.)?amazon\.com/gp/dmusic/mp3/player)
maintainer_name = Michael Mims
maintainer_link = https://launchpad.net/~mims-michael
-version = 2
+version = 3
+api_major = 2
flash_plugin = no
Follow ups