Merge lp:~xerosis/nuvola-player/squeezebox-integration into lp:nuvola-player/releases-1.x

Proposed by Kieran Hogg
Status: Rejected
Rejected by: Jiří Janoušek
Proposed branch: lp:~xerosis/nuvola-player/squeezebox-integration
Merge into: lp:nuvola-player/releases-1.x
Diff against target: 155 lines (+140/-0)
3 files modified
data/nuvolaplayer/services/squeezebox/description.html (+12/-0)
data/nuvolaplayer/services/squeezebox/integration.js (+122/-0)
data/nuvolaplayer/services/squeezebox/metadata.conf (+6/-0)
To merge this branch: bzr merge lp:~xerosis/nuvola-player/squeezebox-integration
Reviewer Review Type Date Requested Status
Jiří Janoušek Disapprove
Review via email: mp+109526@code.launchpad.net

This proposal supersedes a proposal from 2012-06-10.

Description of the change

Thanks for the review, javascript isn't my strongest language as you can tell...

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

Here is a review:

----8<----

6 +<p>The <strong>Squeezebox</strong> is a network music player from Logitech. It plays internet radio or digital ...

This line is too long, wrap it to 80 characters.

----8<----

40 + * @param Nuvola Nuvola JS API

This line can be removed (function does not have any arguments)

----8<----

60 + var state = Nuvola.STATE_PAUSED;

Default state should be Nuvola.STATE_NONE

----8<----

72 + var album_art = document.getElementById('ctrlCurrentArt').firstChild.firstChild.src;
73 + var artist = document.getElementById('ctrlCurrentArtist').lastChild.innerText;
74 + var song = document.getElementById('ctrlCurrentTitle').firstChild.innerText;
75 + // Squeezebox prepends the song number to the song name, remove this
76 + var song = song.split(/\.(.+)?/)[1].trim();
77 + var album = document.getElementById('ctrlCurrentAlbum').firstChild.innerText;

No need to use "var" since all variables are already declared at the beginning of the function.

----8<----

83 + var play_pause = document.getElementById('ext-gen42');
84 + var pp_pressed = play_pause.getAttribute("title");
85 + var state;
86 + if(pp_pressed == "Pause"){
87 + state = Nuvola.STATE_PLAYING;
88 + }
89 + else{
90 + state = Nuvola.STATE_PAUSED;
91 + }

If play_pause is null, line 84 raises exception. This is better:

var play_pause = document.getElementById('ext-gen42');
try{
   var pp_pressed = play_pause.getAttribute("title");
   state = (pp_pressed == "Pause") ? Nuvola.STATE_PLAYING : Nuvola.STATE_PAUSED;
}
catch(e){
// state stays Nuvola.STATE_NONE
}

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

Code is now OK, but it can't be still merged because Nuvola Player is not ready for this kind of services. Currently selecting the Squeezebox service without Squeezebox installed or running on a different address would lead to error (server not found) and user might be confused. It is necessary to create local HTML page that would the tell user that this integration requires his own instance of Squezebox and provide a form to set up the address to that instance. I've subscribed you to the bug #1011097 so you will be notified about progress of a new API. When it will be ready I will help you to finish integration of Squeezebox.

Could you please join a team https://launchpad.net/~nuvola-player-devel and push your branch to lp:~nuvola-player-devel/nuvola-player/squeezebox (shared location) to make collaboration easier?

review: Disapprove

Unmerged revisions

233. By Kieran Hogg

Fixed issues from review

232. By Kieran Hogg

