class Pirata::Search
Attributes
category[R]
pages[RW]
query[R]
results[RW]
sort_type[R]
Public Class Methods
new(query, sort_type = Pirata::Sort::RELEVANCE, categories = ["0"])
click to toggle source
# File lib/pirata/search.rb, line 15 def initialize(query, sort_type = Pirata::Sort::RELEVANCE, categories = ["0"]) @sort_type = sort_type @category = categories.join(',') @pages = 0 @query = query @results = search() end
recent()
click to toggle source
Return an array of the 30 most recent Torrents
# File lib/pirata/search.rb, line 49 def self.recent url = Pirata.config[:base_url] + '/recent' html = self.parse_html(url) Pirata::Search::parse_search_page(html) end
top(category = "all")
click to toggle source
Return the n most recent torrents from a category Searches all categories if none supplied
# File lib/pirata/search.rb, line 42 def self.top(category = "all") url = Pirata.config[:base_url] + '/top/' + URI.escape(category) html = self.parse_html(url) Pirata::Search::parse_search_page(html) end
Public Instance Methods
multipage?()
click to toggle source
# File lib/pirata/search.rb, line 55 def multipage? @pages > 0 end
parse_html(url)
click to toggle source
# File lib/pirata/search.rb, line 63 def parse_html(url) response = open(url, :allow_redirections => Pirata.config[:redirect]) Nokogiri::HTML(response) end
search(page = 0)
click to toggle source
Perform a search and return an array of Torrent
objects
# File lib/pirata/search.rb, line 24 def search(page = 0) #build URL ex: http://thepiratebay.se/search/cats/0/99/0 url = Pirata.config[:base_url] + "/search/#{URI.escape(@query)}" + "/#{page.to_s}" + "/#{@sort_type}" + "/#{@category}" html = Pirata::Search.parse_html(url) Pirata::Search::parse_search_page(html, self) end
search_page(page)
click to toggle source
Return the n page results of a search, assuming it is multipage
# File lib/pirata/search.rb, line 32 def search_page(page) raise "Search must be multipage to search pages" if !multipage? raise "Page must be a valid, positive integer" if page.class != Fixnum || page < 0 raise "Invalid page range" if page > @pages self.search(page) end