mirror of
https://github.com/oddluck/limnoria-plugins.git
synced 2025-04-26 04:51:09 -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',
|
conf.registerGlobalValue(IMDb, 'omdbAPI',
|
||||||
registry.String('', _("""OMDB API Key""")))
|
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:
|
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||||
|
@ -72,7 +72,11 @@ class IMDb(callbacks.Plugin):
|
|||||||
"""<title>
|
"""<title>
|
||||||
Queries the OMDB api about an IMDb title.
|
Queries the OMDB api about an IMDb title.
|
||||||
"""
|
"""
|
||||||
|
channel = msg.channel
|
||||||
|
url = None
|
||||||
|
result = None
|
||||||
apikey = self.registryValue('omdbAPI')
|
apikey = self.registryValue('omdbAPI')
|
||||||
|
if self.registryValue("googleSearch", channel):
|
||||||
url = self.dosearch(query)
|
url = self.dosearch(query)
|
||||||
if url and 'imdb.com/title/' in url:
|
if url and 'imdb.com/title/' in url:
|
||||||
imdb_id = url.split("/title/")[1].rstrip("/")
|
imdb_id = url.split("/title/")[1].rstrip("/")
|
||||||
@ -80,8 +84,6 @@ class IMDb(callbacks.Plugin):
|
|||||||
log.debug("IMDb: requesting %s" % omdb_url)
|
log.debug("IMDb: requesting %s" % omdb_url)
|
||||||
else:
|
else:
|
||||||
omdb_url = "http://www.omdbapi.com/?t=%s&plot=short&r=json&apikey=%s" % (query, apikey)
|
omdb_url = "http://www.omdbapi.com/?t=%s&plot=short&r=json&apikey=%s" % (query, apikey)
|
||||||
channel = msg.channel
|
|
||||||
result = None
|
|
||||||
try:
|
try:
|
||||||
request = requests.get(omdb_url, timeout=10)
|
request = requests.get(omdb_url, timeout=10)
|
||||||
if request.status_code == requests.codes.ok:
|
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
|
load plugindownloader
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ def configure(advanced):
|
|||||||
from supybot.questions import expect, anything, something, yn
|
from supybot.questions import expect, anything, something, yn
|
||||||
conf.registerPlugin('Lyrics', True)
|
conf.registerPlugin('Lyrics', True)
|
||||||
|
|
||||||
|
|
||||||
Lyrics = conf.registerPlugin('Lyrics')
|
Lyrics = conf.registerPlugin('Lyrics')
|
||||||
|
|
||||||
|
conf.registerChannelValue(Lyrics, 'googleSearch',
|
||||||
|
registry.Boolean(True, _("""Use google to perform searches for better results.""")))
|
||||||
|
@ -71,30 +71,60 @@ class Lyrics(callbacks.Plugin):
|
|||||||
pass
|
pass
|
||||||
return title, url
|
return title, url
|
||||||
|
|
||||||
def getlyrics(self, url):
|
def getlyrics(self, query):
|
||||||
|
lyrics = None
|
||||||
|
if 'lyrics.fandom.com/wiki/' in query:
|
||||||
try:
|
try:
|
||||||
log.debug("Lyrics: requesting {0}".format(url))
|
log.debug("Lyrics: requesting {0}".format(query))
|
||||||
lyrics = pylyrics3.get_lyrics_from_url(url)
|
lyrics = pylyrics3.get_lyrics_from_url(query)
|
||||||
lyrics = re.sub('(?<!\.|\!|\?)\s\\n', '.', lyrics).replace(" \n", "")
|
lyrics = re.sub('(?<!\.|\!|\?)\s\\n', '.', lyrics).replace(" \n", "")
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
pass
|
||||||
else:
|
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
|
return lyrics
|
||||||
|
|
||||||
def lyric(self, irc, msg, args, lyric):
|
def lyric(self, irc, msg, args, lyric):
|
||||||
"""<text>
|
"""<query>
|
||||||
Get song lyrics from Lyrics Wiki. Search powered by Google.
|
Get song lyrics from Lyrics Wiki.
|
||||||
"""
|
"""
|
||||||
|
channel = msg.channel
|
||||||
|
title = None
|
||||||
|
url = None
|
||||||
|
if self.registryValue("googleSearch", channel):
|
||||||
title, url = self.dosearch(lyric)
|
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:
|
try:
|
||||||
lyrics = self.getlyrics(url)
|
lyrics = self.getlyrics(url)
|
||||||
|
if lyrics:
|
||||||
irc.reply(title, prefixNick=False)
|
irc.reply(title, prefixNick=False)
|
||||||
irc.reply(lyrics, prefixNick=False)
|
irc.reply(lyrics, prefixNick=False)
|
||||||
|
else:
|
||||||
|
irc.reply("Unable to retrieve lyrics from {0}".format(url))
|
||||||
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
irc.reply("Unable to retrieve lyrics from {0}".format(url))
|
irc.reply("Unable to retrieve lyrics from {0}".format(url))
|
||||||
|
return
|
||||||
else:
|
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
|
return
|
||||||
lyric = wrap(lyric, ['text'])
|
lyric = wrap(lyric, ['text'])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user