Fixed the 'movie not found' message, you can now look up IMDB movie ids

This commit is contained in:
Luke Rogers 2012-10-18 11:15:51 +13:00
parent 274c7b7b50
commit 22b15b5e5f

View file

@ -1,16 +1,24 @@
# IMDb lookup plugin by Ghetto Wizard (2011). # IMDb lookup plugin by Ghetto Wizard (2011).
from util import hook, http from util import hook, http
import re
id_re = re.compile("tt\d+")
@hook.command @hook.command
def imdb(inp): def imdb(inp):
"imdb <movie> -- Gets information about <movie> from IMDb." "imdb <movie> -- Gets information about <movie> from IMDb."
content = http.get_json("http://www.omdbapi.com/", t=inp) strip = inp.strip()
if content['Response'] == 'Movie Not Found': if id_re.match(strip):
return 'movie not found' content = http.get_json("http://www.omdbapi.com/", i=strip)
else:
content = http.get_json("http://www.omdbapi.com/", t=strip)
if content['Error'] == 'Movie not found!':
return 'Movie not found!'
elif content['Response'] == 'True': elif content['Response'] == 'True':
content['URL'] = 'http://www.imdb.com/title/%(imdbID)s' % content content['URL'] = 'http://www.imdb.com/title/%(imdbID)s' % content
@ -23,4 +31,4 @@ def imdb(inp):
out += ' %(URL)s' out += ' %(URL)s'
return out % content return out % content
else: else:
return 'unknown error' return 'Unknown error.'