YouTube/IMDb: channel configs, api fallback
This commit is contained in:
parent
d09455ec86
commit
0b37f50c30
|
@ -1,4 +1,4 @@
|
|||
Information about IMDb titles from the OMDB API. Search powered by Google.
|
||||
Information about IMDb titles from the OMDB API.
|
||||
|
||||
Forked from https://github.com/butterscotchstallion/limnoria-plugins/tree/master/IMDB
|
||||
|
||||
|
|
|
@ -50,10 +50,10 @@ def configure(advanced):
|
|||
|
||||
IMDb = conf.registerPlugin('IMDb')
|
||||
|
||||
conf.registerGlobalValue(IMDb, 'template',
|
||||
conf.registerChannelValue(IMDb, 'template',
|
||||
registry.String("\x02\x031,8 IMDb \x0F\x02 :: $title ($year, $country, [$rated], $genre, $runtime) :: IMDb: $imdbRating | MC: $metascore | RT: $tomatoMeter :: http://imdb.com/title/$imdbID :: $plot :: Director: $director :: Cast: $actors :: Writer: $writer", _("""Template for the output of a search query.""")))
|
||||
|
||||
conf.registerGlobalValue(IMDb, 'noResultsMessage',
|
||||
conf.registerChannelValue(IMDb, 'noResultsMessage',
|
||||
registry.String("No results for that query.", _("""This message is sent when there are no results""")))
|
||||
|
||||
conf.registerGlobalValue(IMDb, 'omdbAPI',
|
||||
|
|
|
@ -74,32 +74,26 @@ class IMDb(callbacks.Plugin):
|
|||
"""
|
||||
apikey = self.registryValue('omdbAPI')
|
||||
url = self.dosearch(query)
|
||||
if url and 'imdb.com' in utils.web.getDomain(url):
|
||||
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&tomatoes=true&apikey=%s" % (imdb_id, apikey)
|
||||
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:
|
||||
irc.reply("No results found for {0}".format(query))
|
||||
return
|
||||
|
||||
channel = msg.args[0]
|
||||
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:
|
||||
response = request.json()
|
||||
|
||||
not_found = "Error" in response
|
||||
unknown_error = response["Response"] != "True"
|
||||
|
||||
if not_found or unknown_error:
|
||||
log.debug("IMDb: OMDB error for %s" % (omdb_url))
|
||||
else:
|
||||
meta = None
|
||||
tomato = None
|
||||
imdb_template = self.registryValue("template")
|
||||
imdb_template = self.registryValue("template", channel)
|
||||
imdb_template = imdb_template.replace("$title", response["Title"])
|
||||
imdb_template = imdb_template.replace("$year", response["Year"])
|
||||
imdb_template = imdb_template.replace("$country", response["Country"])
|
||||
|
@ -133,11 +127,9 @@ class IMDb(callbacks.Plugin):
|
|||
imdb_template = imdb_template.replace("$production",response["Production"])
|
||||
imdb_template = imdb_template.replace("$website",response["Website"])
|
||||
imdb_template = imdb_template.replace("$poster",response["Poster"])
|
||||
|
||||
result = imdb_template
|
||||
else:
|
||||
log.error("IMDb OMDB API %s - %s" % (request.status_code, request.text))
|
||||
|
||||
except requests.exceptions.Timeout as e:
|
||||
log.error("IMDb Timeout: %s" % (str(e)))
|
||||
except requests.exceptions.ConnectionError as e:
|
||||
|
@ -148,11 +140,9 @@ class IMDb(callbacks.Plugin):
|
|||
if result is not None:
|
||||
irc.reply(result, prefixNick=False)
|
||||
else:
|
||||
irc.error(self.registryValue("noResultsMessage"))
|
||||
|
||||
irc.error(self.registryValue("noResultsMessage", channel))
|
||||
imdb = wrap(imdb, ['text'])
|
||||
|
||||
Class = IMDb
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||
|
|
|
@ -54,10 +54,10 @@ YouTube = conf.registerPlugin('YouTube')
|
|||
conf.registerGlobalValue(YouTube, 'developerKey',
|
||||
registry.String("", _("""Google API key. Required.""")))
|
||||
|
||||
conf.registerGlobalValue(YouTube, 'sortOrder',
|
||||
conf.registerChannelValue(YouTube, 'sortOrder',
|
||||
registry.String("relevance", _("""Method used to order API responses: date, rating, relevance, title, viewCount""")))
|
||||
|
||||
conf.registerGlobalValue(YouTube, 'safeSearch',
|
||||
conf.registerChannelValue(YouTube, 'safeSearch',
|
||||
registry.String("none", _("""Safe search filtering: none, moderate, strict""")))
|
||||
|
||||
conf.registerChannelValue(YouTube, 'logo',
|
||||
|
|
|
@ -54,8 +54,8 @@ class YouTube(callbacks.Plugin):
|
|||
|
||||
def dosearch(self, query):
|
||||
apikey = self.registryValue('developerKey')
|
||||
safe_search = self.registryValue("safeSearch")
|
||||
sort_order = self.registryValue("sortOrder")
|
||||
safe_search = self.registryValue("safeSearch", dynamic.channel)
|
||||
sort_order = self.registryValue("sortOrder", dynamic.channel)
|
||||
video_id = None
|
||||
opts = {"q": query,
|
||||
"part": "snippet",
|
||||
|
@ -189,7 +189,7 @@ class YouTube(callbacks.Plugin):
|
|||
else:
|
||||
log.error("YouTube: YouTube API HTTP %s: %s" % (request.status_code, request.text))
|
||||
if title:
|
||||
use_bold = self.registryValue("useBold", dynamic.channel)
|
||||
use_bold = self.registryValue("useBold", channel)
|
||||
if use_bold:
|
||||
title = ircutils.bold(title)
|
||||
irc.reply(title, prefixNick=False)
|
||||
|
|
Loading…
Reference in New Issue