module Transmission

Constants

VERSION

Public Class Methods

all(connector = nil) click to toggle source

Returns all torrents.

# File lib/transmission/extensions/transmission_selectors.rb, line 3
def self.all(connector = nil)
  t = Transmission::Model::Torrent.all connector: connector
  case t.ids.size
  when 0 then Array([])
  when 1 then Array(t)
  else Array(t.torrents)
  end
end
completed() click to toggle source

Returns all completed torrents.

# File lib/transmission/extensions/transmission_selectors.rb, line 18
def self.completed
  all.select { |t| t.attributes['percentDone'] >= 1 }
end
downloading() click to toggle source

Returns all downloading torrents.

# File lib/transmission/extensions/transmission_selectors.rb, line 38
def self.downloading
  all.select { |t| t.attributes['status'] == 4 }
end
errors() click to toggle source

Returns all torrents with errors.

# File lib/transmission/extensions/transmission_selectors.rb, line 48
def self.errors
  all.select { |t| t.attributes['error'] != 0 }
end
find_by_hash(hash) click to toggle source

Returns all torrents whose hash matches hash.

# File lib/transmission/extensions/transmission_selectors.rb, line 64
def self.find_by_hash(hash)
  all.select { |t| t.attributes['hashString'].casecmp(hash).zero? }
end
find_by_id(id) click to toggle source

Returns all torrents whose id matches id.

# File lib/transmission/extensions/transmission_selectors.rb, line 69
def self.find_by_id(id)
  all.select { |t| t.attributes['id'] == id }
end
find_by_name(name) click to toggle source

Returns all torrents whose name matches name.

# File lib/transmission/extensions/transmission_selectors.rb, line 58
def self.find_by_name(name)
  re = name.split(' ').join('.*')
  all.select { |t| t.attributes['name'] =~ /#{re}/i }
end
find_by_tracker(tracker) click to toggle source

Returns all torrents whose trackers match tracker. FIXME: regex matching is not very precise.

# File lib/transmission/extensions/transmission_selectors.rb, line 75
def self.find_by_tracker(tracker)
  url_regex = /([-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b)(?:[-a-zA-Z0-9@:%_\+.~#?&\/=]*)/i
  re = tracker.split(' ').join('.*')
  all.select do |t|
    trackers = t.attributes['trackers'].map do |r|
      if (a = r['announce'].match(url_regex))
        a[1]
      end
    end
    trackers.any? { |r| r =~ /#{re}/i }
  end
end
finished() click to toggle source

Returns all finished torrents.

# File lib/transmission/extensions/transmission_selectors.rb, line 13
def self.finished
  all.select { |t| t.attributes['isFinished'] }
end
hashes() click to toggle source

Returns the hash of every torrents.

# File lib/transmission/extensions/transmission_selectors.rb, line 53
def self.hashes
  all.map { |t| t.attributes['hashString'] }
end
incomplete() click to toggle source

Returns all incomplete torrents.

# File lib/transmission/extensions/transmission_selectors.rb, line 23
def self.incomplete
  all.select { |t| t.attributes['percentDone'] < 1 }
end
paused() click to toggle source

Returns all paused torrents.

# File lib/transmission/extensions/transmission_selectors.rb, line 28
def self.paused
  all.select { |t| t.attributes['status'] == 0 }
end
queued() click to toggle source

Returns all queued torrents.

# File lib/transmission/extensions/transmission_selectors.rb, line 33
def self.queued
  all.select { |t| t.attributes['status'] == 3 }
end
seeding() click to toggle source

Returns all seeding torrents.

# File lib/transmission/extensions/transmission_selectors.rb, line 43
def self.seeding
  all.select { |t| t.attributes['status'] == 6 }
end