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

Fix non-user playlist URI formatting #7

Merged
merged 5 commits into from
Feb 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/build
/yarn.lock
/components

package-lock.json
2 changes: 1 addition & 1 deletion formatOpenURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function formatOpenURL(parsed, base) {
return base + '/user/' + encode(parsed.user) + '/starred';
} else if ('playlist' == parsed.type) {
// user "playlist"
return base + '/user/' + encode(parsed.user) + '/playlist/' + parsed.id;
return base + (parsed.user ? '/user/' + encode(parsed.user) : '') + '/playlist/' + parsed.id;
} else if ('local' == parsed.type) {
// "local" file
return (
Expand Down
4 changes: 2 additions & 2 deletions formatURI.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ function formatURI(parsed) {
// user's "starred" playlist
return 'spotify:user:' + encode(parsed.user) + ':starred';
} else if ('playlist' == parsed.type) {
// user "playlist"
return 'spotify:user:' + encode(parsed.user) + ':playlist:' + parsed.id;
// user or non-user "playlist"
return 'spotify' + (parsed.user ? ':user:' + encode(parsed.user) : '') + ':playlist:' + parsed.id;
} else if ('local' == parsed.type) {
// "local" file
return (
Expand Down
38 changes: 34 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ describe('parse()', function() {
assert('track' == obj.type);
assert('10M2REwwztVxgr0szw7UwD' == obj.id);
});
it('should parse "playlist" URLs', function() {
it('should parse user "playlist" URLs', function() {
var url =
'http://open.spotify.com/user/tootallnate/playlist/0Lt5S4hGarhtZmtz7BNTeX';
var obj = parse(url);
assert('playlist' == obj.type);
assert('tootallnate' == obj.user);
assert('0Lt5S4hGarhtZmtz7BNTeX' == obj.id);
});
it('should parse public "playlist" URLs', function() {
var url =
'https://open.spotify.com/playlist/37i9dQZF1DXcBWIGoYBM5M';
var obj = parse(url);
assert('playlist' == obj.type);
assert('37i9dQZF1DXcBWIGoYBM5M' == obj.id);
});
it('should parse "local" URLs', function() {
var url =
'http://open.spotify.com/local/Yasunori+Mitsuda/Chrono+Trigger+OST/A+Shot+of+Crisis/161';
Expand Down Expand Up @@ -110,14 +117,21 @@ describe('parse()', function() {
assert('track' == obj.type);
assert('5CMjjywI0eZMixPeqNd75R' == obj.id);
});
it('should parse "playlist" URIs', function() {
it('should parse user "playlist" URIs', function() {
var uri =
'spotify:user:daftpunkofficial:playlist:6jP6EcvAwqNksccDkIe6hX';
var obj = parse(uri);
assert('playlist' == obj.type);
assert('daftpunkofficial' == obj.user);
assert('6jP6EcvAwqNksccDkIe6hX' == obj.id);
});
it('should parse public "playlist" URIs', function() {
var uri =
'spotify:playlist:37i9dQZF1DX4JAvHpjipBk';
var obj = parse(uri);
assert('playlist' == obj.type);
assert('37i9dQZF1DX4JAvHpjipBk' == obj.id);
});
it('should parse "local" track URIs', function() {
var uri =
'spotify:local:Yasunori+Mitsuda:Chrono+Trigger+OST:A+Shot+of+Crisis:161';
Expand Down Expand Up @@ -193,13 +207,20 @@ describe('formatURI()', function() {
var actual = formatURI(obj);
assert(actual == expected);
});
it('should parse "playlist" URIs', function() {
it('should parse user "playlist" URIs', function() {
var url = 'spotify:user:syknyk:playlist:0Idyatn0m08Y48tiOovNd9';
var obj = parse(url);
var expected = 'spotify:user:syknyk:playlist:0Idyatn0m08Y48tiOovNd9';
var actual = formatURI(obj);
assert(actual == expected);
});
it('should parse public "playlist" URIs', function() {
var url = 'spotify:playlist:37i9dQZF1DWUa8ZRTfalHk';
var obj = parse(url);
var expected = 'spotify:playlist:37i9dQZF1DWUa8ZRTfalHk';
var actual = formatURI(obj);
assert(actual == expected);
});
it('should parse "local" file URIs', function() {
var url =
'spotify:local:Flite%2c+Medium+Minus:YouTube:Find+What+You+Love:399';
Expand Down Expand Up @@ -233,7 +254,7 @@ describe('formatOpenURL()', function() {
var actual = formatOpenURL(obj);
assert(actual == expected);
});
it('should format "playlist" URIs', function() {
it('should format user "playlist" URIs', function() {
var uri =
'spotify:user:daftpunkofficial:playlist:6jP6EcvAwqNksccDkIe6hX';
var obj = parse(uri);
Expand All @@ -242,6 +263,15 @@ describe('formatOpenURL()', function() {
var actual = formatOpenURL(obj);
assert(actual == expected);
});
it('should format public "playlist" URIs', function() {
var uri =
'spotify:playlist:37i9dQZF1DXaPCIWxzZwR1';
var obj = parse(uri);
var expected =
'http://open.spotify.com/playlist/37i9dQZF1DXaPCIWxzZwR1';
var actual = formatOpenURL(obj);
assert(actual == expected);
});
it('should format "starred" playlist URIs', function() {
var uri = 'spotify:user:tootallnate:starred';
var obj = parse(uri);
Expand Down