From cbaa66e1522dd12848691e0a721dfae4a45d775c Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Sun, 28 Mar 2021 15:28:01 +0000 Subject: [PATCH] Add show URLs support --- src/parse.ts | 4 ++++ test/test.js | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/parse.ts b/src/parse.ts index 239722e..8d6b8ea 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -7,6 +7,7 @@ import Artist from './artist'; import Album from './album'; import Track from './track'; import Episode from './episode'; +import Show from './show'; import User from './user'; import SpotifyUri from './spotify-uri'; import { decode } from './util'; @@ -86,5 +87,8 @@ function parseParts(uri: string, parts: string[]): ParsedSpotifyUri { if (parts[1] === 'episode') { return new Episode(uri, parts[2]); } + if (parts[1] === 'show') { + return new Show(uri, parts[2]); + } throw new TypeError(`Could not determine type for: ${uri}`); } diff --git a/test/test.js b/test/test.js index a7db3b7..a0e627c 100644 --- a/test/test.js +++ b/test/test.js @@ -19,6 +19,12 @@ describe('parse()', function() { assert.equal('episode', obj.type); assert.equal('64TORH3xleuD1wcnFsrH1E', obj.id); }); + it('should parse "show" URLs', function () { + let url = 'https://open.spotify.com/show/6uxKcBftLv1aOWoNL7UzTl' + let obj = parse(url) + assert.equal('show', obj.type) + assert.equal('6uxKcBftLv1aOWoNL7UzTl', obj.id) + }); it('should parse user "playlist" URLs', function() { let url = 'http://open.spotify.com/user/tootallnate/playlist/0Lt5S4hGarhtZmtz7BNTeX'; @@ -124,6 +130,12 @@ describe('parse()', function() { assert.equal('episode', obj.type); assert.equal('64TORH3xleuD1wcnFsrH1E', obj.id); }); + it('should parse "show" URIs', function () { + let uri = 'spotify:show:6uxKcBftLv1aOWoNL7UzTl' + let obj = parse(uri) + assert.equal('show', obj.type) + assert.equal('6uxKcBftLv1aOWoNL7UzTl', obj.id) + }); it('should parse user "playlist" URIs', function() { let uri = 'spotify:user:daftpunkofficial:playlist:6jP6EcvAwqNksccDkIe6hX'; @@ -267,6 +279,13 @@ describe('formatOpenURL()', function() { let actual = formatOpenURL(obj); assert.equal(actual, expected); }); + it('should format "show" URIs', function () { + let uri = 'spotify:show:6uxKcBftLv1aOWoNL7UzTl' + let obj = parse(uri) + let expected = 'http://open.spotify.com/show/6uxKcBftLv1aOWoNL7UzTl' + let actual = formatOpenURL(obj) + assert.equal(actual, expected) + }); it('should format user "playlist" URIs', function() { let uri = 'spotify:user:daftpunkofficial:playlist:6jP6EcvAwqNksccDkIe6hX';