Skip to content

Instantly share code, notes, and snippets.

@guilherme
Created September 9, 2010 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilherme/571109 to your computer and use it in GitHub Desktop.
Save guilherme/571109 to your computer and use it in GitHub Desktop.
# 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