← Back to team overview

nuvola-player-devel team mailing list archive

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

 

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

Requested reviews:
  Jiří Janoušek (fenryxo)
Related bugs:
  Bug #1079648 in Nuvola Player: "Service request: Spotify"
  https://bugs.launchpad.net/nuvola-player/+bug/1079648

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

Adds a Spotify service integration to Nuvola Player.
-- 
https://code.launchpad.net/~chase-t/nuvola-player/integration-spotify/+merge/222084
Your team Nuvola Player Development is subscribed to branch lp:nuvola-player.
=== added directory 'data/nuvolaplayer/services/spotify'
=== added file 'data/nuvolaplayer/services/spotify/description.html'
--- data/nuvolaplayer/services/spotify/description.html	1970-01-01 00:00:00 +0000
+++ data/nuvolaplayer/services/spotify/description.html	2014-06-04 17:58:12 +0000
@@ -0,0 +1,29 @@
+<p><strong>Spotify</strong> is a commercial music streaming service providing
+digital rights management-restricted content from record labels including
+Sony, EMI, Warner Music Group and Universal. Music can be browsed or
+searched by artist, album, genre, playlist, or record label. Paid "Premium"
+subscriptions remove advertisements and allow users to download music to listen
+offline.</p>
+<p><em>Source:
+<a href="http://en.wikipedia.org/wiki/Spotify";>Spotify on Wikipedia</a>,
+<a href="http://spotify.com";>Official website</a></em>
+</p>
+
+<h2>Country Availability</h2>
+<p><b>Spotify</b> is currently available in the following countries:
+Spotify is available in Andorra, Argentina, Australia, Austria, Belgium,
+Bulgaria, Colombia, Cyprus, Denmark, Estonia, Finland, France, Germany, Greece,
+Hong Kong, Iceland, Ireland, Italy, Latvia, Liechtenstein, Lithuania,
+Luxembourg, Malaysia, Malta, Mexico, Monaco, Netherlands, New Zealand, Norway,
+the Philippines, Poland, Portugal, Spain, Singapore, Sweden, Switzerland,
+Taiwan, Turkey, the United Kingdom, the United States and Uruguay.</p><p>You can find
+up-to-date country availability details at the
+<a href="https://www.spotify.com/us/select-your-country/";>Spotify's Select your
+ country page</a>.</p>
+
+<h2>Playback Requirements</h2>
+
+<p><b>Spotify</b> service requires a <b>Flash plugin</b> to play music.</p>
+<ul>
+<li><a href="https://answers.launchpad.net/nuvola-player/+faq/2107";>How to install compatible Flash plugin</a></li>
+</ul>

