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