Class: Xunlei::Engine
- Inherits:
-
Object
- Object
- Xunlei::Engine
- Defined in:
- lib/xunlei/engine.rb
Instance Method Summary collapse
- #add_task(target_address) ⇒ Object
- #dump_cookies ⇒ Object
- #dump_tasks ⇒ Object
-
#initialize(username, password, driver = :chrome) ⇒ Engine
constructor
A new instance of Engine.
- #stop ⇒ Object
Constructor Details
#initialize(username, password, driver = :chrome) ⇒ Engine
Returns a new instance of Engine.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/xunlei/engine.rb', line 6 def initialize(username, password, driver = :chrome) @browser = Watir::Browser.new driver @browser.goto "http://lixian.vip.xunlei.com" @browser.text_field(:id => "u").when_present.set(username) @browser.text_field(:id => "p_show").when_present.set(password) @browser.(:id => "button_submit4reg").when_present.click # temp fix for stupid cloud VOD popup wait_until_all_loaded #@browser.div(:class => "p_rw_pop p_sc_pop p_yuntips").p(:class => 'p_btm_aline').as.first.when_present.click end |
Instance Method Details
#add_task(target_address) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/xunlei/engine.rb', line 46 def add_task(target_address) puts "Adding new task..." # open('|pbcopy', 'w') { |io| io << target_address } @browser.execute_script("add_task_new(0)") @browser.text_field(:id => 'task_url').wait_until_present # @browser.send_keys [:command, 'v'] @browser.execute_script("document.getElementById('task_url').value = '#{target_address}'") puts "Task URL = \"#{target_address}\"" expire_count = 0 sleep(2.0) while !(@browser.(:id => 'down_but').enabled? && expire_count <= 5000) expire_count += 1 end if expire_count <= 5000 print "Submitting... " @browser.(:id => 'down_but').when_present.click puts "Done." else puts "Timed out, the button is unavailable." end end |
#dump_cookies ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/xunlei/engine.rb', line 19 def wait_until_all_loaded = [] @browser.driver.manage..each do || domain = [:domain] path = [:path] expires = [:expires] ? [:expires].strftime("%s") : "0" name = [:name] value = [:value] << "#{domain}\tTRUE\t#{path}\tFALSE\t#{expires}\t#{name}\t#{value}\n" end end |
#dump_tasks ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/xunlei/engine.rb', line 35 def dump_tasks all_files = [] sleep 2 begin all_files += process_current_page end while next_page all_files end |
#stop ⇒ Object
72 73 74 |
# File 'lib/xunlei/engine.rb', line 72 def stop @browser.close end |