# IMDb query v1.17 (updated by username@egghelp.org forums)
# Copyright (C) 2007-2009 perpleXa
# http://perplexa.ugug.org / #perpleXa on QuakeNet
#
# Redistribution, with or without modification, are permitted provided
# that redistributions retain the above copyright notice, this condition
# and the following disclaimer.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
#
# Usage:
# !movie
package require http 2.7; # TCL 8.5
namespace eval imdb {
variable version 1.17;
# Headers color
variable color1 \00314
# Information color
variable color2 \00303
# flood protection (seconds)
variable antiflood "10";
# character encoding
variable encoding "utf-8";
# user agent
variable agent "Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.8.1) Gecko/2006101023 Firefox/2.0";
# internal
bind pub -|- "!movie" [namespace current]::public;
bind msg -|- "!movie" [namespace current]::private;
variable flood;
namespace export *;
}
proc imdb::public {nick host hand chan argv} {
imdb::main $nick $host $hand $chan $argv
}
proc imdb::private {nick host hand argv} {
imdb::main $nick $host $hand $nick $argv
}
proc imdb::main {nick host hand chan argv} {
variable flood; variable antiflood;
variable color1; variable color2;
if {![info exists flood($chan)]} { set flood($chan) 0; }
if {[unixtime] - $flood($chan) <= $antiflood} { return 0; }
set flood($chan) [unixtime];
set argv [string trim $argv];
if {$argv == ""} {
puthelp "NOTICE $nick :\002${color1}Syntax\002: ${color2}$::lastbind \003";
return 0;
}
set id [id $argv];
if {$id == ""} {
chanmsg $chan "${color1}Movie not found: ${color2}$argv";
return 0;
}
set info [getinfo $id];
if {![llength $info]} {
chanmsg $chan "${color1}Couldn't get information for movie id ${color2}$id${color1}.\003";
return 0;
}
for {set i 0} {$i < [llength $info]} {incr i} {
set info [lreplace $info $i $i [decode [lindex $info $i]]];
}
set name [lindex $info 0]; set year [lindex $info 1];
set desc [lindex $info 2]; set dir [lindex $info 3];
set rel [lindex $info 4]; set storyline [lindex $info 5];
set keywords [lindex $info 6]; set country [lindex $info 7];
set genre [lindex $info 8]; set language [lindex $info 9];
set aka [lindex $info 10]; set runtime [lindex $info 11];
set rating [lindex $info 12]; set votes [lindex $info 13];
set top5000 [lindex $info 14]; set stars [lindex $info 15];
set alsoliked [lindex $info 16]; set budget [lindex $info 17];
if {$name == ""} {
chanmsg $chan "${color1}Couldn't get information for movie id ${color2}$id${color1}.\003";
return 0;
}
if {$rating == "-"} {
set rating_ 0
} else {
set rating_ $rating
}
chanmsg $chan "\002${color2}$name\002${color1}. Also known as: \002$color2$aka\002 ${color1}\($year\) \002Rating:\002 [bar $rating_] $color2$rating${color1}/10\003";
chanmsg $chan "${color2}$desc\003";
chanmsg $chan "\002${color1}Top 5000\002 ${color2}$top5000\003";
chanmsg $chan "\002${color1}Stars\002: ${color2}$stars \002${color1}Director\002: ${color2}$dir ${color1}\002Release date\002: ${color2}$rel\003";
chanmsg $chan "\002${color1}Storyline\002: ${color2}$storyline\003 ...";
chanmsg $chan "\002${color1}Plot keywords\002: ${color2}$keywords ${color1}\002Genre\002: ${color2}$genre\003";
chanmsg $chan "\002${color1}Language\002: ${color2}$language ${color1}\002Country\002: ${color2}$country ${color1}\002Runtime\002: ${color2}$runtime ${color1}\002Budget\002: ${color2}$budget ${color1}\002Link\002: \00312\037http://imdb.com/title/$id\037\003";
chanmsg $chan "\002${color1}People who liked this also liked\002: ${color2}$alsoliked\003";
}
proc imdb::bar {float} {
set stars [format "%1.0f" $float];
return "\00312\[\00307[string repeat "*" $stars]\00314[string repeat "-" [expr 10-$stars]]\00312\]\003";
}
proc imdb::chanmsg {chan text} {
if {[validchan $chan]} {
if {[string first "c" [lindex [split [getchanmode $chan]] 0]] >= 0} {
regsub -all {(?:\002|\003([0-9]{1,2}(,[0-9]{1,2})?)?|\017|\026|\037)} $text "" text;
}
}
putquick "PRIVMSG $chan :$text";
}
proc imdb::id {movie} {
variable agent;
http::config -useragent $agent;
if {[catch {http::geturl "http://www.imdb.com/find?q=[urlencode $movie]&s=all" -timeout 20000} token]} {
return;
}
set data [http::data $token];
set code [http::ncode $token];
set meta [http::meta $token];
http::cleanup $token;
if {$code == 200} {
set id "";
regexp -nocase -- {
(.*?).*?