Skip to content

Instantly share code, notes, and snippets.

@rafapolo
Created December 3, 2010 01:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafapolo/726417 to your computer and use it in GitHub Desktop.
Save rafapolo/726417 to your computer and use it in GitHub Desktop.
Pega o título do vídeo no youtube ou no vimeo a partir da URL.
def get_video_name(url)
begin
if url.index("vimeo")
id = url.match(/(\d+)/)[0]
link = "http://vimeo.com/api/v2/video/#{id}.json"
result = JSON.parse(open(link).read)
name = result[0]["title"]
else
# youtube
id = url.match(/=([\w]+)/)[1]
link = "http://gdata.youtube.com/feeds/api/videos/#{id}?alt=json"
result = JSON.parse(open(link).read)
name = result["entry"]["title"]["$t"]
end
rescue
nil
end
name
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment