Created
March 25, 2014 17:35
-
-
Save kirbysayshi/9767018 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) }); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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