Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Refactor and API Redesign #70

Open
wants to merge 109 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
cce3a49
Add Request / Response classes
adammw Feb 14, 2014
ac7c11e
Add HermesRequest / HermesResponse classes
adammw Feb 14, 2014
42f0392
Move request / response classes to "connection" folder
adammw Feb 14, 2014
0584a37
Create Connection class to handle the WebSocket connection
adammw Feb 14, 2014
069b533
error: move to connection folder
adammw Feb 14, 2014
ed2d245
connection: add missing event handlers
adammw Feb 14, 2014
eb3e5b7
spotify: use SpotifyConnection
adammw Feb 14, 2014
08312e9
connection: fix typos
adammw Feb 14, 2014
41610c9
util: add export decorator
adammw Feb 14, 2014
417ec36
connection: use export decorator
adammw Feb 14, 2014
3bba62f
request: handle multiple callbacks
adammw Feb 14, 2014
3ede1a2
connection: separate sending request from flushing queue
adammw Feb 14, 2014
a95558b
connection: fix bugs preventing connection completing
adammw Feb 14, 2014
58cb89d
request: add missing require()
adammw Feb 14, 2014
035cb1b
Merge remote-tracking branch 'origin/ping_flash_2' into api-redesign
adammw Feb 14, 2014
fc74bea
remove unintentionally committed file
adammw Feb 14, 2014
31dfafb
request: add debugging call and fix hasCallback function
adammw Feb 14, 2014
4872677
connection: fix _startHeartbeat function
adammw Feb 14, 2014
b1153eb
connection: add debugging message for connect event
adammw Feb 14, 2014
8a2dc06
Add SpotifyUri class
adammw Feb 14, 2014
4304a67
util: use uri conversion functions from SpotifyUri
adammw Feb 14, 2014
bae1392
util: export what is exported by export()
adammw Feb 14, 2014
6b4a547
util: add caveat to export() function comment
adammw Feb 14, 2014
acc006f
util: fix bug in export()
adammw Feb 14, 2014
fe3b313
util: more export tweaks
adammw Feb 14, 2014
6807948
connection: specify $inject
adammw Feb 14, 2014
2c6785c
spotify: re-export all classes off SpotifyConnection with util.recurs…
adammw Feb 14, 2014
c43dc0d
util: add warning about the order of calls for export()
adammw Feb 14, 2014
3710b99
Move track, artist and album to metadata folder
adammw Feb 14, 2014
7fcaf0c
metadata
adammw Feb 14, 2014
9ec08a7
metadata: fixes
adammw Feb 14, 2014
597a78d
util: add missing bind() helper
adammw Feb 14, 2014
c0b44f2
spotify: export functions from SpotifyUri directly
adammw Feb 14, 2014
f09aaaa
spotify: attach metadata multi get merger as request queue handler
adammw Feb 14, 2014
3a9e715
metadata: requestQueue is now on the connection
adammw Feb 14, 2014
1b73d95
spotify: add _objectify method
adammw Feb 14, 2014
8076bbc
spotify: export uri functions on Spotify object
adammw Feb 17, 2014
95814c1
spotify: make arguments in sendCommand optional
adammw Feb 17, 2014
5ee0538
spotify: fix syntax error
adammw Feb 17, 2014
072d7cc
util: add `$provides` mechanism to export()
adammw Feb 17, 2014
5414617
spotify: declare `$provides` for SpotifyConnection
adammw Feb 17, 2014
6878b1c
request: fix response parameter in callback
adammw Feb 17, 2014
9c7261a
spotify: save all user info in user_info object
adammw Feb 17, 2014
42dfc61
track: default to 'US' if country not specified
adammw Feb 17, 2014
cf013bd
spotify: fix objectify nested loops bug
adammw Feb 17, 2014
2c31c4b
metadata: lowercase 'track' require()
adammw Feb 17, 2014
8584b25
util: add deferCallback helper
adammw Feb 17, 2014
10224bb
uri: fix typo
adammw Feb 17, 2014
fd7e3c1
metadata: convert gid to SpotifyUri objects
adammw Feb 17, 2014
b0afa78
uri: whitespace
adammw Feb 17, 2014
06d11b3
play_session: specify `$inject`
adammw Feb 17, 2014
6b729a7
spotify: rewrite #metadata to use Metadata objects
adammw Feb 17, 2014
26a0841
spotify: fix get function
adammw Feb 19, 2014
10575a1
Add User class
adammw Feb 19, 2014
4d55fdc
spotify: support callback in Spotify#get
adammw Feb 19, 2014
74e1536
spotify: add missing require()
adammw Feb 19, 2014
b0f4c12
Remove `acceptedSchemas` in favour of `_acceptsSchema()`
adammw Feb 19, 2014
40d8bab
uri: add examples to getter/setter comments
adammw Feb 19, 2014
e342919
uri: don't try to make a new object if an object was passed in
adammw Feb 19, 2014
1070a63
track: fix Track#similar()
adammw Feb 19, 2014
1fa8809
connection: update debug namespaces
adammw Feb 19, 2014
911b768
hermes_response: don't require this.request
adammw Feb 19, 2014
6b7a9c1
connection: add subscription
adammw Feb 19, 2014
1280e11
connection: fix typo
adammw Feb 20, 2014
2fc711a
spotify: make Spotify#get backwards compatible, return single objects
adammw Feb 21, 2014
46dcde0
metadata: move _acceptsSchema method onto class
adammw Feb 21, 2014
18c0d62
subscription: fix debug arguments
adammw Feb 21, 2014
49ef229
remove some logspew
adammw Feb 21, 2014
890072a
connection: make subscriptions an array
adammw Feb 22, 2014
aa23a59
metadata: remove logging
adammw Feb 22, 2014
ca983f6
Add initial prototype of Playlist classes
adammw Feb 22, 2014
08a877c
connection: fix subscription header parsing
adammw Feb 24, 2014
55ca9aa
subscription tweaks
adammw Feb 25, 2014
1f7e4c2
hermes_request: add `toString` method to make debugging easier
adammw Feb 25, 2014
c19ed0f
subscription: tweak subscribe/unsubscribe again
adammw Feb 25, 2014
3260103
subscription: add logging statements
adammw Feb 25, 2014
e84fae5
playlist: subscription/event handling
adammw Feb 25, 2014
8705061
Expose playlist changes
adammw Mar 7, 2014
358e857
playlist: bugfix
adammw Mar 7, 2014
8a77a7b
spotify: only load metadata when needed
adammw Mar 10, 2014
642026d
spotify: don't throw on unhandled commands
adammw Mar 10, 2014
62e1bae
playlist: fix bug in Playlist.create
adammw Mar 10, 2014
1b33cc5
contents: handle empty playlists
adammw Mar 10, 2014
c2cc7ec
playlist: more Playlist.create fixes
adammw Mar 10, 2014
b65c445
Added Spotify.Web.App.initialize() noop Function
JChapman202 Apr 2, 2014
b78e3d7
Add initial support for special playlists
adammw Apr 18, 2014
d44c6a4
Add more supported types to Spotify#get
adammw Apr 18, 2014
c618a70
Remove Spotify#playlist, modify Spotify#rootlist
adammw Apr 18, 2014
943ab62
Emit errors from Playlist#_performDiff
adammw Apr 18, 2014
fe2cc33
Fix custom header field parsing
adammw Apr 18, 2014
fedf382
Move rootlist method to User object
adammw Apr 18, 2014
e195147
Parse and cache playlist attributes on contents
adammw Apr 18, 2014
b9f5f39
Remove Spotify#similar
adammw Apr 18, 2014
8d6f1ae
example: add playlistEvents
adammw Apr 18, 2014
c562504
user: add missing SpotifyUri require()
adammw Apr 18, 2014
03bcc31
spotify: create User object on login
adammw Apr 18, 2014
3848063
user: fix typo in User#rootlist
adammw Apr 18, 2014
1d69693
playlist: fix scope in Playlist#contents callback
adammw Apr 18, 2014
a943558
user: use Spotify#get in User#rootlist
adammw Apr 18, 2014
8868c3c
user: implement User#starred
adammw Apr 18, 2014
23dff23
example: Update rootlist for new API
adammw Apr 18, 2014
dde084d
playlist: Make attributes optional upon creation
adammw Apr 18, 2014
84eb34b
playlist: Add method to update playlist attributes
adammw Apr 18, 2014
0a76a3b
playlist-contents: set index and revision on items
adammw Apr 18, 2014
8c1166a
playlist: set index and revision on diff items
adammw Apr 18, 2014
fa5bc9a
playlist: add Playlist#add method
adammw Apr 18, 2014
df5fc9b
playlist: add remove methods
adammw Apr 18, 2014
584a8ce
playlist: automatically add created to rootlist
adammw Apr 18, 2014
6a5e5e8
spotify: new flash key, moved sp_log and sp_user_info commands after …
Apr 26, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions example/playlistEvents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@

