mirror of
https://github.com/oddluck/limnoria-plugins.git
synced 2025-04-25 12:31:07 -05:00
IMDb/Lyrics: add googleSearch config
This commit is contained in:
parent
0b37f50c30
commit
eed95681b1
@ -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:
|
||||
|
@ -72,16 +72,18 @@ class IMDb(callbacks.Plugin):
|
||||
"""<title>
|
||||
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:
|
||||
|
@ -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
|
||||
|
||||
|
@ -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.""")))
|
||||
|
@ -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('(?<!\.|\!|\?)\s\\n', '.', lyrics).replace(" \n", "")
|
||||
except Exception:
|
||||
return
|
||||
def getlyrics(self, query):
|
||||
lyrics = None
|
||||
if 'lyrics.fandom.com/wiki/' in query:
|
||||
try:
|
||||
log.debug("Lyrics: requesting {0}".format(query))
|
||||
lyrics = pylyrics3.get_lyrics_from_url(query)
|
||||
lyrics = re.sub('(?<!\.|\!|\?)\s\\n', '.', lyrics).replace(" \n", "")
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
return lyrics
|
||||
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.
|
||||
"""
|
||||
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 <artist>, <song title>")
|
||||
return
|
||||
lyric = wrap(lyric, ['text'])
|
||||
|
||||
Class = Lyrics
|
||||
|
Loading…
x
Reference in New Issue
Block a user