Skip to content

Commit

Permalink
fix: parse embed playlist urls
Browse files Browse the repository at this point in the history
closes #17
  • Loading branch information
Kikobeats committed Apr 7, 2022
1 parent a6a324d commit ae97f32
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,8 @@ function parseParts(uri: string, parts: string[]): ParsedSpotifyUri {
if (parts[1] === 'show') {
return new Show(uri, parts[2]);
}
if (parts[1] === 'playlist') {
return new Playlist(uri, parts[2]);
}
throw new TypeError(`Could not determine type for: ${uri}`);
}
13 changes: 13 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ describe('parse()', function () {
assert.equal('track', obj.type)
assert.equal('5oscsdDQ0NpjsTgpG4bI8S', obj.id)
})
it('should parse "playlist" URLs', function () {
let url =
'https://embed.spotify.com/?uri=spotify:playlist:7arbVhvtYYaLYJefoRBSvU'
let obj = parse(url)
assert.equal('playlist', obj.type)
assert.equal('7arbVhvtYYaLYJefoRBSvU', obj.id)
})
})

describe('"open.spotify.com/embed" URLs (e.g. twitter embed)', function () {
Expand All @@ -104,6 +111,12 @@ describe('parse()', function () {
assert.equal('track', obj.type)
assert.equal('5oscsdDQ0NpjsTgpG4bI8S', obj.id)
})
it('should parse "playlist" URLs', function () {
let url = 'https://open.spotify.com/embed/playlist/7arbVhvtYYaLYJefoRBSvU'
let obj = parse(url)
assert.equal('playlist', obj.type)
assert.equal('7arbVhvtYYaLYJefoRBSvU', obj.id)
})
})

describe('Spotify URIs', function () {
Expand Down

0 comments on commit ae97f32

Please sign in to comment.