Class: TransmissionRSS::Aggregator
- Extended by:
- Callback
- Defined in:
- lib/transmission-rss/aggregator.rb
Overview
Class for aggregating torrent files through RSS feeds.
Instance Attribute Summary collapse
-
#seen ⇒ Object
readonly
Returns the value of attribute seen.
Instance Method Summary collapse
-
#initialize(feeds = [], options = {}) ⇒ Aggregator
constructor
A new instance of Aggregator.
- #reinitialize!(feeds = [], options = {}) ⇒ Object
-
#run(interval = 600) ⇒ Object
Get file enclosures from all feeds items and call on_new_item callback with torrent file URL as argument.
Methods included from Callback
Constructor Details
#initialize(feeds = [], options = {}) ⇒ Aggregator
Returns a new instance of Aggregator.
18 19 20 |
# File 'lib/transmission-rss/aggregator.rb', line 18 def initialize(feeds = [], = {}) reinitialize!(feeds, ) end |
Instance Attribute Details
#seen ⇒ Object (readonly)
Returns the value of attribute seen.
16 17 18 |
# File 'lib/transmission-rss/aggregator.rb', line 16 def seen @seen end |
Instance Method Details
#reinitialize!(feeds = [], options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/transmission-rss/aggregator.rb', line 22 def reinitialize!(feeds = [], = {}) seen_file = [:seen_file] # Prepare Array of feeds URLs. @feeds = feeds.map { |config| TransmissionRSS::Feed.new(config) } # Nothing seen, yet. @seen = SeenFile.new(seen_file) # Initialize log instance. @log = Log.instance # Log number of +@seen+ URIs. @log.debug(@seen.size.to_s + ' uris from seenfile') end |
#run(interval = 600) ⇒ Object
Get file enclosures from all feeds items and call on_new_item callback with torrent file URL as argument.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/transmission-rss/aggregator.rb', line 40 def run(interval = 600) @log.debug('aggregator start') loop do @feeds.each do |feed| @log.debug('aggregate ' + feed.url) begin content = fetch(feed) rescue StandardError => e @log.debug("retrieval error (#{e.class}: #{e.})") next end # gzip HTTP Content-Encoding is not automatically decompressed in # Ruby 1.9.3. content = decompress(content) if RUBY_VERSION == '1.9.3' begin items = parse(content) rescue StandardError => e @log.debug("parse error (#{e.class}: #{e.})") next end items.each do |item| result = process_link(feed, item) next if result.nil? end end if interval == -1 @log.debug('single run mode, exiting') break end sleep(interval) end end |