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.
17 18 19 |
# File 'lib/transmission-rss/aggregator.rb', line 17 def initialize(feeds = [], = {}) reinitialize!(feeds, ) end |
Instance Attribute Details
#seen ⇒ Object (readonly)
Returns the value of attribute seen.
15 16 17 |
# File 'lib/transmission-rss/aggregator.rb', line 15 def seen @seen end |
Instance Method Details
#reinitialize!(feeds = [], options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/transmission-rss/aggregator.rb', line 21 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(nil, 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.
39 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 |
# File 'lib/transmission-rss/aggregator.rb', line 39 def run(interval = 600) @log.debug('aggregator start') loop do @feeds.each do |feed| @log.debug('aggregate ' + feed.url) begin content = open(feed.url, allow_redirections: :safe).read 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 = RSS::Parser.parse(content, false).items 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 sleep(interval) end end |