2019-05-25 20:40:06 +00:00
|
|
|
#--depends-on commands
|
2018-07-02 10:09:02 +00:00
|
|
|
#--require-config omdbapi-api-key
|
|
|
|
|
2016-03-29 11:56:58 +00:00
|
|
|
import json
|
2018-10-03 12:22:37 +00:00
|
|
|
from src import ModuleManager, utils
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
URL_OMDB = "http://www.omdbapi.com/"
|
|
|
|
URL_IMDBTITLE = "http://imdb.com/title/%s"
|
|
|
|
|
2018-09-27 10:46:10 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2016-03-29 11:56:58 +00:00
|
|
|
_name = "IMDb"
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.imdb", min_args=1)
|
2016-03-29 11:56:58 +00:00
|
|
|
def imdb(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Search for a given title on IMDb
|
|
|
|
:usage: <movie/tv title>
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-12-11 22:26:38 +00:00
|
|
|
page = utils.http.request(URL_OMDB, get_params={
|
2018-07-02 10:09:02 +00:00
|
|
|
"t": event["args"],
|
|
|
|
"apikey": self.bot.config["omdbapi-api-key"]},
|
2016-03-29 11:56:58 +00:00
|
|
|
json=True)
|
|
|
|
if page:
|
2018-12-11 22:26:38 +00:00
|
|
|
if "Title" in page.data:
|
2016-03-29 11:56:58 +00:00
|
|
|
event["stdout"].write("%s, %s (%s) %s (%s/10.0) %s" % (
|
2018-12-11 22:26:38 +00:00
|
|
|
page.data["Title"], page.data["Year"], page.data["Runtime"],
|
|
|
|
page.data["Plot"], page.data["imdbRating"],
|
|
|
|
URL_IMDBTITLE % page.data["imdbID"]))
|
2016-03-29 11:56:58 +00:00
|
|
|
else:
|
|
|
|
event["stderr"].write("Title not found")
|
|
|
|
else:
|
2018-10-20 19:51:29 +00:00
|
|
|
raise utils.EventsResultsError()
|