=== added file 'data/nuvolaplayer/services/spotify/integration.js'
--- data/nuvolaplayer/services/spotify/integration.js	1970-01-01 00:00:00 +0000
+++ data/nuvolaplayer/services/spotify/integration.js	2014-06-04 17:58:12 +0000
@@ -0,0 +1,157 @@
+/*
+ * 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:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ *    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.
+ *
+ * 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
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* Anonymous function is used not to pollute environment */
+(function(Nuvola){
+	var Integration = function(){
+		// Overwrite default commnad function
+		Nuvola.onMessageReceived = Nuvola.bind(this, this.messageHandler);
+
+		this.reset();
+
+		// For debug output
+		this.name = "Spotify";
+
+		var init = Nuvola.bind(this,this.init);
+
+		this.tryInit = setInterval(init, 500);
+	};
+
+	Integration.prototype.init = function() {
+		if (!window.Spotify.Shuttle._initContext) return;
+
+		clearInterval(this.tryInit);
+
+		// Add local links to globals
+		this.context = window.Spotify.Shuttle._initContext;
+		this.player = this.context.contextPlayer;
+		this.appManager = this.context.applicationManager;
+
+		var boundUpdate = Nuvola.bind(this,this.updateSongAndActions);
+
+		this.player.addListeners({
+			trackLoaded: boundUpdate,
+			play: boundUpdate,
+			pause: boundUpdate,
+			stop: boundUpdate,
+			stopped: boundUpdate,
+			clear: boundUpdate
+		});
+
+		this.updateSongAndActions();
+	};
+
+	Integration.prototype.getApp = function(id) {
+		var idFilter = function(el) { return el._id === id; };
+		var result = this.appManager._apps._values.filter(idFilter);
+		return result[0] || null;
+	};
+
+	// Reset song state
+	Integration.prototype.reset = function() {
+		Nuvola.updateSong(null, null, null, null, Nuvola.STATE_NONE);
+	};
+
+	// Update the song and actions
+	Integration.prototype.updateSongAndActions = function() {
+		this.updateSong();
+		this.updateActions();
+	};
+
+	// Update the song
+	Integration.prototype.updateSong = function() {
+		this.player.getPlayerState().then(function (result) {
+			var song = result.trackState.track;
+			if (!song) this.reset();
+
+			var state = result.playbackState.playing ? Nuvola.STATE_PLAYING : Nuvola.STATE_PAUSED;
+			Nuvola.updateSong(song.name,
+							song.artistName,
+							song.albumName,
+							song.image,
+							state);
+		});
+	};
+
+	// Update available actions based on context
+	Integration.prototype.updateActions = function(name) {
+		var usingRadio = this.player._loadedContextList._owner.indexOf("spotify:app:radio") === 0;
+
+		Nuvola.updateAction(Nuvola.ACTION_TOGGLE_PLAY, !!this.player._currentTrack);
+		Nuvola.updateAction(Nuvola.ACTION_FAVORITE, !!this.player._currentTrack&&!this.player._currentTrack.starred);
+		Nuvola.updateAction(Nuvola.ACTION_THUMBS_UP, usingRadio);
+		Nuvola.updateAction(Nuvola.ACTION_THUMBS_DOWN, usingRadio);
+
+		if (!this.player._loadedContextList) return;
+
+		this.player._loadedContextList.hasNext().then(function (result) {
+			Nuvola.updateAction(Nuvola.ACTION_NEXT_SONG, result);
+		});
+		this.player._loadedContextList.hasPrevious().then(function (result) {
+			Nuvola.updateAction(Nuvola.ACTION_PREV_SONG, result);
+		});
+	};
+
+	Integration.prototype.messageHandler = function(cmd){
+		try{
+			switch (cmd) {
+				case Nuvola.ACTION_PLAY:
+					this.player.resume();
+				break;
+				case Nuvola.ACTION_PAUSE:
+					this.player.pause();
+				break;
+				case Nuvola.ACTION_TOGGLE_PLAY:
+					this.player.togglePlay();
+				break;
+				case Nuvola.ACTION_PREV_SONG:
+					this.player.previous("backbtn");
+				break;
+				case Nuvola.ACTION_NEXT_SONG:
+					this.player.next("fwdbtn");
+				break;
+				case Nuvola.ACTION_THUMBS_UP:
+					this.getApp('radio')._frame.contentWindow.$("thumbsup").click();
+				break;
+				case Nuvola.ACTION_THUMBS_DOWN:
+					this.getApp('radio')._frame.contentWindow.$("thumbsdown").click();
+				break;
+				case Nuvola.ACTION_FAVORITE:
+					// All actions and hooks should eventually use the API
+					SpotifyApi.api.request('library_star',['spotify:user:@',Spotify.Shuttle._initContext.contextPlayer._currentTrack.uri]);
+				break;
+				default:
+					// Other commands are not supported
+					throw {"message": "Not supported."};
+			}
+			console.log(this.name + ": comand '" + cmd + "' executed.");
+		} catch(e){
+			// Older API expected exception to be a string
+			throw (this.name + ": " + e.message);
+		}
+	};
+
+	// Store reference
+	Nuvola.integration = new Integration(); // Singleton
+})(this);

=== added file 'data/nuvolaplayer/services/spotify/metadata.conf'
--- data/nuvolaplayer/services/spotify/metadata.conf	1970-01-01 00:00:00 +0000
+++ data/nuvolaplayer/services/spotify/metadata.conf	2014-06-04 17:58:12 +0000
@@ -0,0 +1,10 @@
+name = Spotify
+home_page = https://play.spotify.com
+sandbox_pattern = (https?://o\.scdn\.co|https?://\w*\.?\w*\.?spotify\.com|https?://play\.spotify\.edgekey\.net|https?://\w*\.?spapps\.co|https?://s-static\.ak\.fbcdn\.net|https?:fbcdn-profile-.\.akamaihd\.net|https?://www\.facebook\.com|https?://glue-static\.\w\.amazonaws\.com|https?:\w\.cloudfront.net|https?://api.tunigo.com)
+maintainer_name = Chase Colman
+maintainer_link = https://launchpad.net/~chase-t
+version = 1
+version_minor = 0
+api_major = 2
+flash_plugin = yes
+requirements_specified = yes


Follow ups