mirror of
https://github.com/oddluck/limnoria-plugins.git
synced 2025-04-29 23:11:09 -05:00
IMDb/Lyrics: add more error/debug logging
This commit is contained in:
parent
be8f7e877b
commit
52c28ca15d
@ -72,9 +72,14 @@ class IMDb(callbacks.Plugin):
|
|||||||
google = ddg = match = None
|
google = ddg = match = None
|
||||||
if self.registryValue("google", channel) > 0:
|
if self.registryValue("google", channel) > 0:
|
||||||
google = irc.getCallback("google")
|
google = irc.getCallback("google")
|
||||||
|
if not google:
|
||||||
|
log.error("IMDb: Error: Google search enabled but plugin not loaded.")
|
||||||
if self.registryValue("ddg", channel) > 0:
|
if self.registryValue("ddg", channel) > 0:
|
||||||
ddg = irc.getCallback("ddg")
|
ddg = irc.getCallback("ddg")
|
||||||
|
if not ddg:
|
||||||
|
log.error("IMDb: Error: DDG search enabled but plugin not loaded.")
|
||||||
if not google and not ddg:
|
if not google and not ddg:
|
||||||
|
log.error("IMDb: Google and DDG plugins not loaded.")
|
||||||
return
|
return
|
||||||
query = "site:www.imdb.com/title/ %s" % text
|
query = "site:www.imdb.com/title/ %s" % text
|
||||||
pattern = re.compile(r"https?://www.imdb.com/title/tt\d+/$")
|
pattern = re.compile(r"https?://www.imdb.com/title/tt\d+/$")
|
||||||
@ -84,6 +89,7 @@ class IMDb(callbacks.Plugin):
|
|||||||
for r in results:
|
for r in results:
|
||||||
match = re.search(pattern, r["url"])
|
match = re.search(pattern, r["url"])
|
||||||
if match:
|
if match:
|
||||||
|
log.debug("IMDb: found link using Google search")
|
||||||
break
|
break
|
||||||
elif ddg and self.registryValue("ddg", channel) == i:
|
elif ddg and self.registryValue("ddg", channel) == i:
|
||||||
results = ddg.search_core(
|
results = ddg.search_core(
|
||||||
@ -92,6 +98,7 @@ class IMDb(callbacks.Plugin):
|
|||||||
for r in results:
|
for r in results:
|
||||||
match = re.search(pattern, r[2])
|
match = re.search(pattern, r[2])
|
||||||
if match:
|
if match:
|
||||||
|
log.debug("IMDb: found link using DDG search")
|
||||||
break
|
break
|
||||||
if match:
|
if match:
|
||||||
return match.group(0)
|
return match.group(0)
|
||||||
@ -104,7 +111,7 @@ class IMDb(callbacks.Plugin):
|
|||||||
"""
|
"""
|
||||||
url = response = result = None
|
url = response = result = None
|
||||||
if not self.registryValue("omdbAPI"):
|
if not self.registryValue("omdbAPI"):
|
||||||
irc.error("Error: You must set an API key to use this plugin.")
|
irc.error("Error: You must set an OMDB API key to use this plugin.")
|
||||||
return
|
return
|
||||||
id = re.match(r"tt\d+", query.strip())
|
id = re.match(r"tt\d+", query.strip())
|
||||||
if id:
|
if id:
|
||||||
@ -134,7 +141,7 @@ class IMDb(callbacks.Plugin):
|
|||||||
log.debug("IMDb: requesting %s" % url)
|
log.debug("IMDb: requesting %s" % url)
|
||||||
request = utils.web.getUrl(url).decode()
|
request = utils.web.getUrl(url).decode()
|
||||||
response = json.loads(request)
|
response = json.loads(request)
|
||||||
if response["Response"] != "False":
|
if response["Response"] != "False" and not response.get("Error"):
|
||||||
imdb_template = lowercase_template(
|
imdb_template = lowercase_template(
|
||||||
self.registryValue("template", msg.channel)
|
self.registryValue("template", msg.channel)
|
||||||
)
|
)
|
||||||
@ -147,6 +154,8 @@ class IMDb(callbacks.Plugin):
|
|||||||
rating.get("Value").split("/")[0]
|
rating.get("Value").split("/")[0]
|
||||||
)
|
)
|
||||||
result = imdb_template.safe_substitute(response)
|
result = imdb_template.safe_substitute(response)
|
||||||
|
elif response.get("Error"):
|
||||||
|
log.debug("IMDb: OMDB API: %s" % response["Error"])
|
||||||
if result:
|
if result:
|
||||||
irc.reply(result, prefixNick=False)
|
irc.reply(result, prefixNick=False)
|
||||||
else:
|
else:
|
||||||
|
@ -57,9 +57,14 @@ class Lyrics(callbacks.Plugin):
|
|||||||
google = ddg = title = None
|
google = ddg = title = None
|
||||||
if self.registryValue("google", channel) > 0:
|
if self.registryValue("google", channel) > 0:
|
||||||
google = irc.getCallback("google")
|
google = irc.getCallback("google")
|
||||||
|
if not google:
|
||||||
|
log.error("Lyrics: Error: Google search enabled but plugin not loaded.")
|
||||||
if self.registryValue("ddg", channel) > 0:
|
if self.registryValue("ddg", channel) > 0:
|
||||||
ddg = irc.getCallback("ddg")
|
ddg = irc.getCallback("ddg")
|
||||||
|
if not ddg:
|
||||||
|
log.error("Lyrics: Error: DDG search enabled but plugin not loaded.")
|
||||||
if not google and not ddg:
|
if not google and not ddg:
|
||||||
|
log.error("Lyrics: Google and DDG plugins not loaded.")
|
||||||
return
|
return
|
||||||
query = "site:lyrics.fandom.com/wiki/ %s" % text
|
query = "site:lyrics.fandom.com/wiki/ %s" % text
|
||||||
pattern = re.compile(r"https?://lyrics.fandom.com/wiki/.*")
|
pattern = re.compile(r"https?://lyrics.fandom.com/wiki/.*")
|
||||||
@ -70,6 +75,7 @@ class Lyrics(callbacks.Plugin):
|
|||||||
match = re.search(pattern, r["url"])
|
match = re.search(pattern, r["url"])
|
||||||
if match:
|
if match:
|
||||||
title = r["title"].replace(":", " - ").split("|")[0]
|
title = r["title"].replace(":", " - ").split("|")[0]
|
||||||
|
log.debug("Lyrics: found link using Google search")
|
||||||
break
|
break
|
||||||
elif self.registryValue("ddg", channel) == i:
|
elif self.registryValue("ddg", channel) == i:
|
||||||
results = ddg.search_core(
|
results = ddg.search_core(
|
||||||
@ -79,6 +85,7 @@ class Lyrics(callbacks.Plugin):
|
|||||||
match = re.search(pattern, r[2])
|
match = re.search(pattern, r[2])
|
||||||
if match:
|
if match:
|
||||||
title = r[0].replace(":", " - ").split("|")[0]
|
title = r[0].replace(":", " - ").split("|")[0]
|
||||||
|
log.debug("Lyrics: found link using DDG")
|
||||||
break
|
break
|
||||||
if match and title:
|
if match and title:
|
||||||
return title, match.group(0)
|
return title, match.group(0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user