bitbot-3.11-fork/modules/imdb.py

33 lines
1 KiB
Python
Raw Normal View History

#--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
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"
class Module(ModuleManager.BaseModule):
2016-03-29 11:56:58 +00:00
_name = "IMDb"
@utils.hook("received.command.imdb", min_args=1)
2016-03-29 11:56:58 +00:00
def imdb(self, event):
"""
:help: Search for a given title on IMDb
:usage: <movie/tv title>
"""
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:
if "Title" in page.data:
2016-03-29 11:56:58 +00:00
event["stdout"].write("%s, %s (%s) %s (%s/10.0) %s" % (
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:
raise utils.EventsResultsError()