Skip to content

Instantly share code, notes, and snippets.

@kirbysayshi
Created March 25, 2014 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirbysayshi/9767018 to your computer and use it in GitHub Desktop.
Save kirbysayshi/9767018 to your computer and use it in GitHub Desktop.
var NodeCore = require('node-corejs').NodeCore;
var Spotify = require('node-corejs').Spotify;
var EventEmitter = require('spotify-eventemitter');
var username = process.env.SP_USERNAME;
var password = process.env.SP_PASSWORD;
//console.log(window);
//console.log(window.constructor.prototype.navigator)
// NodeCore unfortunately defines a global window, but leaves out postMessage
window.postMessage = function(message, targetOrigin, transfer) {
var ev = this.document.createEvent('MessageEvent');
ev.initEvent('message', false, true);
ev.data = message
ev.targetOrigin = targetOrigin;
//ev.data = message;
this.dispatchEvent(ev);
console.log('postmsg', ev._eventType, ev._type, ev.data);
}
window.addEventListener('message', function(ev) {
console.log('msgrecv', ev.type, ev.data);
})
global.XMLHttpRequest = window.XMLHttpRequest;
var core = new NodeCore(username, password, 'https://play.spotify.com');
global.Spotify = Spotify;
core.connect(function(err) {
var p = new EventEmitter();
p.subscribe = p.on;
p.unsubscribe = p.off;
p.notify = console.log.bind(console, 'notify');
var shuttle = require('shuttle');
Spotify.Shuttle.init(core._core, {
publisher: p
})
window.SpotifyApi.api.request('user_metadata', ['spotify:user:kirbysayshi'], null,
function(error, payload) { console.log('success', arguments) },
function(error, payload) { console.log('fail', arguments) });
})
{
"name": "collection-to-rel-playlists",
"version": "0.0.0",
"description": "find all tracks in a users collection, get related playlists, and then rank owners of playlists",
"main": "index.js",
"dependencies": {
"async": "~0.2.10",
"node-corejs": "git+ssh://git@ghe.spotify.net:darius/node-corejs.git",
"spotify-liburi": "~1.2.0",
"spotify-bridge": "git+ssh://git.spotify.net:link/bridge.git",
"shuttle": "git+ssh://git.spotify.net:link/shuttle.git",
"spotify-eventemitter": "~2.0.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Drew Petersen <drewp@spotify.com>",
"license": "SpotifyAB"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment