spotify-uri
Parse the various Spotify URI formats into Objects and back
Spotify URIs get passed around in a variety of flavors. This module parses them
into a JavaScript object so you can work with the further. You can also convert
them back into Spotify URIs or HTTP URLs.
Installation
Install for node.js using npm
:
$ npm install spotify-uri
Install for component(1) using component
:
$ component install TooTallNate/spotify-uri
Example
var spotifyUri = require('spotify-uri');
var parsed, uri;
parsed = spotifyUri.parse('spotify:track:3GU4cxkfdc3lIp9pFEMMmw');
console.log(parsed);
parsed = spotifyUri.parse('http://open.spotify.com/track/1pKYYY0dkg23sQQXi0Q5zN');
console.log(parsed);
uri = spotifyUri.formatURI(parsed);
console.log(uri);
uri = spotifyUri.formatOpenURL(parsed);
console.log(uri);
uri = spotifyUri.formatPlayURL(parsed);
console.log(uri);
uri = spotifyUri.formatEmbedURL(parsed);
console.log(uri);
See the test cases for some more examples of Spotify URIs.
API
.parse(String uri) → Object
Parses a Spotify URI or a Spotify HTTP(s) URL into an Object. The specific
properties set on the returned Object depend on the "type" of uri
that gets
passed in. The different "types" are listed below:
.formatURI(Object parsedUri) → String
Formats a parsed URI Object back into a Spotify URI. For example:
var parsed = spotifyUri.parse('https://play.spotify.com/track/3GU4cxkfdc3lIp9pFEMMmw');
var uri = spotifyUri.formatURI(parsed);
console.log(uri);
.formatOpenURL(Object parsedUri) → String
Formats a parsed URI Object back into a Spotify HTTP "open" URL. For example:
var parsed = spotifyUri.parse('spotify:track:3c1zC1Ma3987kQcHQfcG0Q');
var uri = spotifyUri.formatOpenURL(parsed);
console.log(uri);
.formatPlayURL(Object parsedUri) → String
Formats a parsed URI Object back into a Spotify HTTPS "play" URL. For example:
var parsed = spotifyUri.parse('spotify:track:4Jgp57InfWE4MxJLfheNVz');
var uri = spotifyUri.formatPlayURL(parsed);
console.log(uri);
.formatEmbedURL(Object parsedUri) → String
Formats a parsed URI Object back into a Spotify HTTPS "embed" URL. For example:
var parsed = spotifyUri.parse('spotify:track:6JmI8SpUHoQ4yveHLjTrko');
var uri = spotifyUri.formatEmbedURL(parsed);
console.log(uri);
License
MIT