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?

  • Thanks m00nie this script works awesome. I haven’t been able to find a working imdb due to imdb keeps changing things. I loaded your script up and it works perfect. Thank you

    I know this is off topic but I was wondering if you ever thought of writing an eggdrop script for urban dictionary? I have one but it does not work and apparently no one is updating it. Just a thought. Thank you again for all your scripts.

  • Hi m00nie, im not seeing any response from the triggers and im getting the below error in my log. Any idea?

    Tcl error [m00nie::movie::search]: wrong # args: should be “set varName ?newValue?”

  • I sorted the above, turned out when I copied it off the page it had some weird line issues.
    So i downloaded it and its working properly.

    One of the problems with the API is that the “year” of the movie is seperate data from the title.
    So for example you cant search “The Lion King 2019” or “Aladdin 2019” or other remakes of movies, or movies with similar titles from different years.

Leave a Reply

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