Skip to content

Instantly share code, notes, and snippets.

@jacobk
Created April 10, 2012 12:31
Show Gist options
  • Save jacobk/2351058 to your computer and use it in GitHub Desktop.
Save jacobk/2351058 to your computer and use it in GitHub Desktop.
# Metadata lookup for youtube links
#
# <youtube link> - returns info about the link
#
module.exports = (robot) ->
robot.hear youtube.link, (msg) ->
msg.http(youtube.uri msg.match[1]).get() (err, res, body) ->
if res.statusCode is 200
data = JSON.parse(body)
msg.send "Youtube: #{data.entry.title["$t"]}"
youtube =
link: /(?:youtu\.be\/|youtube.com\/(?:watch\?.*\bv=|embed\/|v\/)|ytimg\.com\/vi\/)(.+?)(?:[^-a-zA-Z0-9]|$)/
uri: (vid) -> "https://gdata.youtube.com/feeds/api/videos/#{vid}?v=2&alt=json"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment