2018-07-02 10:09:02 +00:00
|
|
|
#--require-config omdbapi-api-key
|
|
|
|
|
2016-03-29 11:56:58 +00:00
|
|
|
import json
|
2018-09-24 14:13:27 +00:00
|
|
|
from src import Utils
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
URL_OMDB = "http://www.omdbapi.com/"
|
|
|
|
URL_IMDBTITLE = "http://imdb.com/title/%s"
|
|
|
|
|
|
|
|
class Module(object):
|
|
|
|
_name = "IMDb"
|
2018-09-02 18:54:45 +00:00
|
|
|
def __init__(self, bot, events, exports):
|
2018-07-02 10:09:02 +00:00
|
|
|
self.bot = bot
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.command.imdb", min_args=1, usage="<movie/tv title>")
|
2016-03-29 11:56:58 +00:00
|
|
|
def imdb(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
|
|
|
Search for a given title on IMDb
|
|
|
|
"""
|
2018-07-02 10:09:02 +00:00
|
|
|
page = Utils.get_url(URL_OMDB, get_params={
|
|
|
|
"t": event["args"],
|
|
|
|
"apikey": self.bot.config["omdbapi-api-key"]},
|
2016-03-29 11:56:58 +00:00
|
|
|
json=True)
|
|
|
|
if page:
|
|
|
|
if "Title" in page:
|
|
|
|
event["stdout"].write("%s, %s (%s) %s (%s/10.0) %s" % (
|
|
|
|
page["Title"], page["Year"], page["Runtime"],
|
|
|
|
page["Plot"], page["imdbRating"],
|
|
|
|
URL_IMDBTITLE % page["imdbID"]))
|
|
|
|
else:
|
|
|
|
event["stderr"].write("Title not found")
|
|
|
|
else:
|
|
|
|
event["stderr"].write("Failed to load results")
|