← Back to team overview

nuvola-player-devel team mailing list archive

[Merge] lp:~chase-t/nuvola-player/integration-grooveshark-html5 into lp:nuvola-player

 

Chase Colman has proposed merging lp:~chase-t/nuvola-player/integration-grooveshark-html5 into lp:nuvola-player.

Requested reviews:
  Jiří Janoušek (fenryxo)
Related bugs:
  Bug #1035487 in Nuvola Player: "Orphaned service: Grooveshark"
  https://bugs.launchpad.net/nuvola-player/+bug/1035487
  Bug #1175088 in Nuvola Player: "Service Request: Grooveshark HTML5"
  https://bugs.launchpad.net/nuvola-player/+bug/1175088

For more details, see:
https://code.launchpad.net/~chase-t/nuvola-player/integration-grooveshark-html5/+merge/221628

Replaces the Grooveshark service with an HTML5-based rewrite that supports all Nuvola actions.
-- 
https://code.launchpad.net/~chase-t/nuvola-player/integration-grooveshark-html5/+merge/221628
Your team Nuvola Player Development is subscribed to branch lp:nuvola-player.
=== modified file 'data/nuvolaplayer/services/grooveshark/description.html'
--- data/nuvolaplayer/services/grooveshark/description.html	2013-08-22 20:26:33 +0000
+++ data/nuvolaplayer/services/grooveshark/description.html	2014-06-01 02:08:14 +0000
@@ -8,11 +8,3 @@
 <a href="http://en.wikipedia.org/wiki/Grooveshark";>Grooveshark on Wikipedia</a>,
 <a href="http://grooveshark.com";>Official website</a></em>
 </p>
-
-<h2>Known issues</h2>
-
-<h3>Page loads only partially with a large empty orange area</h3>
-<p>Because of a bug in WebKitGtk+ 1.8.x (Debian 7, Ubuntu 12.04),
-Grooveshark page loads only partially with a large empty orange area.
-This issue is in an external library, so it cannot be fixed in Nuvola Player itself.
-The bug seems to be fixed in WebKitGtk+ 1.10.x (Ubuntu 12.10 and 13.04).</p>

