From bb5968d232ee479f65ba690ca30e25894b8e42a2 Mon Sep 17 00:00:00 2001 From: PrgmrBill Date: Fri, 10 Apr 2015 19:33:31 -0400 Subject: [PATCH] Fixes #14 - Adds option for ignoring a list of domains --- README.md | 15 +++++++++++++++ config.py | 22 ++++++++++++++++++++++ plugin.py | 23 +++++++++++++++++++++-- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b0e1e78..adb7901 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,21 @@ Default: `useBold` - Whether to bold the title. Defaults to `False` +`ignoredDomainPatterns` - a comma separated list of strings that are regular expressions to match +against URLs posted in channels. + +Examples + +Ignore all domains matching *.tk + + r"(.*)\.tk" + + +Ignore all domains matching *.net + + r"(.*)\.net" + + `userAgents` - A comma separated list of strings of user agents randomly chosen when requesting. `urlRegularExpression` - A regular expression used to match URLs. You shouldn't need to change this. diff --git a/config.py b/config.py index 1d1a84e..e8d9360 100644 --- a/config.py +++ b/config.py @@ -50,3 +50,25 @@ conf.registerGlobalValue(SpiffyTitles, 'userAgents', # Mime Types conf.registerGlobalValue(SpiffyTitles, 'mimeTypes', registry.CommaSeparatedListOfStrings(["text/html"], _("""Acceptable mime types for displaying titles"""))) + +# Ignored domain patterns +conf.registerGlobalValue(SpiffyTitles, 'ignoredDomainPatterns', + registry.CommaSeparatedListOfStrings([], _("""Domains matching these patterns will be ignored"""))) + + + + + + + + + + + + + + + + + + diff --git a/plugin.py b/plugin.py index d20058b..a4496f3 100644 --- a/plugin.py +++ b/plugin.py @@ -48,6 +48,11 @@ class SpiffyTitles(callbacks.Plugin): if info: domain = info.netloc + is_ignored = self.is_ignored_domain(domain) + + if is_ignored: + self.log.info("SpiffyTitles: ignoring url due to pattern match: %s" % (url)) + return handlers = { "youtube.com": self.handler_youtube, @@ -71,6 +76,18 @@ class SpiffyTitles(callbacks.Plugin): irc.reply(formatted_title) + def is_ignored_domain(self, domain): + ignored_patterns = self.registryValue("ignoredDomainPatterns") + + if ignored_patterns: + for pattern in ignored_patterns: + pattern_search_result = re.search(pattern, domain) + + if pattern_search_result is not None: + match = pattern_search_result.group() + + return match + def get_video_id_from_url(self, url, info, irc): try: path = info.path @@ -82,7 +99,7 @@ class SpiffyTitles(callbacks.Plugin): else: parsed = cgi.parse_qsl(info.query) video_id = dict(parsed)["v"] - + if video_id: return video_id else: @@ -132,7 +149,9 @@ class SpiffyTitles(callbacks.Plugin): # If we found a title, return that. otherwise, use default handler if title: return title - else: + else: + self.log.info("SpiffyTitles: falling back to default handler") + return self.handler_default(url, domain, irc) def handler_default(self, url, domain, irc):