From 24514349bdf39f3d163c040bc38b3c3ebe24db4f Mon Sep 17 00:00:00 2001 From: jntn-st Date: Sun, 21 Apr 2019 21:12:05 +0200 Subject: [PATCH 1/2] Support exclude filters --- lib/transmission-rss/aggregator.rb | 2 +- lib/transmission-rss/feed.rb | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/transmission-rss/aggregator.rb b/lib/transmission-rss/aggregator.rb index e882637..fd5b4f6 100644 --- a/lib/transmission-rss/aggregator.rb +++ b/lib/transmission-rss/aggregator.rb @@ -103,7 +103,7 @@ def process_link(feed, item) # The link is not in +@seen+ Array. unless @seen.include?(link) # Skip if filter defined and not matching. - unless feed.matches_regexp?(item.title) + unless feed.matches_regexp?(item.title) && !(feed.exclude?(item.title)) @seen.add(link) return end diff --git a/lib/transmission-rss/feed.rb b/lib/transmission-rss/feed.rb index 8436c24..0b7abbd 100644 --- a/lib/transmission-rss/feed.rb +++ b/lib/transmission-rss/feed.rb @@ -4,6 +4,7 @@ class Feed def initialize(config = {}) @download_paths = {} + @excludes = {} case config when Hash @@ -20,7 +21,7 @@ def initialize(config = {}) @regexp = build_regexp(matchers) - initialize_download_paths(config['regexp']) + initialize_download_paths_and_excludes(config['regexp']) else @config = {} @url = config.to_s @@ -41,6 +42,13 @@ def matches_regexp?(title) @regexp.nil? || !(title =~ @regexp).nil? end + def exclude?(title) + @excludes.each do |regexp, exclude| + return title =~ to_regexp(exclude) if title =~ to_regexp(regexp) + end + return false + end + private def build_regexp(matchers) @@ -48,14 +56,16 @@ def build_regexp(matchers) matchers.empty? ? nil : Regexp.union(matchers) end - def initialize_download_paths(regexps) + def initialize_download_paths_and_excludes(regexps) return unless regexps.is_a?(Array) regexps.each do |regexp| matcher = regexp['matcher'] path = regexp['download_path'] + exclude = regexp['exclude'] @download_paths[matcher] = path if matcher && path + @excludes[matcher] = exclude if matcher && exclude end end From 9a0cc9fc8468cd0c6dbe7a1f91271ab3088e9838 Mon Sep 17 00:00:00 2001 From: jntn-st Date: Sun, 21 Apr 2019 21:33:17 +0200 Subject: [PATCH 2/2] Add example of exclude filter to example config --- transmission-rss.conf.example | 1 + 1 file changed, 1 insertion(+) diff --git a/transmission-rss.conf.example b/transmission-rss.conf.example index 38fa207..b8085e9 100644 --- a/transmission-rss.conf.example +++ b/transmission-rss.conf.example @@ -27,6 +27,7 @@ feeds: regexp: - matcher: match1 download_path: /home/user/match1 + exclude: dontmatch - matcher: match2 download_path: /home/user/match2 - url: http://example.com/feed8