Module: Transmission
- Defined in:
- lib/transmission.rb,
lib/transmission/rpc.rb,
lib/transmission/model.rb,
lib/transmission/utils.rb,
lib/transmission/config.rb,
lib/transmission/fields.rb,
lib/transmission/arguments.rb,
lib/transmission/model/session.rb,
lib/transmission/model/torrent.rb,
lib/transmission/rpc/connector.rb,
lib/transmission/fields/session_get.rb,
lib/transmission/fields/torrent_get.rb,
lib/transmission/model/session_stats.rb,
lib/transmission/fields/session_stats.rb,
lib/transmission/arguments/session_set.rb,
lib/transmission/arguments/torrent_add.rb,
lib/transmission/arguments/torrent_set.rb,
lib/transmission/arguments/location_set.rb,
lib/transmission/extensions/torrent_status.rb,
lib/transmission/extensions/torrent_actions.rb,
lib/transmission/extensions/torrent_prettify.rb,
lib/transmission/extensions/torrent_attributes.rb,
lib/transmission/extensions/transmission_selectors.rb
Defined Under Namespace
Modules: Model, Utils Classes: Arguments, Config, Fields, RPC
Constant Summary collapse
- VERSION =
'0.1.1'.freeze
Class Method Summary collapse
-
.all(connector = nil) ⇒ Object
Returns all torrents.
-
.completed ⇒ Object
Returns all completed torrents.
-
.downloading ⇒ Object
Returns all downloading torrents.
-
.errors ⇒ Object
Returns all torrents with errors.
-
.find_by_hash(hash) ⇒ Object
Returns all torrents whose hash matches
hash. -
.find_by_id(id) ⇒ Object
Returns all torrents whose id matches
id. -
.find_by_name(name) ⇒ Object
Returns all torrents whose name matches
name. -
.find_by_tracker(tracker) ⇒ Object
Returns all torrents whose trackers match
tracker. -
.finished ⇒ Object
Returns all finished torrents.
-
.hashes ⇒ Object
Returns the hash of every torrents.
-
.incomplete ⇒ Object
Returns all incomplete torrents.
-
.paused ⇒ Object
Returns all paused torrents.
-
.queued ⇒ Object
Returns all queued torrents.
-
.seeding ⇒ Object
Returns all seeding torrents.
Class Method Details
.all(connector = nil) ⇒ Object
Returns all torrents.
3 4 5 6 7 8 9 10 |
# 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 ⇒ Object
Returns all completed torrents.
18 19 20 |
# File 'lib/transmission/extensions/transmission_selectors.rb', line 18 def self.completed all.select { |t| t.attributes['percentDone'] >= 1 } end |
.downloading ⇒ Object
Returns all downloading torrents.
38 39 40 |
# File 'lib/transmission/extensions/transmission_selectors.rb', line 38 def self.downloading all.select { |t| t.attributes['status'] == 4 } end |
.errors ⇒ Object
Returns all torrents with errors.
48 49 50 |
# File 'lib/transmission/extensions/transmission_selectors.rb', line 48 def self.errors all.select { |t| t.attributes['error'] != 0 } end |
.find_by_hash(hash) ⇒ Object
Returns all torrents whose hash matches hash.
64 65 66 |
# 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) ⇒ Object
Returns all torrents whose id matches id.
69 70 71 |
# 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) ⇒ Object
Returns all torrents whose name matches name.
58 59 60 61 |
# 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) ⇒ Object
Returns all torrents whose trackers match tracker. FIXME: regex matching is not very precise.
75 76 77 78 79 80 81 82 83 84 85 86 |
# 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 ⇒ Object
Returns all finished torrents.
13 14 15 |
# File 'lib/transmission/extensions/transmission_selectors.rb', line 13 def self.finished all.select { |t| t.attributes['isFinished'] } end |
.hashes ⇒ Object
Returns the hash of every torrents.
53 54 55 |
# File 'lib/transmission/extensions/transmission_selectors.rb', line 53 def self.hashes all.map { |t| t.attributes['hashString'] } end |
.incomplete ⇒ Object
Returns all incomplete torrents.
23 24 25 |
# File 'lib/transmission/extensions/transmission_selectors.rb', line 23 def self.incomplete all.select { |t| t.attributes['percentDone'] < 1 } end |
.paused ⇒ Object
Returns all paused torrents.
28 29 30 |
# File 'lib/transmission/extensions/transmission_selectors.rb', line 28 def self.paused all.select { |t| t.attributes['status'] == 0 } end |
.queued ⇒ Object
Returns all queued torrents.
33 34 35 |
# File 'lib/transmission/extensions/transmission_selectors.rb', line 33 def self.queued all.select { |t| t.attributes['status'] == 3 } end |
.seeding ⇒ Object
Returns all seeding torrents.
43 44 45 |
# File 'lib/transmission/extensions/transmission_selectors.rb', line 43 def self.seeding all.select { |t| t.attributes['status'] == 6 } end |