class BitTorrent

Constants

DEFAULTS

Attributes

sources[R]

Public Class Methods

download(sources, options = {}) click to toggle source
# File lib/bit_torrent.rb, line 27
def self.download(sources, options = {})
  new(sources, options).download
end
download!(sources, options = {}) click to toggle source
# File lib/bit_torrent.rb, line 31
def self.download!(sources, options = {})
  new(sources, options).download!
end
new(source, options = {}) click to toggle source
# File lib/bit_torrent.rb, line 20
def initialize(source, options = {})
  @sources = [ source ].flatten
  DEFAULTS.keys.each do |option|
    self.instance_variable_set("@#{option}", (options[option] || DEFAULTS[option]))
  end
end

Public Instance Methods

download() click to toggle source
# File lib/bit_torrent.rb, line 35
def download
  system(download_commmand)
end
download!() click to toggle source
# File lib/bit_torrent.rb, line 39
def download!
  download or raise DownloadError
end

Private Instance Methods

download_commmand() click to toggle source
# File lib/bit_torrent.rb, line 45
def download_commmand
  [
    'aria2c',
    "--dir=#{destination_directory}",
    '--bt-enable-lpd',
    '--bt-min-crypto-level=arc4',
    '--bt-require-crypto=true',
    '--enable-dht=true',
    '--enable-peer-exchange=true',
    "--max-overall-upload-limit=#{upload_rate_limit}",
    "--seed-ratio=#{seed_ratio}",
    "--seed-time=#{seed_time}",
    "--bt-tracker-connect-timeout=#{connect_timeout}",
    "--bt-tracker-timeout=#{timeout}",
    "--bt-stop-timeout=#{stop_timeout}",
    tor_proxy_options,
    sources.map { |s| "'#{s}'" }
  ].flatten.compact.join(' ')
end
tor_proxy_options() click to toggle source
# File lib/bit_torrent.rb, line 65
def tor_proxy_options
  if use_tor_proxy
    if use_tor_proxy.is_a?(String)
      "--all-proxy=#{use_tor_proxy}"
    else
      '--all-proxy=127.0.0.1:9050'
    end
  end
end