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/disabled_stuff/imdb.py

60 lines
2.0 KiB
Python
Raw Permalink 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
import re
2014-02-14 04:36:57 +01:00
from util import hook, http, text
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):
2013-09-04 12:30:04 +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':
2013-09-05 03:46:49 +02:00
content['URL'] = 'http://www.imdb.com/title/{}'.format(content['imdbID'])
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):
2014-02-14 05:03:08 +01:00
imdb_id = match.group(4).split('/')[-1]
if imdb_id == "":
imdb_id = match.group(4).split('/')[-2]
content = http.get_json("http://www.omdbapi.com/", i=imdb_id)
2013-06-27 12:34:06 +02:00
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.'