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

58 lines
2 KiB
Python
Raw Normal View History

2013-06-27 12:34:06 +02:00
# IMDb lookup plugin by Ghetto Wizard (2011) and blha303 (2013)
2011-11-20 10:23:31 +01:00
2013-07-01 19:14:54 +02:00
from util import hook, http, text
import re
id_re = re.compile("tt\d+")
2013-07-01 19:14:54 +02:00
imdb_re = (r'(.*:)//(imdb.com|www.imdb.com)(:[0-9]+)?(.*)', re.I)
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
2012-10-18 13:06:34 +02:00
if content.get('Error', None) == '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.'
2013-06-27 12:34:06 +02:00
@hook.regex(*imdb_re)
def imdb_url(match):
id = match.group(4).split('/')[-1]
if id == "":
2013-07-01 19:14:54 +02:00
id = match.group(4).split('/')[-2]
2013-06-27 12:34:06 +02:00
content = http.get_json("http://www.omdbapi.com/", i=id)
if content.get('Error', None) == 'Movie not found!':
return 'Movie not found!'
elif content['Response'] == 'True':
content['URL'] = 'http://www.imdb.com/title/%(imdbID)s' % content
2013-07-01 19:14:54 +02:00
content['Plot'] = text.truncate_str(content['Plot'], 50)
2013-06-27 12:34:06 +02:00
out = '\x02%(Title)s\x02 (%(Year)s) (%(Genre)s): %(Plot)s'
if content['Runtime'] != 'N/A':
out += ' \x02%(Runtime)s\x02.'
if content['imdbRating'] != 'N/A' and content['imdbVotes'] != 'N/A':
out += ' \x02%(imdbRating)s/10\x02 with \x02%(imdbVotes)s\x02' \
' votes.'
return out % content
else:
return 'Unknown error.'