Created
September 9, 2010 00:09
-
-
Save guilherme/571109 to your computer and use it in GitHub Desktop.
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
# THIS SNIPPET OPEN A LOG FILE THEN | |
# SEARCH FOR YOUTUBE LINKS AND GET ALL VIDEO TITLES. | |
require 'rubygems' | |
require 'hpricot' | |
require 'fileutils' | |
require 'open-uri' | |
youtube_xml_url = "http://gdata.youtube.com/feeds/api/videos/" | |
youtube_url = "http://youtube.com/watch?v=" | |
video_regexp = /youtube\.com\/watch\?v=([A-Za-z0-9\-_]*)/ | |
videos = [] | |
video_names = [] | |
File.open('LOG_FILE.log') do |f| | |
f.each_line do |line| | |
video = line.match(video_regexp) | |
if video | |
videos.push(video[1]) | |
end | |
end | |
end | |
videos.each do |video| | |
video_xml_url = youtube_xml_url+video | |
video_youtube_url = youtube_url+video | |
begin | |
document = Hpricot(open(video_xml_url).read) | |
video_name = document.search("media:title")[0].inner_html | |
video_names.push(video_name) | |
puts "#{video_name} : #{video_youtube_url}" | |
rescue OpenURI::HTTPError | |
puts "Erro ao abrir o video: #{video_youtube_url}\n" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment