This repository has been archived by the owner. It is now read-only.
Permalink
Cannot retrieve contributors at this time
# 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}" |