class TorrentFinder::Adapters::NyaaAdapter
Public Class Methods
name()
click to toggle source
name of the adapter
# File lib/torrent-finder/adapters/nyaa_adapter.rb, line 9 def self.name "nyaa" end
Public Instance Methods
list(page=0)
click to toggle source
list recently available torrent
# File lib/torrent-finder/adapters/nyaa_adapter.rb, line 14 def list(page=0) url = page == 0 ? "http://www.nyaa.se/" : "http://www.nyaa.se/?offset=#{(page).to_s}" response = HTTParty.get(url) parse_html(response.body) end
search(terms)
click to toggle source
search and return available torrent
# File lib/torrent-finder/adapters/nyaa_adapter.rb, line 21 def search(terms) response = HTTParty.get("http://www.nyaa.se/?page=search&term=", :query => {"term" => terms}) parse_html(response.body) end
Protected Instance Methods
parse_html(html)
click to toggle source
# File lib/torrent-finder/adapters/nyaa_adapter.rb, line 27 def parse_html(html) doc = Nokogiri::HTML(html) rows = doc.search(".tlist .tlistrow") rows.collect do |row| name = row.search('.tlistname').text rescue nil url = row.search('.tlistdownload a').first['href'] rescue nil Torrent.new(name, url) end.select {|row| row.name && row.url } end