Merge lp:~rameshdharan/nuvola-player/songza into lp:nuvola-player/2.5.x

Proposed by Ramesh Dharan
Status: Rejected
Rejected by: Jiří Janoušek
Proposed branch: lp:~rameshdharan/nuvola-player/songza
Merge into: lp:nuvola-player/2.5.x
Diff against target: 220 lines (+205/-0)
3 files modified
data/nuvolaplayer/services/songza/description.html (+10/-0)
data/nuvolaplayer/services/songza/integration.js (+185/-0)
data/nuvolaplayer/services/songza/metadata.conf (+10/-0)
To merge this branch: bzr merge lp:~rameshdharan/nuvola-player/songza
Reviewer Review Type Date Requested Status
Jiří Janoušek Disapprove
Review via email: mp+230330@code.launchpad.net

Description of the change

Songza service integration

This change implements a Songza service integration.

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

Thanks for your work. There is one major issue: Songza.com redirects to daily.songza.com, probably everywhere except for US and Canada. Since daily.songza.com doesn't match the sandbox pattern, the Songza Daily website is opened in an user's default web browsers, which is very confusing. It's better to allow navigation to the Songza Daily website and to inform the user what's going on. See inline comments with proposed modifications.

Please attach a screenshot of Nuvola Player with a visible developer's bar with loaded Songza home page as it would be loaded for the first time.

https://bugs.launchpad.net/nuvola-player/+bug/1048347

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

Nuvola Player 2.x is closed for new features. Consider porting to Nuvola Player 3.

http://tiliado.github.io/nuvolaplayer/development/apps/porting.html

review: Disapprove

Unmerged revisions

846. By Ramesh Dharan

Songza service integration