/**
* Example script that plays a playlist, with live updating of the internal queue
* when the contents of the playlist changes
*/

var Spotify = require('../');
var login = require('../login');
var lame = require('lame');
var Speaker = require('speaker');
var uri = process.argv[2];

var onPlaylist = function(err, playlist) {
if (err) throw err;

var playing = false;
var itemsToPlay = [];
var queueOffset = 0;

playlist.contents(function(err, contents) {
if (err) throw err;

// add existing playlist contents to queue
contents.forEach(function(playlistItem) {
itemsToPlay.push(playlistItem.item);
});

// handle playlist modifications
playlist.contents.on('add', function(change) {
change.add.items.forEach(function(playlistItem, index) {
var item = playlistItem.item;
var position = change.add.fromIndex + index;
if (position < queueOffset) {
console.log('Tracks added before current track, will not be played.');
return;
}
console.log('Track added to queue: %s at position %d', item.uri, position);
itemsToPlay.splice(position - queueOffset, 0, item);
if (!playing) next();
});
});
playlist.contents.on('rem', function(change) {
itemsToPlay.splice(change.rem.fromIndex - queueOffset, change.rem.length);
console.log('items:', change.rem.items);
console.log('Tracks removed from queue: %s', change.rem.items.map(function(i) { return i.item.uri; }).join(', '));
// TODO: handle removing current track
});
playlist.contents.on('mov', function(change) {
console.log('tracks moved', change);
var itemsToMove = itemsToPlay.splice(change.mov.fromIndex - queueOffset, change.mov.toIndex);
if (change.mov.toIndex < queueOffset) {
console.log('Tracks moved to before current track, will not be played.');
return;
}
var args = [change.mov.toIndex - queueOffset, 0].concat(itemsToMove);
itemsToPlay.splice.apply(itemsToPlay, args);
console.log('Tracks moved in queue');
// TODO: handle moving current track
});

// start playing or wait for tracks
if (itemsToPlay.length) {
console.log('Playing songs from %s.', playlist.uri);
next();
} else {
console.log('Ready... Add songs to the playlist %s to start playing.', playlist.uri);
}
});

var next = function() {
var track = itemsToPlay.shift();
if (!track) {
console.log('End of queue');
playing = false;
return;
}
queueOffset++;
if ('track' != track.type) {
console.log('Skipping non-track item:', track);
return next();
}

playing = true;

console.log('Fetching: %s', track.uri);

track.get(function(err, track) {
if (err) {
console.error(err.stack || err);
return next();
}

console.log('Playing: %s - %s', track.artist[0].name, track.name);

track.play()
.on('error', function (err) {
console.error(err.stack || err);
next();
})
.pipe(new lame.Decoder())
.pipe(new Speaker())
.on('finish', next);
});
};
};

