class BulkYoutube::Scrape
Attributes
max_retries[RW]
save_destination[RW]
search_path[RW]
Public Class Methods
new(search_path=nil, save_destination=nil, max_downloads=2, max_retries=10)
click to toggle source
# File lib/bulk_youtube.rb, line 14 def initialize(search_path=nil, save_destination=nil, max_downloads=2, max_retries=10) @search_path = search_path @save_destination = save_destination @max_downloads = max_downloads @max_retries = max_retries end
Public Instance Methods
grab_links(word=nil)
click to toggle source
# File lib/bulk_youtube.rb, line 30 def grab_links(word=nil) gather(word) end
links()
click to toggle source
# File lib/bulk_youtube.rb, line 45 def links @link_arr end
show()
click to toggle source
# File lib/bulk_youtube.rb, line 34 def show arr = [] @link_arr.each do |link| REPLACE.each do |r| link.text.gsub!(r[0], r[1]) end arr << link end arr end
you_convert()
click to toggle source
# File lib/bulk_youtube.rb, line 22 def you_convert begin send_files(@link_arr) rescue StandardError false end end
Private Instance Methods
gather(word)
click to toggle source
returns itself
# File lib/bulk_youtube.rb, line 65 def gather(word) @link_arr = [] path = mec_get(@search_path) count = 0 if word.nil? path.links_with(:href => /watch\?v=/).each do |link| break if count > @max_downloads @link_arr << link count += 1 end else path.links_with(:text => /#{word}/).each do |link| break if count > @max_downloads if link.text.include?(word) && link.href.include?('watch?v=') @link_arr << link count += 1 end end end self end
mec_get(path)
click to toggle source
# File lib/bulk_youtube.rb, line 60 def mec_get(path) Mechanize.new.get(path) end
noko(path)
click to toggle source
# File lib/bulk_youtube.rb, line 56 def noko(path) Nokogiri::HTML(path) end
send_files(links)
click to toggle source
requires an array
# File lib/bulk_youtube.rb, line 95 def send_files(links) you_convert = 'http://www.youtubeinmp4.com/' links.each_with_index do |link, i| clicked_link = link.href form = mec_get(you_convert).forms[0] next if link.nil? puts "printing link #{i}" form.field_with(:class => 'c3').value = clicked_link path = "#{@save_destination}/#{i}.mp4" form.submit.links[1].click.save_as(path) puts "link #{1} successful" end end