=== modified file 'data/nuvolaplayer/services/grooveshark/integration.js'
--- data/nuvolaplayer/services/grooveshark/integration.js	2013-12-22 18:57:54 +0000
+++ data/nuvolaplayer/services/grooveshark/integration.js	2014-06-01 02:08:14 +0000
@@ -1,15 +1,15 @@
 /*
- * Copyright 2011-2012 Jiří Janoušek <janousek.jiri@xxxxxxxxx>
+ * Copyright 2014 Chase Colman <chase@xxxxxxxxx>
  *
  * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met: 
- * 
+ * modification, are permitted provided that the following conditions are met:
+ *
  * 1. Redistributions of source code must retain the above copyright notice, this
- *    list of conditions and the following disclaimer. 
+ *    list of conditions and the following disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright notice,
  *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution. 
- * 
+ *    and/or other materials provided with the distribution.
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -24,153 +24,121 @@
 
 /* Anonymous function is used not to pollute environment */
 (function(Nuvola){
-	
-	if (Nuvola.checkFlash)
-		Nuvola.checkFlash();
-	
 	/**
-	 * Creates Google Music integration binded to Nuvola JS API
+	 * Creates Grooveshark HTML5 integration binded to Nuvola JS API
 	 * @param Nuvola Nuvola JS API
 	 */
 	var Integration = function(){
-		/* Overwrite default commnad function */
-		Nuvola.command = Nuvola.bind(this, this.command);
-		
-		/* For debug output */
-		this.name = "GrooveShark";
-		
-		/* Let's run */
-		this.state = Nuvola.STATE_NONE;
-		this.timeout = null;
-		
-		
-		/* Periodically try to set the callback */
-		this.timeout = setInterval(Nuvola.bind(this, this.setCallback), 100);
+		// Overwrite default commnad function
+		Nuvola.onMessageReceived = Nuvola.bind(this, this.messageHandler);
+
+		// Reset
+		Nuvola.updateSong(null, null, null, null, Nuvola.STATE_NONE);
+
+		// For debug output
+		this.name = "Grooveshark-HTML5";
+
+		// Add local links to globals
+		this.audio = GS.audio;
+		this.queue = GS.models.queue;
+		this.session = GS.models.session;
+		this.radio = GS.views.Radio.prototype;
+
+		this.audio.bind("all", Nuvola.bind(this, this.playerHandler))
 	};
-	
-	/* Set callback function for GrooveShark JS API */
-	Integration.prototype.setCallback = function(){
-		try{
-			window.Grooveshark.setSongStatusCallback(Nuvola.bind(this, this.update));
-			clearInterval(this.timeout); // done!
-			this.update();
-		}
-		catch(e){
-			// Grooveshark API is probably not finished yet
-		}
-	}
-	
+
+	// Update the song
+	Integration.prototype.updateSong = function(name) {
+		var song = this.audio.model;
+		if (!song || name === "player:stopped") {
+			Nuvola.updateSong(null, null, null, null, Nuvola.STATE_NONE);
+			return;
+		}
+
+		var state = this.audio.audio.paused ? Nuvola.STATE_PAUSED : Nuvola.STATE_PLAYING;
+
+		// The song name is either stored in Name or SongName, for some reason.
+		Nuvola.updateSong(song.get("Name") || song.get("SongName"),
+						  song.get("ArtistName"),
+						  song.get("AlbumName"),
+						  song.get("coverURL500"),
+						  state);
+	}
+
+	// Update available actions based on context
+	Integration.prototype.updateActions = function(name) {
+		var radioIsVisible = !this.radio.el.hasClass('hidden');
+		var hasAudio = !!this.audio.model;
+		Nuvola.updateAction(Nuvola.ACTION_TOGGLE_PLAY, hasAudio);
+		Nuvola.updateAction(Nuvola.ACTION_PREV_SONG, !!this.queue.getPrev());
+		Nuvola.updateAction(Nuvola.ACTION_NEXT_SONG, !!this.queue.getNext());
+		Nuvola.updateAction(Nuvola.ACTION_THUMBS_UP, radioIsVisible);
+		Nuvola.updateAction(Nuvola.ACTION_THUMBS_DOWN, radioIsVisible);
+	}
+
 	/**
-	 * Updates current playback state
+	 * Handles Grooveshark player events
+	 * @param name String namespace prefixed event name
+	 * @param event Object event object
 	 */
-	Integration.prototype.update = function(current_song){
-		if(!current_song){
-			try{
-				current_song = window.Grooveshark.getCurrentSongStatus();
-			}
-			catch(e){
-				console.log(e.message);
-			}
-		}
-		if(!current_song) return;
-		
-		var album_art = null;
-		var artist = null;
-		var song = null;
-		var state = Nuvola.STATE_NONE;
-		var album = null;
-		var can_prev;
-		var can_next;
-		var can_thumbs_up = false;
-		var can_thumbs_down = false;
-		var can_favorite = false;
-		
-		try{
-			var info = current_song.song;
-			if(info){
-				song = info.songName;
-				album = info.albumName;
-				artist = info.artistName;
-				album_art = info.artURL;
-			}
-			
-			if(current_song.status == "playing"
-			|| current_song.status == "buffering"){
-				state = Nuvola.STATE_PLAYING;
-			}
-			else if(current_song.status == "paused" || info){
-				state = Nuvola.STATE_PAUSED;
-			}
-			else{
-				state = Nuvola.STATE_NONE;
-			}
-		}
-		catch(e){
-			
-		}
-		
-		// FIXME: check it!
-		can_prev = can_next = true;		
-		
-		this.state = state;
-		Nuvola.dataChanged(
-			song, artist, album, album_art,
-			state, can_prev, can_next,
-			can_thumbs_up, can_thumbs_down, can_favorite);
+	Integration.prototype.playerHandler = function(name, event){
+		var verb = name.split(':')[1];
+
+		// Match actions without the namespaces
+		switch (verb) {
+			case 'error':
+			case 'started':
+			case 'play':
+			case 'pause':
+			case 'stopped':
+				this.updateSong(name);
+				this.updateActions(name);
+				break;
+		}
 	}
-	
+
 	/**
-	 * Command handler
+	 * Handles Nuvola user action messages
 	 * @param cmd command to execute
 	 */
-	Integration.prototype.command = function(cmd){
+	Integration.prototype.messageHandler = function(cmd){
 		try{
-			// Grooveshark provides good JavaScript API
-			// See http://developers.grooveshark.com/docs/js_api/
-			switch(cmd){
-			case Nuvola.CMD_TOGGLE:
-				if(this.state != Nuvola.STATE_PLAYING){
-					window.Grooveshark.play();
-				}
-				else{
-					window.Grooveshark.togglePlayPause();
-				}
-				break;
-			case Nuvola.CMD_PREV_SONG:
-				window.Grooveshark.previous();
-				break;
-			case Nuvola.CMD_PLAY:
-				window.Grooveshark.play();
-				break;
-			case Nuvola.CMD_PAUSE:
-				window.Grooveshark.pause();
-				break;
-			case Nuvola.CMD_NEXT_SONG:
-				window.Grooveshark.next();
-				break;
-			case Nuvola.CMD_THUMBS_UP:
-				// FIXME: Does it work? Maybe only for logged-in user?
-				window.Grooveshark.voteCurrentSong(1);
-				break;
-			case Nuvola.CMD_THUMBS_DOWN:
-				// FIXME: Does it work? Maybe only for logged-in user?
-				window.Grooveshark.voteCurrentSong(-1);
-				break;
-			case Nuvola.CMD_FAVORITE:
-				// FIXME: Does it work? Maybe only for logged-in user?
-				window.Grooveshark.favoriteCurrentSong();
-				break;
-			default:
-				// Other actions are not supported
-				throw {"message": "Not supported."};
+			switch (cmd) {
+				case Nuvola.ACTION_PLAY:
+					this.audio.play();
+					break;
+				case Nuvola.ACTION_PAUSE:
+					this.audio.audio.pause();
+					break;
+				case Nuvola.ACTION_TOGGLE_PLAY:
+					this.audio.pauseResume();
+					break;
+				case Nuvola.ACTION_PREV_SONG:
+					this.queue.prev()&&this.audio.playNow();
+					break;
+				case Nuvola.ACTION_NEXT_SONG:
+					this.audio.playNext();
+					break;
+				case Nuvola.ACTION_THUMBS_UP:
+					this.radio.smile({target: this.radio.$('.smile')});
+					break;
+				case Nuvola.ACTION_THUMBS_DOWN:
+					this.radio.frown();
+					break;
+				case Nuvola.ACTION_FAVORITE:
+					this.session.favorited()
+					break;
+				default:
+					// Other commands are not supported
+					throw {"message": "Not supported."};
 			}
 			console.log(this.name + ": comand '" + cmd + "' executed.");
-		}
-		catch(e){
-			// API expects exception to be a string
+		} catch(e){
+			// Older API expected exception to be a string
 			throw (this.name + ": " + e.message);
 		}
 	}
-	
-	Nuvola.integration = new Integration(); // Singleton ;-)
-})(window._Nuvola);
+
+	// Store reference
+	Nuvola.integration = new Integration(); // Singleton
+})(this);

=== modified file 'data/nuvolaplayer/services/grooveshark/metadata.conf'
--- data/nuvolaplayer/services/grooveshark/metadata.conf	2013-12-24 14:23:11 +0000
+++ data/nuvolaplayer/services/grooveshark/metadata.conf	2014-06-01 02:08:14 +0000
@@ -1,8 +1,9 @@
 name = Grooveshark
-home_page = http://grooveshark.com/
-sandbox_pattern = https?://grooveshark.com/
-maintainer_name = Orphaned service
-maintainer_link = https://answers.launchpad.net/nuvola-player/+faq/2012
-version = 3
-version_minor = 2
-flash_plugin = yes
+home_page = https://html5.grooveshark.com/
+sandbox_pattern = (https?://\w*\.?grooveshark\.com/|https?://\w*\.?gs-cdn\.net)
+maintainer_name = Chase Colman
+maintainer_link = https://launchpad.net/~chase-t
+version = 4
+version_minor = 3
+flash_plugin = no
+api_major = 2