This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/imdb.py

35 lines
1 KiB
Python
Raw Normal View History

2011-11-20 10:23:31 +01:00
# IMDb lookup plugin by Ghetto Wizard (2011).
from util import hook, http
import re
id_re = re.compile("tt\d+")
2011-11-20 10:23:31 +01:00
@hook.command
def imdb(inp):
2012-05-16 05:07:27 +02:00
"imdb <movie> -- Gets information about <movie> from IMDb."
2011-11-20 10:23:31 +01:00
strip = inp.strip()
if id_re.match(strip):
content = http.get_json("http://www.omdbapi.com/", i=strip)
else:
content = http.get_json("http://www.omdbapi.com/", t=strip)
2011-11-20 10:23:31 +01:00
if content['Error'] == 'Movie not found!':
return 'Movie not found!'
2011-11-20 10:23:31 +01:00
elif content['Response'] == 'True':
2012-05-12 16:10:05 +02:00
content['URL'] = 'http://www.imdb.com/title/%(imdbID)s' % content
2011-11-20 10:23:31 +01:00
out = '\x02%(Title)s\x02 (%(Year)s) (%(Genre)s): %(Plot)s'
if content['Runtime'] != 'N/A':
out += ' \x02%(Runtime)s\x02.'
2012-05-12 16:10:05 +02:00
if content['imdbRating'] != 'N/A' and content['imdbVotes'] != 'N/A':
out += ' \x02%(imdbRating)s/10\x02 with \x02%(imdbVotes)s\x02' \
' votes.'
2011-11-20 10:23:31 +01:00
out += ' %(URL)s'
return out % content
else:
return 'Unknown error.'