movie search script for eggdrop bot using api

Recently another script I used to search for film information got broken. After a quick look around I found the nice people over at OMDb (http://www.omdbapi.com/) who have a good API to expose things like IMDB rating and other information regarding movies. Its a simple script (as usual) but hopefully as useful as more traditional IMDB script with a bit less chance of being broken so often. You can grab the script [here]

Example screenshot of the script in action:

Code looks something like this:

#########################################################################################
# Name          m00nie::movie
# Description   Uses omdbapi to grab info about a film title then spam it into the chan
#
# Version       1.0 - Initial release
# Website       https://www.m00nie.com
# Notes         Create ypu own API keys here: http://www.omdbapi.com
#       requires .chanset #chan +movie
#########################################################################################
namespace eval m00nie {
namespace eval movie {
package require json
bind pub - !movie m00nie::movie::search
# Uncomment bind below to also use "more traditional" !imdb search
#bind pub - !imdb m00nie::movie::search
variable version "1.0"
setudef flag movie
# Setup your own app and keys at the URL above
variable key "---GET-YOUR-OWN---"

proc search {nick uhost hand chan text} {
if {[channel get $chan movie]} {
putlog "m00nie::movie::search is running"
regsub -all {\s+} $text "%20" text
set response [getinfo "http://www.omdbapi.com/?t=$text&apikey=$m00nie::movie::key"]
#set response [dict get [json::json2dict $response]]
foreach var { Title Year Rated Released Runtime Genre Actors Plot Metascore imdbRating imdbID } {
set $var [dict get $response $var]
}
set imdburl "http://www.imdb.com/title/$imdbID/"
puthelp "PRIVMSG $chan :\002$Title ($Year)\002 $Rated \002|\002 $Runtime \002|\002 $Genre \002|\002 $Released"
puthelp "PRIVMSG $chan :\002Cast:\002 $Actors"
puthelp "PRIVMSG $chan :\002Plot:\002 $Plot"
puthelp "PRIVMSG $chan :\002Metascore:\002 $Metascore, \002IMDB Rating:\002 $imdbRating"
puthelp "PRIVMSG $chan :$imdburl"
}
}

proc getinfo { url } {
for { set i 1 } { $i <= 5 } { incr i } { set rawpage [::http::data [::http::geturl "$url" -timeout 5000]] if {[string length rawpage] > 0} { break }
}
putlog "m00nie::movie::getinfo Rawpage length is: [string length $rawpage]"
if {[string length $rawpage] == 0} { error "omdbapi returned ZERO no data :( or we couldnt connect properly" }
set ids [dict get [json::json2dict $rawpage]]
putlog "m00nie::movie::getinfo IDS are $ids"
return $ids

}
}
}
putlog "m00nie::movie $m00nie::movie::version loaded" 

As ever any comment, questions or suggestions are more than welcome

m00nie

Comments

  • When attempting to use this script, as fantastic as it looks, I keep getting bitched at for not having json on my centos set up. I’ve installed the available json package. Any tips?

Leave a Reply

Your email address will not be published. Required fields are marked *