Add initial Squeezebox service

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'data/nuvolaplayer/services/squeezebox'
2=== added file 'data/nuvolaplayer/services/squeezebox/description.html'
3--- data/nuvolaplayer/services/squeezebox/description.html 1970-01-01 00:00:00 +0000
4+++ data/nuvolaplayer/services/squeezebox/description.html 2012-06-10 14:36:26 +0000
5@@ -0,0 +1,12 @@
6+<p>
7+The <strong>Squeezebox</strong> is a network music player from Logitech. It
8+plays internet radio or digital audio streamed to it across a home network. It
9+also streams a variety of popular music services, such as Pandora, Slacker,
10+Napster, SomaFM, Mediafly, Live365, Rhapsody, Last.fm, Spotify and Sirius
11+among others.
12+</p>
13+<p>
14+<em>Source:
15+<a href="http://en.wikipedia.org/wiki/Squeezebox_(network_music_player)">
16+Squeezebox on Wikipedia</a></em>
17+</p>
18
19=== added file 'data/nuvolaplayer/services/squeezebox/integration.js'
20--- data/nuvolaplayer/services/squeezebox/integration.js 1970-01-01 00:00:00 +0000
21+++ data/nuvolaplayer/services/squeezebox/integration.js 2012-06-10 14:36:26 +0000
22@@ -0,0 +1,122 @@
23+/*
24+ Nuvola Player :: Cloud music integration
25+
26+ This script provides integration of the Logitech Squeezebox streaming service
27+
28+
29+ Copyright 2012 Kieran Hogg <kieran.hogg@gmail.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 Squeezebox 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 = "Squeezebox";
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+ * Updates current playback state
64+ */
65+ Integration.prototype.update = function(){
66+ // Default state
67+ var state = Nuvola.STATE_NONE;
68+ var album = null;
69+ var album_art = null;
70+ var artist = null;
71+ var song = null;
72+ var can_prev = true;
73+ var can_next = true;
74+ var can_thumbs_up = false;
75+ var can_thumbs_down = false;
76+ var can_favorite = false;
77+
78+ try{
79+ album_art = document.getElementById('ctrlCurrentArt').firstChild.firstChild.src;
80+ artist = document.getElementById('ctrlCurrentArtist').lastChild.innerText;
81+ song = document.getElementById('ctrlCurrentTitle').firstChild.innerText;
82+ // Squeezebox prepends the song number to the song name, remove this
83+ song = song.split(/\.(.+)?/)[1].trim();
84+ album = document.getElementById('ctrlCurrentAlbum').firstChild.innerText;
85+ }
86+ catch(e){
87+ console.debug("Unable to obtain song info: " + e.message);
88+ }
89+
90+ var play_pause = document.getElementById('ext-gen42');
91+ try {
92+ var pp_pressed = play_pause.getAttribute("title");
93+ state = (pp_pressed == "Pause") ? Nuvola.STATE_PLAYING : Nuvola.STATE_PAUSED;
94+ }
95+ catch (e) {
96+ //state stays Nuvola.STATE_NONE
97+
98+ this.state = state;
99+ // Submit data to Nuvola backend
100+ Nuvola.dataChanged(
101+ song, artist, album, album_art,
102+ state, can_prev, can_next,
103+ can_thumbs_up, can_thumbs_down, can_favorite);
104+ }
105+
106+ /**
107+ * Command handler
108+ * @param cmd command to execute
109+ */
110+ Integration.prototype.command = function(cmd){
111+ try{
112+ switch(cmd){
113+ case Nuvola.CMD_PLAY:
114+ if(this.state != Nuvola.STATE_PLAYING) document.getElementById('ext-gen42').click();
115+ break;
116+ case Nuvola.CMD_PAUSE:
117+ document.getElementById('ext-gen42').click();
118+ break;
119+ case Nuvola.CMD_TOGGLE:
120+ document.getElementById('ext-gen42').click();
121+ break;
122+ case Nuvola.CMD_PREV_SONG:
123+ document.getElementById('ext-gen40').click();
124+ break;
125+ case Nuvola.CMD_NEXT_SONG:
126+ document.getElementById('ext-gen44').click();
127+ break;
128+ default:
129+ // Other commands are not supported
130+ throw {"message": "Not supported."};
131+ }
132+ console.log(this.name + ": comand '" + cmd + "' executed.");
133+ }
134+ catch(e){
135+ // API expects exception to be a string!
136+ throw (this.name + ": " + e.message);
137+ }
138+ }
139+
140+ /* Store reference */
141+ Nuvola.integration = new Integration(); // Singleton
142+
143+// Call anonymous function with Nuvola object as an argument
144+})(window._Nuvola);
145
146=== added file 'data/nuvolaplayer/services/squeezebox/metadata.conf'
147--- data/nuvolaplayer/services/squeezebox/metadata.conf 1970-01-01 00:00:00 +0000
148+++ data/nuvolaplayer/services/squeezebox/metadata.conf 2012-06-10 14:36:26 +0000
149@@ -0,0 +1,6 @@
150+name = Squeezebox
151+home_page = http://localhost:9000
152+sandbox_pattern = https?://(localhost:9000)
153+maintainer_name = Kieran Hogg
154+maintainer_link = https://launchpad.net/~xerosis
155+version = 1

Subscribers

People subscribed via source and target branches