class ExtratorrentSearch::Search
Extract a list of results from your search ExtratorrentSearch::Search.new
(“Suits s05e16”)
Constants
- BASE_URL
- NUMBER_OF_LINKS
Attributes
url[RW]
Public Class Methods
new(search)
click to toggle source
# File lib/extratorrent_search/search.rb, line 16 def initialize(search) # Order by seeds desc @url = "#{BASE_URL}/search/?search=#{ERB::Util.url_encode(search)}&srt=seeds&order=desc" end
Public Instance Methods
links()
click to toggle source
# File lib/extratorrent_search/search.rb, line 27 def links @links ||= generate_links end
results_found?()
click to toggle source
# File lib/extratorrent_search/search.rb, line 21 def results_found? @results_found ||= page.at('i:contains("No torrents")').nil? rescue OpenURI::HTTPError @results_found = false end
Private Instance Methods
crawl_link(link)
click to toggle source
# File lib/extratorrent_search/search.rb, line 37 def crawl_link(link) Link.new( filename: link.at('.tli > a').text, size: link.css('td')[4].text, magnet_link: link.at('a[title="Magnet link"]')['href'], seeders: link.at('td.sy, td.sn').text, leechers: link.at('td.ly, td.ln').text ) end
generate_links()
click to toggle source
# File lib/extratorrent_search/search.rb, line 47 def generate_links links = [] return links unless results_found? link_nodes = page.css('tr.tlr, tr.tlz') link_nodes.each { |link| links << crawl_link(link) } links.first(NUMBER_OF_LINKS) end
page()
click to toggle source
# File lib/extratorrent_search/search.rb, line 33 def page @page ||= Nokogiri::HTML(open(@url)) end