// initiate the Spotify session
Spotify.login(login.username, login.password, function (err, spotify) {
if (err) throw err;

// Load an existing playlist if specified, otherwise create a new one
if (uri && uri.length) {
var type = Spotify.uriType(uri);
if ('playlist' != type) {
throw new Error('Must pass a "playlist" URI, got ' + JSON.stringify(type));
}
spotify.Playlist.get(uri, onPlaylist);
} else {
spotify.Playlist.create('Test Playlist ' + (new Date().toDateString()), onPlaylist);
}
});
11 changes: 8 additions & 3 deletions example/rootlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ var login = require('../login');
Spotify.login(login.username, login.password, function (err, spotify) {
if (err) throw err;

console.log('Rootlist for %s\n============', spotify.user.username);

// get the currently logged in user's rootlist (playlist names)
spotify.rootlist(function (err, rootlist) {
if (err) throw err;
var rootlist = spotify.user.rootlist();

console.log(rootlist.contents);
rootlist.contents(function(err, contents) {
if (err) throw err;
contents.forEach(function(item, i) {
console.log('%d. %s', i+1, item.item.uri);
});

spotify.disconnect();
});
Expand Down
55 changes: 0 additions & 55 deletions lib/album.js

This file was deleted.

55 changes: 0 additions & 55 deletions lib/artist.js

This file was deleted.

Loading