Merge lp:~mims-michael/nuvola-player/amazon into lp:nuvola-player/2.5.x

Proposed by Michael Mims
Status: Superseded
Proposed branch: lp:~mims-michael/nuvola-player/amazon
Merge into: lp:nuvola-player/2.5.x
Diff against target: 179 lines (+151/-2)
4 files modified
data/nuvolaplayer/services/amazon/description.html (+9/-0)
data/nuvolaplayer/services/amazon/integration.js (+135/-0)
data/nuvolaplayer/services/amazon/metadata.conf (+6/-0)
src/core/storage.vala (+1/-2)
To merge this branch: bzr merge lp:~mims-michael/nuvola-player/amazon
Reviewer Review Type Date Requested Status
Jiří Janoušek Needs Fixing
Review via email: mp+103551@code.launchpad.net

This proposal has been superseded by a proposal from 2012-04-26.

Description of the change

I don't know if there is a need/want for this, but I use Amazon Cloud Player frequently so I've created a service integration module for it. You certainly don't have to use it, but I thought I would share it with you. I've been using it for a little over a day and it seems to be working fine.

To post a comment you must log in.
Revision history for this message
Jiří Janoušek (fenryxo) wrote :

Thanks for your work, it's certainly valuable contribution to the project. Code looks good (1 minor improvement and 1 cosmetic stuff).

--------8<-----------

66 + var state = Nuvola.STATE_NONE;
90 + var state = Nuvola.STATE_NONE;

The second assignment is unnecessary.

--------8<-----------

78 + var __meta
91 + var __widgets
121 + var __player

