Merge lp:~chase-t/nuvola-player/integration-grooveshark-mobile into lp:nuvola-player/2.5.x

Proposed by Chase Colman
Status: Merged
Approved by: Jiří Janoušek
Approved revision: 834
Merged at revision: 834
Proposed branch: lp:~chase-t/nuvola-player/integration-grooveshark-mobile
Merge into: lp:nuvola-player/2.5.x
Diff against target: 200 lines (+185/-0)
3 files modified
data/nuvolaplayer/services/groovesharkmobile/description.html (+23/-0)
data/nuvolaplayer/services/groovesharkmobile/integration.js (+152/-0)
data/nuvolaplayer/services/groovesharkmobile/metadata.conf (+10/-0)
To merge this branch: bzr merge lp:~chase-t/nuvola-player/integration-grooveshark-mobile
Reviewer Review Type Date Requested Status
Jiří Janoušek Approve
Review via email: mp+221972@code.launchpad.net

Description of the change

Adds the Grooveshark Mobile HTML5 interface for Grooveshark to the available Nuvola Player services. This does not affect the original Grooveshark service.

To post a comment you must log in.
834. By Chase Colman

Grooveshark Mobile: Fix song update for broadcasts

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

Brilliant :-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'data/nuvolaplayer/services/groovesharkmobile'
2=== added file 'data/nuvolaplayer/services/groovesharkmobile/description.html'
3--- data/nuvolaplayer/services/groovesharkmobile/description.html 1970-01-01 00:00:00 +0000
4+++ data/nuvolaplayer/services/groovesharkmobile/description.html 2014-06-04 00:18:44 +0000
5@@ -0,0 +1,23 @@
6+<p><strong>Grooveshark</strong> is an international online music search engine,
7+music streaming service and music recommendation web software application, allowing users
8+to search for, stream, and upload music that can be played immediately or added
9+to a playlist. An optional paid subscription adds additional functionality and removes
10+advertisements.
11+</p>
12+<p><em>This is the HTML5-based mobile version of <strong>Grooveshark</strong> which does not require Flash.</em></p>
13+<p><em>Source:
14+<a href="http://en.wikipedia.org/wiki/Grooveshark">Grooveshark on Wikipedia</a>,
15+<a href="http://grooveshark.com">Official website</a></em>
16+</p>
17+
18+<h2>Country Availability</h2>
19+
20+<p><b>Grooveshark</b> is currently unavailable in Germany due to the excessive cost of operation.</p>
21+<p><em>Source: <a href="http://help.grooveshark.com/customer/portal/articles/322794-inability-to-access-grooveshark-from-germany">Grooveshark Help - Inability to access Grooveshark from Germany</a></em></p>
22+
23+<h2>Playback Requirements</h2>
24+
25+<p><b>Grooveshark Mobile</b> requires <b>HTML5 audio</b> technology to play music.</p>
26+<ul>
27+<li><a href="https://answers.launchpad.net/nuvola-player/+faq/2277">How to install HTML5 Audio support</a></li>
28+</ul>
29
30=== added file 'data/nuvolaplayer/services/groovesharkmobile/integration.js'
31--- data/nuvolaplayer/services/groovesharkmobile/integration.js 1970-01-01 00:00:00 +0000
32+++ data/nuvolaplayer/services/groovesharkmobile/integration.js 2014-06-04 00:18:44 +0000
33@@ -0,0 +1,152 @@
34+/*
35+ * Copyright 2014 Chase Colman <chase@colman.io>
36+ *
37+ * Redistribution and use in source and binary forms, with or without
38+ * modification, are permitted provided that the following conditions are met:
39+ *
40+ * 1. Redistributions of source code must retain the above copyright notice, this
41+ * list of conditions and the following disclaimer.
42+ * 2. Redistributions in binary form must reproduce the above copyright notice,
43+ * this list of conditions and the following disclaimer in the documentation
44+ * and/or other materials provided with the distribution.
45+ *
46+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
47+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
48+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
49+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
50+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
51+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
52+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
55+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56+ */
57+
58+/* Anonymous function is used not to pollute environment */
59+(function(Nuvola){
60+ /**
61+ * Creates Grooveshark HTML5 integration binded to Nuvola JS API
62+ * @param Nuvola Nuvola JS API
63+ */
64+ var Integration = function(){
65+ // Overwrite default commnad function
66+ Nuvola.onMessageReceived = Nuvola.bind(this, this.messageHandler);
67+
68+ // Reset
69+ Nuvola.updateSong(null, null, null, null, Nuvola.STATE_NONE);
70+
71+ // For debug output
72+ this.name = "Grooveshark-HTML5";
73+
74+ // Add local links to globals
75+ this.audio = GS.audio;
76+ this.queue = GS.models.queue;
77+ this.session = GS.models.session;
78+ this.radio = GS.views.Radio.prototype;
79+
80+ this.audio.bind("all", Nuvola.bind(this, this.playerHandler))
81+ };
82+
83+ // Update the song
84+ Integration.prototype.updateSong = function(name) {
85+ var song = this.audio.model;
86+ if (!song || name === "player:stopped") {
87+ Nuvola.updateSong(null, null, null, null, Nuvola.STATE_NONE);
88+ return;
89+ }
90+
91+ // Broadcasts have a different model for songs
92+ if (this.audio.isSubscribedToBroadcast()) {
93+ song = song.get("activeSong");
94+ }
95+
96+ var state = this.audio.audio.paused ? Nuvola.STATE_PAUSED : Nuvola.STATE_PLAYING;
97+
98+ // The song name is either stored in Name or SongName, for some reason.
99+ Nuvola.updateSong(song.get("Name") || song.get("SongName"),
100+ song.get("ArtistName"),
101+ song.get("AlbumName"),
102+ song.get("coverURL500"),
103+ state);
104+ }
105+
106+ // Update available actions based on context
107+ Integration.prototype.updateActions = function(name) {
108+ var radioIsVisible = !this.radio.el.hasClass('hidden');
109+ var hasAudio = !!this.audio.model;
110+ var hasFavorites = !!this.session.favorites;
111+ Nuvola.updateAction(Nuvola.ACTION_TOGGLE_PLAY, hasAudio);
112+ Nuvola.updateAction(Nuvola.ACTION_PREV_SONG, !!this.queue.getPrev());
113+ Nuvola.updateAction(Nuvola.ACTION_NEXT_SONG, !!this.queue.getNext());
114+ Nuvola.updateAction(Nuvola.ACTION_THUMBS_UP, radioIsVisible);
115+ Nuvola.updateAction(Nuvola.ACTION_THUMBS_DOWN, radioIsVisible);
116+ Nuvola.updateAction(Nuvola.ACTION_FAVORITE, hasAudio&&hasFavorites);
117+ }
118+
119+ /**
120+ * Handles Grooveshark player events
121+ * @param name String namespace prefixed event name
122+ * @param event Object event object
123+ */
124+ Integration.prototype.playerHandler = function(name, event){
125+ var verb = name.split(':')[1];
126+
127+ // Match actions without the namespaces
128+ switch (verb) {
129+ case 'error':
130+ case 'started':
131+ case 'play':
132+ case 'set-model':
133+ case 'pause':
134+ case 'stopped':
135+ this.updateSong(name);
136+ this.updateActions(name);
137+ break;
138+ }
139+ }
140+
141+ /**
142+ * Handles Nuvola user action messages
143+ * @param cmd command to execute
144+ */
145+ Integration.prototype.messageHandler = function(cmd){
146+ try{
147+ switch (cmd) {
148+ case Nuvola.ACTION_PLAY:
149+ this.audio.play();
150+ break;
151+ case Nuvola.ACTION_PAUSE:
152+ this.audio.audio.pause();
153+ break;
154+ case Nuvola.ACTION_TOGGLE_PLAY:
155+ this.audio.pauseResume();
156+ break;
157+ case Nuvola.ACTION_PREV_SONG:
158+ this.queue.prev()&&this.audio.playNow();
159+ break;
160+ case Nuvola.ACTION_NEXT_SONG:
161+ this.audio.playNext();
162+ break;
163+ case Nuvola.ACTION_THUMBS_UP:
164+ this.radio.smile({target: this.radio.$('.smile')});
165+ break;
166+ case Nuvola.ACTION_THUMBS_DOWN:
167+ this.radio.frown();
168+ break;
169+ case Nuvola.ACTION_FAVORITE:
170+ this.session.favorite(this.audio.model, [null,null]);
171+ break;
172+ default:
173+ // Other commands are not supported
174+ throw {"message": "Not supported."};
175+ }
176+ console.log(this.name + ": comand '" + cmd + "' executed.");
177+ } catch(e){
178+ // Older API expected exception to be a string
179+ throw (this.name + ": " + e.message);
180+ }
181+ }
182+
183+ // Store reference
184+ Nuvola.integration = new Integration(); // Singleton
185+})(this);
186
187=== added file 'data/nuvolaplayer/services/groovesharkmobile/metadata.conf'
188--- data/nuvolaplayer/services/groovesharkmobile/metadata.conf 1970-01-01 00:00:00 +0000
189+++ data/nuvolaplayer/services/groovesharkmobile/metadata.conf 2014-06-04 00:18:44 +0000
190@@ -0,0 +1,10 @@
191+name = Grooveshark Mobile
192+home_page = https://html5.grooveshark.com/
193+sandbox_pattern = (https?://\w*\.?grooveshark\.com/|https?://\w*\.?gs-cdn\.net)
194+maintainer_name = Chase Colman
195+maintainer_link = https://launchpad.net/~chase-t
196+version = 1
197+version_minor = 0
198+api_major = 2
199+flash_plugin = no
200+requirements_specified = yes

Subscribers

People subscribed via source and target branches