Merge lp:~stefan-lohmaier/nuvola-player/rdio into lp:nuvola-player/2.5.x

Proposed by StefanL
Status: Superseded
Proposed branch: lp:~stefan-lohmaier/nuvola-player/rdio
Merge into: lp:nuvola-player/2.5.x
Diff against target: 238 lines (+223/-0)
3 files modified
data/nuvolaplayer/services/rdio/description.html (+10/-0)
data/nuvolaplayer/services/rdio/integration.js (+207/-0)
data/nuvolaplayer/services/rdio/metadata.conf (+6/-0)
To merge this branch: bzr merge lp:~stefan-lohmaier/nuvola-player/rdio
Reviewer Review Type Date Requested Status
Jiří Janoušek Needs Fixing
Review via email: mp+98050@code.launchpad.net

This proposal has been superseded by a proposal from 2012-03-28.

Description of the change

I just added a new service. I've using it for the past week without any issues. It supports the old and the new design.

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

Thanks for your contribution to Nuvola Player project.

Code looks good, a few minor improvements:

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

6 +<p><strong>Rdio</strong> is an ad-free music subscription service available ..

The line is too long, split it to multiple lines with maximal width 80 characters.

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

25 + Copyright 2011 Stefan Lohmaier <email address hidden>

It's 2012.

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

44 + * @param Nuvola Nuvola JS API

You can remove this line, because the param no longer exists. I should clean up my scripts :-)

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

62 + * 0 : old ui
63 + * 1 : new ui

replace with

* @returns 0 for the old ui and 1 for the new ui

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

83 + var state = Nuvola.STATE_NONE;
...
133 + default: state = Nuvola.STATE_NONE; break;

The second assignment is unnecessary.

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

126 + player_model.playState;//old

You may have forgotten an assignment to rdiostate (not sure):

rdiostate = player_model.playState;//old

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

Your work will be shipped with Nuvola Player 1.1. As a maintainer, you will be responsible for fixing all bugs reported against this service integration. The bugs will be assigned to your Launchpad account.

I can also create package for release 1.0.x, if you are willing to support it.

review: Needs Fixing
Revision history for this message
Jiří Janoušek (fenryxo) wrote :

FYI I'm about to release version 1.0.4 soon (at the weekend), so you should perform suggested modifications, if you would like to have your work merged to that release.

345. By StefanL

