diff --git a/config.py b/config.py index 52dca3a..40e410b 100644 --- a/config.py +++ b/config.py @@ -41,6 +41,9 @@ conf.registerGlobalValue(SpiffyTitles, 'language', conf.registerGlobalValue(SpiffyTitles, 'imdbTemplate', registry.String("^ {{Title}} ({{Year}}, {{Country}}) - Rating: {{imdbRating}} :: {{Plot}}", _("""Uses http://www.omdbapi.com to provide additional information about IMDB links"""))) +# alternative template: +# ^ {{Title}} ({{Year}} - {{Director}}) :: [i:{{imdbRating}} r:{{tomatoMeter}} m:{{Metascore}}] {{Plot}} + conf.registerGlobalValue(SpiffyTitles, 'coubTemplate', registry.String("^ {%if not_safe_for_work %}NSFW{% endif %} [{{channel.title}}] {{title}} :: {{views_count}} views :: {{likes_count}} likes :: {{recoubs_count}} recoubs", _("""Uses Coub API to get additional information about coub.com links"""))) @@ -154,3 +157,7 @@ conf.registerGlobalValue(SpiffyTitles, 'requireCapability', + +conf.registerGlobalValue(SpiffyTitles, 'ignoredTitlePattern', + registry.Regexp("", _("""Titles matching this pattern will be ignored."""))) + diff --git a/plugin.py b/plugin.py index d947934..e152e8d 100644 --- a/plugin.py +++ b/plugin.py @@ -339,7 +339,13 @@ class SpiffyTitles(callbacks.Plugin): if title is not None and title: self.log.info("SpiffyTitles: title found: %s" % (title)) - irc.sendMsg(ircmsgs.privmsg(channel, title)) + ignore_match = self.title_matches_ignore_pattern(title) + + if ignore_match: + self.log.info("SpiffyTitles: ignoring title due to ignoredTitlePattern match") + return + else: + irc.sendMsg(ircmsgs.privmsg(channel, title)) else: if self.default_handler_enabled: self.log.debug("SpiffyTitles: could not get a title for %s" % (url)) @@ -753,7 +759,7 @@ class SpiffyTitles(callbacks.Plugin): # We can only accommodate a specific format of URL here if "/title/" in url: imdb_id = url.split("/title/")[1].rstrip("/") - omdb_url = "http://www.omdbapi.com/?i=%s&plot=short&r=json" % (imdb_id) + omdb_url = "http://www.omdbapi.com/?i=%s&plot=short&r=json&tomatoes=true" % (imdb_id) try: request = requests.get(omdb_url, timeout=10, headers=headers) @@ -1069,6 +1075,19 @@ class SpiffyTitles(callbacks.Plugin): return match + def title_matches_ignore_pattern(self, input): + """ + Checks message against ignoredTitlePattern to determine + whether the title should be ignored. + """ + match = False + pattern = self.registryValue("ignoredTitlePattern") + + if pattern: + match = re.search(pattern, input) + + return match + def get_url_from_message(self, input): """ Find the first string that looks like a URL from the message