I created this class for a project I am working on where I need to validate Spotify playlist and track URLs. I hope someone will get some use out of it or maybe improve it. It provides two static methods for validating and allows you to specify the return type which currently is a HTTP or Spotify URL format.
Here is an example of how to use the method which will convert the link variable below to “spotify:user:user_name:playlist:3WbWswJtOPIdKBQmZs9pGr”:
var link : String = "http://open.spotify.com/user/user_name/playlist/3WbWswJtOPIdKBQmZs9pGr";
var validUrl : String = SpotifyUtil.validatePlaylist( link, SpotifyUtil.URL_FORMAT_SPOTIFY );
if( validUrl )
{
trace( link );
}
2 Comments
How does this work within your project? I must admit I’m pretty useless when it comes down to this type of thing but am curious as to how it would be used.
We created an app using the libSpotify APIs where users could dynamically add songs to playlists in a competition setting. It came in handy for validation (like email but for Spotify URLs) before we sent them off to the server for submission. Hope that helps!