Created
December 3, 2010 01:07
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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