diff --git a/IMDb/config.py b/IMDb/config.py
index 812de0d..33efdb2 100644
--- a/IMDb/config.py
+++ b/IMDb/config.py
@@ -59,4 +59,7 @@ conf.registerChannelValue(IMDb, 'noResultsMessage',
conf.registerGlobalValue(IMDb, 'omdbAPI',
registry.String('', _("""OMDB API Key""")))
+conf.registerChannelValue(IMDb, 'googleSearch',
+ registry.Boolean(True, _("""Use google to perform searches for better results.""")))
+
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
diff --git a/IMDb/plugin.py b/IMDb/plugin.py
index 3bd1614..96f059e 100644
--- a/IMDb/plugin.py
+++ b/IMDb/plugin.py
@@ -72,16 +72,18 @@ class IMDb(callbacks.Plugin):
"""
Queries the OMDB api about an IMDb title.
"""
+ channel = msg.channel
+ url = None
+ result = None
apikey = self.registryValue('omdbAPI')
- url = self.dosearch(query)
+ if self.registryValue("googleSearch", channel):
+ url = self.dosearch(query)
if url and 'imdb.com/title/' in url:
imdb_id = url.split("/title/")[1].rstrip("/")
omdb_url = "http://www.omdbapi.com/?i=%s&plot=short&r=json&apikey=%s" % (imdb_id, apikey)
log.debug("IMDb: requesting %s" % omdb_url)
else:
omdb_url = "http://www.omdbapi.com/?t=%s&plot=short&r=json&apikey=%s" % (query, apikey)
- channel = msg.channel
- result = None
try:
request = requests.get(omdb_url, timeout=10)
if request.status_code == requests.codes.ok:
diff --git a/Lyrics/README.md b/Lyrics/README.md
index bb646b3..60a9651 100644
--- a/Lyrics/README.md
+++ b/Lyrics/README.md
@@ -1,4 +1,4 @@
-Limnoria plugin to return song lyrics from http://lyrics.wikia.com/. Search powered by Google.
+Limnoria plugin to return song lyrics from http://lyrics.wikia.com/
load plugindownloader
diff --git a/Lyrics/config.py b/Lyrics/config.py
index b21222a..25af774 100644
--- a/Lyrics/config.py
+++ b/Lyrics/config.py
@@ -46,6 +46,7 @@ def configure(advanced):
from supybot.questions import expect, anything, something, yn
conf.registerPlugin('Lyrics', True)
-
Lyrics = conf.registerPlugin('Lyrics')
+conf.registerChannelValue(Lyrics, 'googleSearch',
+ registry.Boolean(True, _("""Use google to perform searches for better results.""")))
diff --git a/Lyrics/plugin.py b/Lyrics/plugin.py
index 531a1e2..368140b 100644
--- a/Lyrics/plugin.py
+++ b/Lyrics/plugin.py
@@ -71,31 +71,61 @@ class Lyrics(callbacks.Plugin):
pass
return title, url
- def getlyrics(self, url):
- try:
- log.debug("Lyrics: requesting {0}".format(url))
- lyrics = pylyrics3.get_lyrics_from_url(url)
- lyrics = re.sub('(?
- Get song lyrics from Lyrics Wiki. Search powered by Google.
+ """
+ Get song lyrics from Lyrics Wiki.
"""
- title, url = self.dosearch(lyric)
- if url and title and 'lyrics.fandom.com' in utils.web.getDomain(url):
+ channel = msg.channel
+ title = None
+ url = None
+ if self.registryValue("googleSearch", channel):
+ title, url = self.dosearch(lyric)
+ if url and title and 'lyrics.fandom.com/wiki/' in url:
try:
lyrics = self.getlyrics(url)
- irc.reply(title, prefixNick=False)
- irc.reply(lyrics, prefixNick=False)
+ if lyrics:
+ irc.reply(title, prefixNick=False)
+ irc.reply(lyrics, prefixNick=False)
+ else:
+ irc.reply("Unable to retrieve lyrics from {0}".format(url))
+ return
except Exception:
irc.reply("Unable to retrieve lyrics from {0}".format(url))
+ return
else:
- irc.reply("No results found for {0}".format(lyric))
- return
+ if ',' in lyric:
+ try:
+ lyrics = self.getlyrics(lyric)
+ if lyrics:
+ irc.reply(lyrics, prefixNick=False)
+ else:
+ irc.reply("Unable to retrieve lyrics for {0}".format(lyric))
+ return
+ except Exception:
+ irc.reply("Unable to retrieve lyrics for {0}".format(lyric))
+ return
+ else:
+ irc.reply("Searches must be formatted as , ")
+ return
lyric = wrap(lyric, ['text'])
Class = Lyrics