fixed notes from review

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/rdio'
2=== added file 'data/nuvolaplayer/services/rdio/description.html'
3--- data/nuvolaplayer/services/rdio/description.html 1970-01-01 00:00:00 +0000
4+++ data/nuvolaplayer/services/rdio/description.html 2012-03-28 22:17:18 +0000
5@@ -0,0 +1,10 @@
6+<p><strong>Rdio</strong> is an ad-free music subscription service available in
7+the United States, Canada, Germany, Brazil, Australia, Spain, Portugal and New
8+Zealand. It is available as a website and also has clients for the iPhone,
9+iPod Touch & iPad, Android, BlackBerry and Windows Phone mobile devices, which
10+can play streaming music or cache songs for offline playback.
11+</p><p>
12+<em>Source:
13+<a href="http://en.wikipedia.org/wiki/Rdio">Rdio on Wikipedia</a>,
14+<a href="http://www.rdio.com">Official website</a></em>
15+</p>
16
17=== added file 'data/nuvolaplayer/services/rdio/integration.js'
18--- data/nuvolaplayer/services/rdio/integration.js 1970-01-01 00:00:00 +0000
19+++ data/nuvolaplayer/services/rdio/integration.js 2012-03-28 22:17:18 +0000
20@@ -0,0 +1,207 @@
21+/*
22+ Nuvola Player :: Cloud music integration
23+
24+ This script provides integration of the Rdio streaming service
25+ on the JavaScript side. It's executed when Rdio page is completely
26+ loaded.
27+
28+
29+ Copyright 2012 Stefan Lohmaier <stefan.lohmaier@googlemail.com>
30+
31+This program is free software: you can redistribute it and/or modify it
32+under the terms of the GNU General Public License version 3, as published
33+by the Free Software Foundation.
34+
35+This program is distributed in the hope that it will be useful, but
36+WITHOUT ANY WARRANTY; without even the implied warranties of
37+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
38+PURPOSE. See the GNU General Public License for more details.
39+
40+You should have received a copy of the GNU General Public License along
41+with this program. If not, see <http://www.gnu.org/licenses/>.
42+*/
43+
44+/* Anonymous function is used not to pollute environment */
45+(function(Nuvola){
46+ /**
47+ * Creates Rdio integration binded to Nuvola JS API
48+ */
49+ var Integration = function(){
50+ /* Overwrite default commnad function */
51+ Nuvola.command = Nuvola.bind(this, this.command);
52+
53+ /* For debug output */
54+ this.name = "Rdio";
55+
56+ /* Let's run */
57+ this.state = Nuvola.STATE_NONE;
58+ this.update();
59+ this.timeout = setInterval(Nuvola.bind(this, this.update), 500);
60+ };
61+
62+
63+ /**
64+ * Determine, which version of the ui is currently being used.
65+ * @returns 0 for the old ui and 1 for the new ui
66+ */
67+ Integration.prototype.getUiVersion = function(){
68+ var uiVersion;
69+ try {
70+ if (playbackControls == undefined) {
71+ uiVersion = 0;
72+ }
73+ }
74+ catch (e) {
75+ uiVersion = 1;
76+ }
77+ return uiVersion;
78+ }
79+
80+ /**
81+ * Updates current playback state
82+ */
83+ Integration.prototype.update = function(){
84+ // Default state
85+ var state = Nuvola.STATE_NONE;
86+ var album = null;
87+ var album_art = null;
88+ var artist = null;
89+ var song = null;
90+ var can_prev;
91+ var can_next;
92+ var can_thumbs_up = false;
93+ var can_thumbs_down = false;
94+ var can_favorite = false;
95+ var uiVersion = this.getUiVersion();
96+
97+ try{
98+ var album_art;
99+ var album;
100+ var artist;
101+ var song;
102+
103+ if(uiVersion == 1){
104+ album_art = document.getElementsByClassName("album_link")[0].getElementsByClassName("image")[0].src;
105+ album = null;
106+ artist = document.getElementsByClassName("artist truncated_line")[0].innerText;
107+ song = document.getElementsByClassName("name truncated_line")[0].innerText;
108+ }
109+ else {
110+ album_art = document.getElementById('playerNowPlayingImage').src;
111+ album = document.getElementById('playerNowPlayingAlbum').firstChild.innerText;
112+ artist = document.getElementById('playerNowPlayingArtist').firstChild.innerText;
113+ song = document.getElementById('playerNowPlayingTitle').firstChild.innerText;
114+ }
115+ }
116+ catch(e){
117+ //~ console.debug("Unable to obtain song info: " + e.message);
118+ }
119+
120+ try{
121+ var state = Nuvola.STATE_NONE;
122+
123+ var rdiostate;
124+ if(uiVersion == 1){
125+ rdiostate = R.Services.Player.model.attributes.playState;//new
126+ }
127+ else {
128+ rdiostate = player_model.playState;//old
129+ }
130+
131+
132+ switch (rdiostate){
133+ case 0: state = Nuvola.STATE_PAUSED; break;
134+ case 1: state = Nuvola.STATE_PLAYING; break;
135+ }
136+
137+ if(state != Nuvola.STATE_NONE){
138+ can_prev = can_next = true;
139+ }
140+ else{
141+ can_prev = can_next = false;
142+ }
143+
144+ }
145+ catch(e){
146+ can_prev = can_next = false;
147+ }
148+
149+ this.state = state;
150+
151+ // Submit data to Nuvola backend
152+ Nuvola.dataChanged(
153+ song, artist, album, album_art,
154+ state, can_prev, can_next,
155+ can_thumbs_up, can_thumbs_down, can_favorite);
156+ }
157+
158+ /**
159+ * Command handler
160+ * @param cmd command to execute
161+ */
162+ Integration.prototype.command = function(cmd){
163+ uiVersion = this.getUiVersion();
164+
165+ try{
166+ switch(cmd){
167+ case Nuvola.CMD_PLAY:
168+ if(this.state != Nuvola.STATE_PLAYING){
169+ if(uiVersion == 1){
170+ document.getElementsByClassName("play_pause")[0].click();
171+ }
172+ else{
173+ playbackControls.playPause();
174+ }
175+ }
176+ break;
177+ case Nuvola.CMD_PAUSE:
178+ if(this.state == Nuvola.STATE_PLAYING){
179+ if(uiVersion == 1){
180+ document.getElementsByClassName("play_pause")[0].click();
181+ }
182+ else{
183+ playbackControls.playPause();
184+ }
185+ }
186+ break;
187+ case Nuvola.CMD_TOGGLE:
188+ if(uiVersion == 1){
189+ document.getElementsByClassName("play_pause")[0].click();
190+ }
191+ else{
192+ playbackControls.playPause();
193+ }
194+ break;
195+ case Nuvola.CMD_PREV_SONG:
196+ if(uiVersion == 1){
197+ document.getElementsByClassName("prev")[0].click();
198+ }
199+ else{
200+ getPlayer()._previous();
201+ }
202+ break;
203+ case Nuvola.CMD_NEXT_SONG:
204+ if(uiVersion == 1){
205+ document.getElementsByClassName("next")[0].click();
206+ }
207+ else{
208+ getPlayer()._next();
209+ }
210+ break;
211+ default:
212+ // Other commands are not supported
213+ throw {"message": "Not supported."};
214+ }
215+ console.log(this.name + ": comand '" + cmd + "' executed.");
216+ }
217+ catch(e){
218+ // API expects exception to be a string!
219+ throw (this.name + ": " + e.message);
220+ }
221+ }
222+
223+ /* Store reference */
224+ Nuvola.integration = new Integration(); // Singleton
225+
226+// Call anonymous function with Nuvola object as an argument
227+})(window._Nuvola);
228
229=== added file 'data/nuvolaplayer/services/rdio/metadata.conf'
230--- data/nuvolaplayer/services/rdio/metadata.conf 1970-01-01 00:00:00 +0000
231+++ data/nuvolaplayer/services/rdio/metadata.conf 2012-03-28 22:17:18 +0000
232@@ -0,0 +1,6 @@
233+name = Rdio
234+home_page = http://www.rdio.com/
235+sandbox_pattern = https?://((www\.)?rdio\.com/|ak.rdio\.com|)
236+maintainer_name = Stefan Lohmaier
237+maintainer_link = https://launchpad.net/~stefan-lohmaier
238+version = 1

Subscribers

People subscribed via source and target branches