Created
October 1, 2013 18:52
-
-
Save baileylo/6783242 to your computer and use it in GitHub Desktop.
Code to create spotify openable links.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// starts with spotify:track | |
// used defined input | |
input = 'spotify:track:6MdqqkQ8sSC0WB4i8PyRuQ'; | |
var parts = input.match(/spotify\:track\:(.+)/) | |
if (parts.length !== 2) { | |
return input; | |
} | |
var song_id = parts[1], | |
url = 'http://logansbailey.com/ogp/?q=http://open.spotify.com/track/' + song_id, | |
request = new XMLHttpRequest(); | |
request.open('get', url, true); | |
request.onload = function() { | |
var response = httpRequest.response; | |
if (!response || !JSON.parse(httpRequest.response)) { | |
response = {description: 'Unknown track on spotify'}; | |
} else { | |
response = JSON.parse(httpRequest.response); | |
} | |
return '<a target="_blank" href="spotify://track:' + song_id + '">' response.description'</a>'; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment