mirror of
https://github.com/oddluck/limnoria-plugins.git
synced 2025-05-03 17:01:09 -05:00
SpiffyTitles: minor edit to bad link handling
This commit is contained in:
parent
a51bc196da
commit
877deb7a08
@ -133,7 +133,14 @@ conf.registerGlobalValue(
|
|||||||
conf.registerGlobalValue(
|
conf.registerGlobalValue(
|
||||||
SpiffyTitles,
|
SpiffyTitles,
|
||||||
"cacheGlobal",
|
"cacheGlobal",
|
||||||
registry.Boolean(False, _("""Keep link title cache globally""")),
|
registry.Boolean(
|
||||||
|
False,
|
||||||
|
_(
|
||||||
|
"""
|
||||||
|
Keep link cache globally. This will use default values for all link templates
|
||||||
|
"""
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
conf.registerChannelValue(
|
conf.registerChannelValue(
|
||||||
|
@ -224,14 +224,13 @@ class SpiffyTitles(callbacks.Plugin):
|
|||||||
self.registryValue("default.template", channel=channel)
|
self.registryValue("default.template", channel=channel)
|
||||||
)
|
)
|
||||||
(title, is_redirect) = self.get_source_by_url(url, channel)
|
(title, is_redirect) = self.get_source_by_url(url, channel)
|
||||||
if not title:
|
if title:
|
||||||
log.error(
|
title_template = default_template.render(
|
||||||
"SpiffyTitles: Unable to parse title from html response for %s"
|
title=title, redirect=is_redirect
|
||||||
% (url)
|
|
||||||
)
|
)
|
||||||
title = self.registryValue("badLinkText", channel=channel)
|
|
||||||
title_template = default_template.render(title=title, redirect=is_redirect)
|
|
||||||
return title_template
|
return title_template
|
||||||
|
else:
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
log.debug(
|
log.debug(
|
||||||
"SpiffyTitles: default handler fired but doing nothing because disabled"
|
"SpiffyTitles: default handler fired but doing nothing because disabled"
|
||||||
@ -386,7 +385,7 @@ class SpiffyTitles(callbacks.Plugin):
|
|||||||
title = ircutils.bold(title).strip()
|
title = ircutils.bold(title).strip()
|
||||||
return title
|
return title
|
||||||
|
|
||||||
def get_title_from_html(self, html):
|
def get_title_from_html(self, html, channel):
|
||||||
"""
|
"""
|
||||||
Retrieves value of <title> tag from HTML
|
Retrieves value of <title> tag from HTML
|
||||||
"""
|
"""
|
||||||
@ -396,7 +395,11 @@ class SpiffyTitles(callbacks.Plugin):
|
|||||||
try:
|
try:
|
||||||
title = soup.title.string.strip()
|
title = soup.title.string.strip()
|
||||||
except:
|
except:
|
||||||
pass
|
log.error(
|
||||||
|
"SpiffyTitles: Unable to parse title from html response for %s"
|
||||||
|
% (url)
|
||||||
|
)
|
||||||
|
title = self.registryValue("badLinkText", channel=channel)
|
||||||
return title
|
return title
|
||||||
|
|
||||||
def get_source_by_url(self, url, channel, retries=1):
|
def get_source_by_url(self, url, channel, retries=1):
|
||||||
@ -465,7 +468,7 @@ class SpiffyTitles(callbacks.Plugin):
|
|||||||
if content_type in acceptable_types:
|
if content_type in acceptable_types:
|
||||||
text = request.content
|
text = request.content
|
||||||
if text:
|
if text:
|
||||||
return (self.get_title_from_html(text), is_redirect)
|
return (self.get_title_from_html(text, channel), is_redirect)
|
||||||
else:
|
else:
|
||||||
log.debug("SpiffyTitles: empty content from %s" % (url))
|
log.debug("SpiffyTitles: empty content from %s" % (url))
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user