-
Notifications
You must be signed in to change notification settings - Fork 6
/
spotify-link.js
30 lines (26 loc) · 904 Bytes
/
spotify-link.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const uriPrefixLength = 'https://'.length
// The URIs defined in this list are used on the web and should not be
// intercepted and opened in the desktop client
const spotifyUriStubsToLeaveAlone = [
'/embed/', // To embed a playlist or track on the web
'/embed?', // Legacy embed format
'/log/' // Used for analytics
]
// These are domains to register intercepts for
export const domains = [
'open.spotify.com',
'play.spotify.com'
]
export function createDesktop (webUri) {
const domainEnds = webUri.indexOf('/', uriPrefixLength) + 1
const uriPart = webUri.slice(domainEnds).replace(/\//g, ':')
return `spotify:${uriPart}`
}
// If the URI contains any of the stubs specified in spotifyUriStubsToLeaveAlone
// These are URLs
export function leaveAlone (webUri) {
for (const stub of spotifyUriStubsToLeaveAlone) {
if (webUri.indexOf(stub) !== -1) return true
}
return false
}