This change implements a service integration for Songza.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'data/nuvolaplayer/services/songza'
2=== added file 'data/nuvolaplayer/services/songza/description.html'
3--- data/nuvolaplayer/services/songza/description.html 1970-01-01 00:00:00 +0000
4+++ data/nuvolaplayer/services/songza/description.html 2014-08-11 15:13:26 +0000
5@@ -0,0 +1,10 @@
6+<p><strong>Songza</strong> is a free music streaming and recommendation
7+service.</p>
8+<p>
9+<em>Source:
10+<a href="http://songza.com">Official website</a></em>
11+<a href="http://en.wikipedia.org/wiki/Songza">Songza on Wikipedia</a>,
12+</p>
13+<h2>Country Availability</h2>
14+<p><strong>Songza</strong> is currently only available in the United States and
15+Canada.</p>
16
17=== added file 'data/nuvolaplayer/services/songza/integration.js'
18--- data/nuvolaplayer/services/songza/integration.js 1970-01-01 00:00:00 +0000
19+++ data/nuvolaplayer/services/songza/integration.js 2014-08-11 15:13:26 +0000
20@@ -0,0 +1,185 @@
21+/*
22+ * Copyright 2014 Google Inc. All Rights Reserved.
23+ * Author: dharan@google.com (Ramesh Dharan)
24+ *
25+ * Copyright 2011-2013 Jiří Janoušek <janousek.jiri@gmail.com>
26+ *
27+ * Redistribution and use in source and binary forms, with or without
28+ * modification, are permitted provided that the following conditions are met:
29+ *
30+ * 1. Redistributions of source code must retain the above copyright notice, this
31+ * list of conditions and the following disclaimer.
32+ * 2. Redistributions in binary form must reproduce the above copyright notice,
33+ * this list of conditions and the following disclaimer in the documentation
34+ * and/or other materials provided with the distribution.
35+ *
36+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
37+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
38+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
40+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
41+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
45+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46+ */
47+
48+/* Anonymous function is used not to pollute environment */
49+(function(Nuvola)
50+{
51+ /**
52+ * Creates integration binded to Nuvola JS API
53+ */
54+ var Integration = function()
55+ {
56+ /* For debug output */
57+ this.name = "Songza";
58+
59+ /* Overwrite default command function */
60+ Nuvola.onMessageReceived = Nuvola.bind(this, this.messageHandler);
61+
62+ require(["songza/app", ], Nuvola.bind(this, function(App) {
63+ App.postInit(Nuvola.bind(this, function() {
64+ this.songza = App.getInstance();
65+ }));
66+ }));
67+
68+ /* Let's run */
69+ this.state = Nuvola.STATE_NONE;
70+ this.can_prev = null;
71+ this.can_next = null;
72+ this.can_thumbs_up = null;
73+ this.can_thumbs_down = null;
74+
75+ this.update();
76+ };
77+
78+ /**
79+ * Updates current playback state
80+ */
81+ Integration.prototype.update = function()
82+ {
83+ // Default values
84+ var state = Nuvola.STATE_NONE;
85+ var can_prev = false;
86+ var can_next = false;
87+ var can_thumbs_up = false;
88+ var can_thumbs_down = false;
89+
90+ var song = null;
91+ var artist = null;
92+ var album = null;
93+ var art = null;
94+
95+ try {
96+ var player = this.songza.getPlayer();
97+ var manager = player.getManager();
98+ var songContext = player.songContext(player.findSongOrCurrent());
99+
100+ state = player.isPlaying() ? Nuvola.STATE_PLAYING :
101+ player.isPaused() ? Nuvola.STATE_PAUSED : state;
102+
103+ can_next = manager.canSkip();
104+
105+ song = songContext.song.title;
106+ artist = songContext.song.artist;
107+ album = songContext.album;
108+ art = songContext.song.image_url;
109+
110+ can_thumbs_up = true;
111+ can_thumbs_down = true;
112+
113+ } catch(e) {
114+ console.debug(this.name + ": could not update song state");
115+ }
116+
117+ // Save state
118+ this.state = state;
119+
120+ // Submit data to Nuvola backend
121+ Nuvola.updateSong(song, artist, album, art, state);
122+
123+ if (this.can_next !== can_next) {
124+ this.can_next = can_next;
125+ Nuvola.updateAction(Nuvola.ACTION_NEXT_SONG, can_next);
126+ }
127+
128+ if (this.can_thumbs_up !== can_thumbs_up) {
129+ this.can_thumbs_up = can_thumbs_up;
130+ Nuvola.updateAction(Nuvola.ACTION_THUMBS_UP, can_thumbs_up);
131+ }
132+
133+ if (this.can_thumbs_down !== can_thumbs_down) {
134+ this.can_thumbs_down = can_thumbs_down;
135+ Nuvola.updateAction(Nuvola.ACTION_THUMBS_DOWN, can_thumbs_down);
136+ }
137+
138+ // Schedule update
139+ setTimeout(Nuvola.bind(this, this.update), 500);
140+ };
141+
142+ /**
143+ * Message handler
144+ * @param cmd command to execute
145+ */
146+ Integration.prototype.messageHandler = function(cmd)
147+ {
148+ /* Respond to user actions */
149+ try
150+ {
151+ var player = this.songza.getPlayer();
152+ var song = player.findSongOrCurrent();
153+ var stream = song.get("streamSong");
154+
155+ switch (cmd)
156+ {
157+ case Nuvola.ACTION_PLAY:
158+ player.play();
159+ break;
160+ case Nuvola.ACTION_PAUSE:
161+ player.pause();
162+ break;
163+ case Nuvola.ACTION_TOGGLE_PLAY:
164+ player.play_or_pause();
165+ break;
166+ case Nuvola.ACTION_NEXT_SONG:
167+ player.skip();
168+ break;
169+
170+ /*
171+ * XXX player.voteUp() method relies on a jQuery selector that doesn't
172+ * seem to work in this context so we can't use it. This code mimics
173+ * what the player method actually does, but it feels fragile since
174+ * the upstream implementation could change.
175+ */
176+ case Nuvola.ACTION_THUMBS_UP:
177+ song.set({vote : "up"});
178+ stream.voteUp();
179+ player.songTrigger("vote-up");
180+ break;
181+ case Nuvola.ACTION_THUMBS_DOWN:
182+ song.set({vote : "down"});
183+ stream.voteDown();
184+ player.songTrigger("vote-down");
185+ break;
186+
187+ default:
188+ // Other commands are not supported
189+ throw {"message": "Not supported."};
190+ }
191+ console.log(this.name + ": comand '" + cmd + "' executed.");
192+ }
193+ catch (e)
194+ {
195+ // Older API expected exception to be a string.
196+ throw (this.name + ": " + e.message);
197+ }
198+ };
199+
200+ /* Store reference */
201+ Nuvola.integration = new Integration(); // Singleton
202+
203+ // Immediately call the anonymous function with Nuvola JS API main object as an argument.
204+ // Note that "this" is set to the Nuvola JS API main object.
205+})(this);
206
207=== added file 'data/nuvolaplayer/services/songza/metadata.conf'
208--- data/nuvolaplayer/services/songza/metadata.conf 1970-01-01 00:00:00 +0000
209+++ data/nuvolaplayer/services/songza/metadata.conf 2014-08-11 15:13:26 +0000
210@@ -0,0 +1,10 @@
211+name = Songza
212+home_page = https://songza.com/
213+sandbox_pattern = https?://songza.com/
214+maintainer_name = Ramesh Dharan
215+maintainer_link = https://launchpad.net/~rameshdharan
216+version = 1
217+version_minor = 0
218+flash_plugin = no
219+requirements_specified = yes
220+api_major = 2

Subscribers

People subscribed via source and target branches