Youtube-Scraping

Aus C3D2
Wechseln zu: Navigation, Suche

Suchen & Saugen

<source lang="ruby">require 'ubygems' require 'mechanize' if ARGV.size < 1

 puts "Usage: #{$0} [ keywords ... ]"
 exit -1

end agent = WWW::Mechanize.new homepage = agent.get('http://www.youtube.com/') searchform = homepage.forms.select { |f| f.action == '/results' }.first searchform['search_query'] = ARGV.join(' ') result = searchform.submit result.root.traverse_element('td') do |td|

 if td.classes == ['vinfo']
   a = td.find_element('a') || raise
   puts a.children.to_s
   watch = agent.click(a)
   if watch.root.to_s =~ /\?video_id=(.+?)\&l=(.+?)\&t=(.+?)\&/
     video_id, l, t = $1, $2, $3
     p [video_id, l, t]
     video_id.gsub!(/[^a-zA-Z0-9_-]/, )
     video_id = a.get_attribute('href').split('?v=').last
     system("wget -O #{video_id}.flv 'http://www.youtube.com/get_video?video_id=#{video_id}&t=#{t}'")
   else
     puts "Warning: cannot find video URL"
   end
 end

end</source>


Speed metal coding 64x64.jpg
Rübÿ Spëëd Mëtäl Cödïng
Coders: Astro | Conny | Sven
Projects: CacaANSICam | Date Determinator | DVB-Scraping | Filmnächte-Scraping | GeeKal | Gruntmaster | Harvester | Hirn | Irb | Jargon-File | Ruby-MediaWiki | Miniwebserver | Momomoto | Pentabarf | Podcast-fetching | Ruby | Ruby-Geekend | Ruby und Ruby on Rails | Sedusa | VDS-Badges | Xmotoctl | Youtube-Scraping