使用Ruby,我如何获取YouTube视频的数据?例如,我有一个像这样的视频的api url :(例如https://gdata.youtube.com/feeds/api/videos/6Dakd7EIgBE?v=2
)。如何使用Ruby将我的rails应用程序中的视图,投票,缩略图等元素提取出来?
答案 0 :(得分:5)
Ruby gem从vedio获取信息。看看这个链接。 https://github.com/thibaudgg/video_info
gem install video_info
video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4")
# video.available? => true
# video.video_id => "mZqGqE0D0n4"
# video.provider => "YouTube"
# video.title => "Cherry Bloom - King Of The Knife"
# video.description => "The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net"
# video.duration => 175 (in seconds)
# video.date => Sat Apr 12 22:25:35 UTC 2008
# video.thumbnail_small => "http://i.ytimg.com/vi/mZqGqE0D0n4/default.jpg"
# video.thumbnail_medium => "http://i.ytimg.com/vi/mZqGqE0D0n4/mqdefault.jpg"
# video.thumbnail_large => "http://i.ytimg.com/vi/mZqGqE0D0n4/hqdefault.jpg"
# video.embed_url => "http://www.youtube.com/embed/mZqGqE0D0n4"
# video.embed_code => "'<iframe src="//www.youtube.com/embed/mZqGqE0D0n4" frameborder="0" allowfullscreen="allowfullscreen"></iframe>'"