Guest User

Untitled

a guest
Feb 27th, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.02 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. require './req_gemcook.rb'
  3. $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'ext')))
  4. $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
  5.  
  6. web = Watir::Browser.new :phantomjs
  7.  
  8. DB = Sequel.connect('sqlite://clublandlv.sqlite')
  9.  
  10. zippy_mp3 = DB[:songsdown].select_map(:zippy_mp3)
  11. zippy_link = DB[:songsdown].select_map(:zippy_url)
  12. songsdown = DB[:songsdown]
  13.  
  14.  
  15. index = zippy_link
  16. index.each do |zip|
  17.  
  18.   web.goto(zip)
  19.  
  20.   webtitle = web.title
  21.   webtext = web.text
  22.  
  23.   if web.link(:id => 'dlbutton').exists?
  24.     songsdown.where(:zippy_url => zip).update(:healthy => 1)
  25.     dl_link = web.link(:id => 'dlbutton').href
  26.     zip_link = songsdown.where(:zippy_url => zip).get(:zippy_url)
  27.     songsdown.where(:zippy_url => zip).update(:zippy_mp3 => dl_link)
  28.       puts "You are viewing: #{webtitle}"
  29.       puts "Got this download link: #{dl_link}"
  30.  
  31.  
  32.     easy = Curl::Easy.new autoreferer = true
  33.     easy.headers['User-Agent'] = "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:27.0) Gecko/20100101 Firefox/27.0"
  34.     easy.headers['Referer'] = "#{zip_link}"
  35.  
  36.     easy.url = dl_link
  37.     filename = songsdown.where(:zippy_url => zip).get(:song_title)
  38.     print "'#{filename}' :"
  39.     File.open(filename, 'w') do|f|
  40.       easy.on_progress {|dl_total, dl_now, ul_total, ul_now| print "="; true }
  41.       easy.on_body {|data| f << data; data.size }
  42.       easy.perform
  43.         puts "=> '#{filename}'"
  44.       puts
  45.     end
  46.  
  47.   elsif webtext.include? "File does not exist on this server" && "File has expired and does not exist anymore on this server"
  48.     songsdown.where(:zippy_url => zip).update(:healthy => 0)
  49.       puts "File is expired or mising"
  50.   else
  51.     songsdown.where(:zippy_url => zip).update(:healthy => 2)
  52.       puts "∆∆∆∆∆∆∆∆∆∆This is an ad. Really wish phantomjs supported custom headers∆∆∆∆∆∆∆∆∆∆"
  53.       puts
  54.   end
  55.   sleep(2)
  56. end
  57.  
  58. songsdown.where(:zippy_url => nil).update(:healthy => 2, :zippy_mp3 => nil)
Advertisement
Add Comment
Please, Sign In to add comment