Class: JavLibrary::Client
- Inherits:
-
Object
- Object
- JavLibrary::Client
- Defined in:
- lib/jav_library/client.rb
Instance Attribute Summary collapse
-
#success ⇒ Object
readonly
Returns the value of attribute success.
Instance Method Summary collapse
- #cast ⇒ Object
- #close ⇒ Object
- #cover ⇒ Object
- #genres ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #load(code) ⇒ Object
- #release_date ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 |
# File 'lib/jav_library/client.rb', line 10 def initialize @browser = Watir::Browser.new :firefox, 'pageLoadStrategy': 'eager' # Disable alerts @browser.execute_script "window.alert = () => {}" end |
Instance Attribute Details
#success ⇒ Object (readonly)
Returns the value of attribute success.
8 9 10 |
# File 'lib/jav_library/client.rb', line 8 def success @success end |
Instance Method Details
#cast ⇒ Object
53 54 55 |
# File 'lib/jav_library/client.rb', line 53 def cast @doc.css('#video_cast .star a').map {|node| node.content.split('(', 2).first.strip } end |
#close ⇒ Object
70 71 72 |
# File 'lib/jav_library/client.rb', line 70 def close @browser.close end |
#cover ⇒ Object
57 58 59 60 |
# File 'lib/jav_library/client.rb', line 57 def cover src = @doc.at_css('#video_jacket_img').attr('src') 'https:' + src.sub('http:', '') end |
#genres ⇒ Object
66 67 68 |
# File 'lib/jav_library/client.rb', line 66 def genres @doc.css("#video_genres .genre").map(&:content) end |
#load(code) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/jav_library/client.rb', line 16 def load(code) @browser.goto HOST + code @browser..add "over18", "18" # For cloudflare's ddos checking begin while @browser.html.include? "<title>Just a moment...</title>" sleep 0.1 end rescue sleep 0.1 retry end # Wait until page is loaded until @browser.html.include? 'leftmenu' sleep 0.1 end @success = !@browser.html.include?('The search term you entered is invalid.') @doc = Nokogiri::HTML @browser.html # if multiple search results if @doc.css('.videos .video').length > 1 url = 'http://www.javlibrary.com/en/' url += @doc.at_css('.videos a').attr('href').split('./', 2).last @browser.goto url @browser..add 'over18', '18' @doc = Nokogiri::HTML(@browser.html) end end |
#release_date ⇒ Object
62 63 64 |
# File 'lib/jav_library/client.rb', line 62 def release_date @doc.at_css("#video_date .text").content end |
#title ⇒ Object
48 49 50 51 |
# File 'lib/jav_library/client.rb', line 48 def title # splits to remove the prepended jav code @doc.at_css('.post-title a').content.split(' ', 2).last end |