Is there any reason to use "__" prefix? (You can leave it as is if it's your personal preference.)

--------8<-----------

175 - var i = uri.last_index_of_char('/');
176 - var id = uri.substring(i+1);
177 + var id = Checksum.compute_for_string(ChecksumType.MD5, uri);

I will revert this change, because it will be merged as a separate patch.

review: Needs Fixing
351. By Michael Mims

Removed duplicate state declarations. Removed '__' variable prefixes.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'data/nuvolaplayer/services/amazon'
2=== added file 'data/nuvolaplayer/services/amazon/description.html'
3--- data/nuvolaplayer/services/amazon/description.html 1970-01-01 00:00:00 +0000
4+++ data/nuvolaplayer/services/amazon/description.html 2012-04-26 14:45:23 +0000
5@@ -0,0 +1,9 @@
6+<p><strong>Amazon Cloud Player</strong> is integrated with the MP3 store and allows
7+users to store their music on Amazon Cloud Drive, and play that music from any
8+supported web browsers. Currently, Amazon Cloud Player is available on the website
9+and within the Amazon MP3 Android application.
10+</p><p>
11+<em>Source:
12+<a href="http://http://en.wikipedia.org/wiki/Amazon_MP3">Amazon MP3 on Wikipedia</a>,
13+<a href="http://www.amazon.com">Official website</a></em>
14+</p>
15
16=== added file 'data/nuvolaplayer/services/amazon/integration.js'
17--- data/nuvolaplayer/services/amazon/integration.js 1970-01-01 00:00:00 +0000
18+++ data/nuvolaplayer/services/amazon/integration.js 2012-04-26 14:45:23 +0000
19@@ -0,0 +1,135 @@
20+/*
21+ Nuvola Player :: Cloud music integration
22+
23+ This script provides integration of the Amazon cloud player streaming service
24+ on the JavaScript side. It's executed when Amazon page is completely
25+ loaded.
26+
27+
28+ Copyright 2012 Michael Mims <mims.michael@gmail.com>
29+
30+This program is free software: you can redistribute it and/or modify it
31+under the terms of the GNU General Public License version 3, as published
32+by the Free Software Foundation.
33+
34+This program is distributed in the hope that it will be useful, but
35+WITHOUT ANY WARRANTY; without even the implied warranties of
36+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
37+PURPOSE. See the GNU General Public License for more details.
38+
39+You should have received a copy of the GNU General Public License along
40+with this program. If not, see <http://www.gnu.org/licenses/>.
41+*/
42+
43+/* Anonymous function is used not to pollute environment */
44+(function(Nuvola){
45+ /**
46+ * Creates Amazon integration binded to Nuvola JS API
47+ */
48+ var Integration = function(){
49+ /* Overwrite default commnad function */
50+ Nuvola.command = Nuvola.bind(this, this.command);
51+
52+ /* For debug output */
53+ this.name = "Amazon";
54+
55+ /* Let's run */
56+ this.state = Nuvola.STATE_NONE;
57+ this.update();
58+ this.timeout = setInterval(Nuvola.bind(this, this.update), 500);
59+ };
60+
61+ /**
62+ * Updates current playback state
63+ */
64+ Integration.prototype.update = function(){
65+ // Default state
66+ var state = Nuvola.STATE_NONE;
67+ var album = null;
68+ var album_art = null;
69+ var artist = null;
70+ var song = null;
71+ var can_prev;
72+ var can_next;
73+ var can_thumbs_up = false;
74+ var can_thumbs_down = false;
75+ var can_favorite = false;
76+
77+ try{
78+ var meta = window.amznMusic.widgets.queueManager.getCurrent().metadata;
79+
80+ album = meta.albumName;
81+ album_art = meta.albumCoverImageSmall;
82+ artist = meta.albumArtistName;
83+ song = meta.title;
84+ }
85+ catch(e){
86+ //~ console.debug("Unable to obtain song info: " + e.message);
87+ }
88+
89+ try{
90+ var widgets = window.amznMusic.widgets;
91+ state = widgets.player.isPlaying() ? Nuvola.STATE_PLAYING : Nuvola.STATE_PAUSED;
92+
93+ if(state != Nuvola.STATE_NONE){
94+ can_prev = widgets.queueManager.hasPrevious();
95+ can_next = widgets.queueManager.hasNext();
96+ }
97+ else{
98+ can_prev = can_next = false;
99+ }
100+
101+ }
102+ catch(e){
103+ can_prev = can_next = false;
104+ }
105+
106+ this.state = state;
107+
108+ // Submit data to Nuvola backend
109+ Nuvola.dataChanged(
110+ song, artist, album, album_art,
111+ state, can_prev, can_next,
112+ can_thumbs_up, can_thumbs_down, can_favorite);
113+ }
114+
115+ /**
116+ * Command handler
117+ * @param cmd command to execute
118+ */
119+ Integration.prototype.command = function(cmd){
120+ var player = window.amznMusic.widgets.player;
121+ try{
122+ switch(cmd){
123+ case Nuvola.CMD_PLAY:
124+ if(this.state != Nuvola.STATE_PLAYING) player.playHash("play/togglePlay", "");
125+ break;
126+ case Nuvola.CMD_PAUSE:
127+ player.pause();
128+ break;
129+ case Nuvola.CMD_TOGGLE:
130+ player.playHash("play/togglePlay", "");
131+ break;
132+ case Nuvola.CMD_PREV_SONG:
133+ player.playHash("play/previous", "");
134+ break;
135+ case Nuvola.CMD_NEXT_SONG:
136+ player.playHash("play/next", "");
137+ break;
138+ default:
139+ // Other commands are not supported
140+ throw {"message": "Not supported."};
141+ }
142+ console.log(this.name + ": comand '" + cmd + "' executed.");
143+ }
144+ catch(e){
145+ // API expects exception to be a string!
146+ throw (this.name + ": " + e.message);
147+ }
148+ }
149+
150+ /* Store reference */
151+ Nuvola.integration = new Integration(); // Singleton
152+
153+// Call anonymous function with Nuvola object as an argument
154+})(window._Nuvola);
155
156=== added file 'data/nuvolaplayer/services/amazon/metadata.conf'
157--- data/nuvolaplayer/services/amazon/metadata.conf 1970-01-01 00:00:00 +0000
158+++ data/nuvolaplayer/services/amazon/metadata.conf 2012-04-26 14:45:23 +0000
159@@ -0,0 +1,6 @@
160+name = Amazon
161+home_page = http://www.amazon.com/gp/dmusic/mp3/player
162+sandbox_pattern = https?://((www\.)?amazon\.com/ap/signin|(www\.)?amazon\.com/gp/dmusic/mp3/player)
163+maintainer_name = Michael Mims
164+maintainer_link = https://launchpad.net/~mims-michael
165+version = 1
166
167=== modified file 'src/core/storage.vala'
168--- src/core/storage.vala 2012-03-21 22:29:37 +0000
169+++ src/core/storage.vala 2012-04-26 14:45:23 +0000
170@@ -43,8 +43,7 @@
171 public string? get_album_art(string? uri){
172 if(uri == null) return null;
173 /* Album art is stored locally to be passed to libnotify and Sound menu */
174- var i = uri.last_index_of_char('/');
175- var id = uri.substring(i+1);
176+ var id = Checksum.compute_for_string(ChecksumType.MD5, uri);
177 var f = this.get_default_cache_file(ALBUM_ART_DIRNAME + "/" + id + ".jpg");
178 if(f.query_exists(null)){
179 return f.get_path();

Subscribers

People subscribed via source and target branches