Skip to content

Commit

Permalink
Ignore URLs with localization (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hatzilu authored Dec 23, 2023
1 parent 6800077 commit ff1e8bb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export default function parse (input: string | SpotifyUri): ParsedSpotifyUri {
}

function parseParts (uri: string, parts: string[]): ParsedSpotifyUri {
parts = parts.filter(p => !p.startsWith('intl'))

let spotifyType = parts[1]
if (spotifyType === SpotifyTypes.Embed) {
parts = parts.slice(1)
Expand Down
37 changes: 37 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,36 @@ describe('parse()', function () {
assert.strictEqual('track', obj.type)
assert.strictEqual('10M2REwwztVxgr0szw7UwD', obj.id)
})
it('should parse "track" URLs with localization', function () {
const url = 'https://open.spotify.com/intl-il/track/4uhnhRlZ1Jq5zN7VOxqHeW'
const obj = parse(url)
assert.strictEqual('track', obj.type)
assert.strictEqual('4uhnhRlZ1Jq5zN7VOxqHeW', obj.id)
})
it('should parse "episode" URLs', function () {
const url = 'http://open.spotify.com/episode/64TORH3xleuD1wcnFsrH1E'
const obj = parse(url)
assert.strictEqual('episode', obj.type)
assert.strictEqual('64TORH3xleuD1wcnFsrH1E', obj.id)
})
it('should parse "episode" URLs with localization', function () {
const url = 'http://open.spotify.com/intl-il/episode/64TORH3xleuD1wcnFsrH1E'
const obj = parse(url)
assert.strictEqual('episode', obj.type)
assert.strictEqual('64TORH3xleuD1wcnFsrH1E', obj.id)
})
it('should parse "show" URLs', function () {
const url = 'https://open.spotify.com/show/6uxKcBftLv1aOWoNL7UzTl'
const obj = parse(url)
assert.strictEqual('show', obj.type)
assert.strictEqual('6uxKcBftLv1aOWoNL7UzTl', obj.id)
})
it('should parse "show" URLs with localization', function () {
const url = 'https://open.spotify.com/intl-il/show/6uxKcBftLv1aOWoNL7UzTl'
const obj = parse(url)
assert.strictEqual('show', obj.type)
assert.strictEqual('6uxKcBftLv1aOWoNL7UzTl', obj.id)
})
it('should parse user "playlist" URLs', function () {
const url =
'http://open.spotify.com/user/tootallnate/playlist/0Lt5S4hGarhtZmtz7BNTeX'
Expand Down Expand Up @@ -87,6 +105,12 @@ describe('parse()', function () {
assert.strictEqual('track', obj.type)
assert.strictEqual('5W3cjX2J3tjhG8zb6u0qHn', obj.id)
})
it('should parse "track" URLs with localization', function () {
const url = 'https://play.spotify.com/intl-fr/track/4uhnhRlZ1Jq5zN7VOxqHeW'
const obj = parse(url)
assert.strictEqual('track', obj.type)
assert.strictEqual('4uhnhRlZ1Jq5zN7VOxqHeW', obj.id)
})
})

describe('"embed.spotify.com" URLs', function () {
Expand All @@ -113,13 +137,26 @@ describe('parse()', function () {
assert.strictEqual('track', obj.type)
assert.strictEqual('5oscsdDQ0NpjsTgpG4bI8S', obj.id)
})
it('should parse "track" URLs with localization', function () {
const url = 'https://open.spotify.com/embed/intl-il/track/5oscsdDQ0NpjsTgpG4bI8S'
const obj = parse(url)
assert.strictEqual('track', obj.type)
assert.strictEqual('5oscsdDQ0NpjsTgpG4bI8S', obj.id)
})
it('should parse "playlist" URLs', function () {
const url =
'https://open.spotify.com/embed/playlist/7arbVhvtYYaLYJefoRBSvU'
const obj = parse(url)
assert.strictEqual('playlist', obj.type)
assert.strictEqual('7arbVhvtYYaLYJefoRBSvU', obj.id)
})
it('should parse "playlist" URLs with localization', function () {
const url =
'https://open.spotify.com/intl-il/embed/playlist/7arbVhvtYYaLYJefoRBSvU'
const obj = parse(url)
assert.strictEqual('playlist', obj.type)
assert.strictEqual('7arbVhvtYYaLYJefoRBSvU', obj.id)
})
})

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

0 comments on commit ff1e8bb

Please sign in to comment.