Sha256: 7efe408bbf2521bb3bdec617013eb4d9f14d3ffc0f9701378c4291b25acf2b90

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module DownloadTV
  ##
  # ThePirateBay grabber
  class ThePirateBayAPI < LinkGrabber
    TRACKERS = %w[
      udp://tracker.coppersurfer.tk:6969/announce
      udp://tracker.openbittorrent.com:6969/announce
      udp://tracker.opentrackr.org:1337
      udp://movies.zsw.ca:6969/announce
      udp://tracker.dler.org:6969/announce
      udp://opentracker.i2p.rocks:6969/announce
      udp://open.stealth.si:80/announce
      udp://tracker.0x.tf:6969/announce
    ]

    def initialize
      super("https://tpb36.ukpass.co/apibay/q.php?q=%s&cat=")
    end

    def get_links(show)
      search = format(@url, show)

      data = agent.get(search)
      parsed = JSON.parse(data.body)

      raise NoTorrentsError if parsed.size == 1 && parsed.first['name'] == 'No results returned'

      parsed.map do |elem|
        [elem['name'], build_magnet(elem['info_hash'], elem['name'])]
      end
    end

    private

    def build_magnet(torrent_hash, name)
      "magnet:?xt=urn:btih:#{torrent_hash}&dn=#{CGI.escape(name)}#{trackers_params}"
    end

    def trackers_params
      trackers_params ||= "&tr=#{TRACKERS.map { |tracker| CGI.escape(tracker) }.join('&tr=')}"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
download_tv-2.9.1 lib/download_tv/grabbers/tpbapi.rb
download_tv-2.9.0 lib/download_tv/grabbers/tpbapi.rb
download_tv-2.8.5 lib/download_tv/grabbers/tpbapi.rb