Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
41 lines (34 sloc) 1.012 kb
# Description:
# Metadata lookup for spotify links
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# <spotify link> - returns info about the link (track, artist, etc.)
#
# Author:
# jacobk
module.exports = (robot) ->
robot.hear spotify.link, (msg) ->
msg.http(spotify.uri msg.match[0]).get() (err, res, body) ->
if res.statusCode is 200
data = JSON.parse(body)
msg.send spotify[data.info.type](data)
spotify =
link: /// (
?: (http|https)://(open|play).spotify.com/(track|album|artist)/
| spotify:(track|album|artist):
) \S+ ///
uri: (link) -> "http://ws.spotify.com/lookup/1/.json?uri=#{link}"
track: (data) ->
track = "#{data.track.artists[0].name} - #{data.track.name}"
album = "(#{data.track.album.name}) (#{data.track.album.released})"
"Track: #{track} #{album}"
album: (data) ->
"Album: #{data.album.artist} - #{data.album.name} (#{data.album.released})"
artist: (data) ->
"Artist: #{data.artist.name}"
Jump to Line
Something went wrong with that request. Please try again.