IMDb/Lyrics: add googleSearch config

This commit is contained in:
oddluck 2020-02-27 21:12:20 +00:00
parent 0b37f50c30
commit eed95681b1
5 changed files with 57 additions and 21 deletions

View File

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

View File

@ -72,7 +72,11 @@ class IMDb(callbacks.Plugin):
"""<title>
Queries the OMDB api about an IMDb title.
"""
channel = msg.channel
url = None
result = None
apikey = self.registryValue('omdbAPI')
if self.registryValue("googleSearch", channel):
url = self.dosearch(query)
if url and 'imdb.com/title/' in url:
imdb_id = url.split("/title/")[1].rstrip("/")
@ -80,8 +84,6 @@ class IMDb(callbacks.Plugin):
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:

View File

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

View File

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

View File

@ -71,30 +71,60 @@ class Lyrics(callbacks.Plugin):
pass
return title, url
def getlyrics(self, url):
def getlyrics(self, query):
lyrics = None
if 'lyrics.fandom.com/wiki/' in query:
try:
log.debug("Lyrics: requesting {0}".format(url))
lyrics = pylyrics3.get_lyrics_from_url(url)
log.debug("Lyrics: requesting {0}".format(query))
lyrics = pylyrics3.get_lyrics_from_url(query)
lyrics = re.sub('(?<!\.|\!|\?)\s\\n', '.', lyrics).replace(" \n", "")
except Exception:
return
pass
else:
try:
log.debug("Lyrics: requesting {0}".format(query))
query = query.split(',', 1)
lyrics = pylyrics3.get_song_lyrics(query[0].strip(), query[1].strip())
lyrics = re.sub('(?<!\.|\!|\?)\s\\n', '.', lyrics).replace(" \n", "")
except Exception:
pass
return lyrics
def lyric(self, irc, msg, args, lyric):
"""<text>
Get song lyrics from Lyrics Wiki. Search powered by Google.
"""<query>
Get song lyrics from Lyrics Wiki.
"""
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' in utils.web.getDomain(url):
if url and title and 'lyrics.fandom.com/wiki/' in url:
try:
lyrics = self.getlyrics(url)
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))
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 <artist>, <song title>")
return
lyric = wrap(lyric, ['text'])