Fixes #14 - Adds option for ignoring a list of domains

This commit is contained in:
PrgmrBill 2015-04-10 19:33:31 -04:00
parent 1e76646eb3
commit bb5968d232
3 changed files with 58 additions and 2 deletions

View File

@ -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.

View File

@ -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""")))

View File

@ -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):