IMDb search for eggdrop

By FordLawnmower on May 28, 2012

This is a tcl script for eggdrop. Not for mIRC!
Loading:

  • Save this code to a file called imdb.tcl
  • Place the file in your eggdrop scripts directory
  • Add this line to eggdrop.conf -->> source scripts/imdb.tcl
  • Rehash or restart your eggdrop
  • (In the console) type .chanset #channelname +imdb "where #channelname is the channel you want the script on in"

The trigger is !imdb.

The trigger can be changed, along with the output. (See the setup portion at the top of the script)

Example output:

Image

##############################################################################################
##  ##     imdb.tcl for eggdrop by Ford_Lawnmower irc.geekshed.net #Script-Help         ##  ##
##############################################################################################
## To use this script you must set channel flag +imdb (ie .chanset #chan +imdb)             ##
##############################################################################################
##############################################################################################
##  ##                             Start Setup.                                         ##  ##
##############################################################################################
## Change imdb_cmdchar to the character you want to use.                                    ##
set imdb_cmdchar "!"
## Change imdb_lang to the 2 digit language code you want to use                            ##
set imdb_lang "en"
proc imdb {nick host hand chan imdbsite imdburl} {
  if {[lsearch -exact [channel info $chan] +imdb] != -1} {
## Change the characters between the "" below to change the logo shown with each result.    ##
    set imdblogo "\002\00301,08IMDb\017"
## Change the format codes between the "" below to change the color/state of the text.      ##
    set imdbtext "\0034"
## Change the format codes between the "" below to change the color/state of the tags.      ##
    set imdbtags "\002"
## Change the format codes between the "" below to change the color/state of the links.     ##
    set imdblinks "\037\002"
## You may adjust how the results are printed by changing line1, line2 and line3            ##
## Valid items are as follows: cast language country genre director writer stars link title ##
## plot rating critic comment shortplot date duration votes title logo graph                ## 
    set line1 "otitle duration genre date language country director writer stars"
    set line2 "shortplot rating graph votes comment critic"
    set line3 "cast plot link"
##############################################################################################
##  ##                           End Setup.                                              ## ##
##############################################################################################   
    if {[catch {set imdbSock [socket -async $imdbsite 80]} sockerr]} {
      putserv "PRIVMSG $chan :$imdbsite $imdburl $sockerr error"
      return 0
      } else {
      puts $imdbSock "GET $imdburl HTTP/1.0"
      puts $imdbSock "Host: $imdbsite"
      puts $imdbSock "User-Agent: Opera 9.6"
      puts $imdbSock ""
      flush $imdbSock
      set imdbtable 0
      set imdbtitle ""
      set imdbcast ""
      set imdblanguage ""
      set imdbcountry ""
      set imdbgenre ""
      set imdbdirector ""
      set imdbwriter ""
      set imdbstars ""
      set imdblink ""
      set imdbtitle ""
      set imdbplot ""
      set imdbrating ""
      set imdbcritic ""
      set imdbcomment ""
      set imdbshortplot ""
      set imdbdate ""
      set imdbduration ""
      set imdbvotes ""
      set imdbgraph ""
      set imdbdurationfound ""
      set imdbtablealt ""
      set imdbotitle ""
      while {![eof $imdbSock]} {
        set imdbvar " [gets $imdbSock] "
        if {[regexp {may refer to:} $imdbvar] || [regexp {HTTP\/1\.0 403} $imdbvar]} {
           putserv "PRIVMSG $chan :\002Nothing found on imdb! Please refine your search and check your spelling."
           close $imdbSock
      return 0
        } elseif {[string match "*<table class=*" $imdbvar]} {
          regexp {"(.*?)"} $imdbvar match imdbtable
        } elseif {[string match "*<h4 class=\"inline\">*</h4>*" $imdbvar]} {
          regexp {>(.*?)<\/h4>} $imdbvar match imdbtable
      } elseif {[string match "*</div>*" $imdbvar]} {
        set imdbtable ""
        } elseif {[string match "*Director:*" $imdbvar]} {
          set imdbtable "Director:"
        } elseif {[string match "*Writers:*" $imdbvar]} {
          set imdbtable "Writers:"
      } elseif {[string match "*<h2>Cast</h2>*" $imdbvar]} {
        set imdbtablealt "Cast:"
        } elseif {[regexp {content="(http:\/\/www.imdb.com\/title\/.*\/)"} $imdbvar match imdblink]} {
          set imdblink [concat "\017${imdbtags}Link:\017" "${imdblinks}${imdblink}\015"]
        } elseif {[regexp {<title>([^<]*)\s-\sIMDb<\/title>} $imdbvar match imdbtitle]} {
          set imdbtitle [concat "\017${imdbtags}Title:\017${imdbtext}" [imdbdehex $imdbtitle]]
      } elseif {[regexp {class="title-extra"\sitemprop="name">([^<]*)} $imdbvar match imdbtitle]} {
          set imdbtitle [concat "\017${imdbtags}Title:\017${imdbtext}" [imdbdehex $imdbtitle]]
        } elseif {[string match "*<h2>Storyline</h2>*" $imdbvar]} {
          set imdbtable "plotfound:"
      } elseif {[regexp {'og:title'\scontent="([^<]*)"} $imdbvar match imdbotitle]} {
        set imdbotitle [concat "\017${imdbtags}Title:\017${imdbtext}" [imdbdehex $imdbotitle]]
      } elseif {$imdbtable == "plotfound:" && [string match "*<p>*" $imdbvar]} {
        set imdbtable "plot:"
        } elseif {$imdbtable == "plot:"} {
          set imdbplot [string map {"Written by" ""} [concat "\017${imdbtags}Plot:\017${imdbtext}" [imdbdehex [imdbstrip $imdbvar]]]]
          set imdbtable ""
        } elseif {[regexp {<span\sclass="rating">(.*?)<span} $imdbvar match imdbrating]} {
          set imdbgraph "\017${imdbtags}\[${imdbtext}[string repeat "*" [imdbround $imdbrating]]\00314"
          set imdbgraph "${imdbgraph}[string repeat "*" [expr 10 - [imdbround $imdbrating]]]\017${imdbtags}\]\017"
          set imdbrating [concat "\017${imdbtags}Rating:\017${imdbtext}" $imdbrating]
          set imdbtable ""
        } elseif {$imdbtablealt == "Cast:"} {
          if {[regexp {"name">(.*?)<\/span>} $imdbvar match imdbcasttemp]} {
            if {$imdbcast == ""} { 
            set imdbcast [concat "\017${imdbtags}Cast:\017${imdbtext}" $imdbcasttemp]
          } else {
            set imdbcast [concat $imdbcast "," [imdbdehex $imdbcasttemp]]
          }
        } elseif {[string match "*</table>*" $imdbvar]} {
          set imdbtablealt ""
        }
        } elseif {$imdbtable == "Language:"} {
          if {[regexp {>(.*?)<\/a>} $imdbvar match imdblanguagetemp]} {
            if {$imdblanguage == ""} { 
            set imdblanguage [concat "\017${imdbtags}Language:\017${imdbtext}" $imdblanguagetemp]
          } else {
            set imdblanguage [concat $imdblanguage "," [imdbdehex $imdblanguagetemp]]
          }
        }
        } elseif {$imdbtable == "Country:"} {
          if {[regexp {>(.*?)<\/a>} $imdbvar match imdbcountrytemp]} {
            if {$imdbcountry == ""} { 
            set imdbcountry [concat "\017${imdbtags}Country:\017${imdbtext}" $imdbcountrytemp]
          } else {
            set imdbcountry [concat $imdbcountry "," [imdbdehex $imdbcountrytemp]]
          }
        }
        } elseif {$imdbtable == "Genres:"} {
          if {[regexp {>(.*?)<\/a>} $imdbvar match imdbgenretemp]} {
            if {$imdbgenre == ""} { 
            set imdbgenre [concat "\017${imdbtags}Genre:\017${imdbtext}" $imdbgenretemp]
          } else {
            set imdbgenre [concat $imdbgenre "," [imdbdehex $imdbgenretemp]]
          }
        }
        } elseif {$imdbtable == "Director:"} {
          if {[regexp {"name">(.*?)<\/span>} $imdbvar match imdbdirectortemp]} {
            if {$imdbdirector == ""} { 
            set imdbdirector [concat "\017${imdbtags}Director:\017${imdbtext}" $imdbdirectortemp]
          } else {
            set imdbdirector [concat $imdbdirector "," [imdbdehex $imdbdirectortemp]]
          }
        }
        } elseif {$imdbtable == "Writer:"} {
          if {[regexp {"name">(.*?)<\/span>} $imdbvar match imdbwritertemp]} {
            if {$imdbwriter == ""} { 
            set imdbwriter [concat "\017${imdbtags}Writers:\017${imdbtext}" $imdbwritertemp]
          } else {
            set imdbwriter [concat $imdbwriter "," [imdbdehex $imdbwritertemp]]
          }
        }
        } elseif {$imdbtable == "Stars:" && ![string match "*cast and crew*" $imdbvar]} {
          if {[regexp {"name">([^<]*)<} $imdbvar match imdbstarstemp]} {
            if {$imdbstars == ""} { 
            set imdbstars [concat "\017${imdbtags}Stars:\017${imdbtext}" $imdbstarstemp]
          } else {
            set imdbstars [concat $imdbstars "," [imdbdehex $imdbstarstemp]]
          }
        }
        } elseif {[regexp {"reviewCount">(.*?)\scritic} $imdbvar match imdbcritic]} {
          set imdbcritic [concat "\017${imdbtags}Critics:\017${imdbtext}" [imdbdehex $imdbcritic]]
        } elseif {[regexp {<span\sitemprop="reviewCount">(.*)<\/span>\suser<\/a>} $imdbvar match imdbcomment]} {
          set imdbcomment [concat "\017${imdbtags}Comments:\017${imdbtext}" [imdbdehex $imdbcomment]]
        } elseif {[regexp {<meta name="description"\scontent="(.*?)"\s/>} $imdbvar match imdbshortplot]} {
          set imdbshortplot [concat "\017${imdbtags}Description:\017${imdbtext}" [imdbdehex $imdbshortplot]]
        } elseif {[regexp {>(.*?)<meta\sitemprop="datePublished"} $imdbvar match imdbdate]} {
          set imdbdate [concat "\017${imdbtags}Published:\017${imdbtext}" [imdbdehex $imdbdate]]
        } elseif {$imdbtable == "Runtime:" && [regexp {<time itemprop="duration" datetime=".*">(.*)<\/time>} $imdbvar match imdbduration]} {
          set imdbduration [concat "\017${imdbtags}Runtime:\017${imdbtext}" [imdbdehex $imdbduration]]
          set imdbtable 0
      } elseif {[string match {*<time itemprop="duration"*} $imdbvar] && $imdbduration == ""} {  
        set imdbdurationfound "on"
        } elseif {$imdbdurationfound == "on"} {
        set imdbduration [concat "\017${imdbtags}Runtime:\017${imdbtext}" [imdbdehex $imdbvar]]
          set imdbtable 0
        set imdbdurationfound ""
        } elseif {[string match "*</body>*" $imdbvar]} {
          if {$line1 != ""} {
            imdbmsg $chan $imdblogo $imdbtext [subst [regsub -all -nocase {(\S+)} $line1 {$imdb\1}]]
          }
          if {$line2 != ""} {
            imdbmsg $chan $imdblogo $imdbtext [subst [regsub -all -nocase {(\S+)} $line2 {$imdb\1}]]
          }
          if {$line3 != ""} {
            imdbmsg $chan $imdblogo $imdbtext [subst [regsub -all -nocase {(\S+)} $line3 {$imdb\1}]]
          }
        close $imdbSock
        return 0
        } elseif {[regexp {<span itemprop="ratingCount">(.*?)<\/span>} $imdbvar match imdbvotes]} {
          set imdbvotes [concat "\017${imdbtags}Votes:\017${imdbtext}" $imdbvotes]
        }
      }
    }
      close $imdbSock
      return 0 
  }
}
proc imdbround {num} {
  return [expr {round($num)}]
}
proc imdbmsg {chan logo textf text} {
  set text [imdbtextsplit $text 50]
  set counter 0
  while {$counter <= [llength $text]} {
    if {[lindex $text $counter] != ""} {
      putserv "PRIVMSG $chan :${logo} ${textf}[lindex $text $counter]"
    }
    incr counter
  }
}
proc googleimdbsearch {nick host hand chan search} {
  global imdb_lang
  if {[lsearch -exact [channel info $chan] +imdb] != -1} {
    if {[regexp -nocase {http\:\/\/([^\.]*\.google\.[^\/]*)(.*)} $search match googleimdbsite googleimdburl]} {
    } else {
      set googleimdbsite "www.google.com"
      set googleimdbsearch [string map {{ } \%20} "${search}"]
      set googleimdburl "/search?q=${googleimdbsearch}+site:imdb.com&rls=${imdb_lang}&hl=${imdb_lang}"
    }
    if {[catch {set googleimdbSock [socket -async $googleimdbsite 80]} sockerr]} {
      putserv "PRIVMSG $chan :$googleimdbsite $googleimdburl $sockerr error"
      return 0
    } else {
      puts $googleimdbSock "GET $googleimdburl HTTP/1.0"
      puts $googleimdbSock "Host: $googleimdbsite"
      puts $googleimdbSock "User-Agent: Opera 9.6"
      puts $googleimdbSock ""
      flush $googleimdbSock
      while {![eof $googleimdbSock]} {
        set googleimdbvar " [gets $googleimdbSock] "
        if {[regexp -nocase {Location\:\s?(.*)} $googleimdbvar match search]} {
          close $googleimdbSock
          googleimdbsearch $nick $host $hand $chan $search
          return
        } elseif {[regexp {<cite>(.*?)<\/cite>} $googleimdbvar match googleimdbresult]} {
          if {[regexp {imdb\.com} $googleimdbresult]} {
            set googleimdbresult [imdbstrip $googleimdbresult]
            regexp {(.*?)\/} $googleimdbresult match imdbsite
            regexp {\.com(.*)} $googleimdbresult match imdburl
            imdb $nick $host $hand $chan "akas.imdb.com" $imdburl
            close $googleimdbSock
         return 0
          }
        }
      }
      putserv "PRIVMSG $chan :\002Nothing found on imdb! Please refine your search and check your spelling."
      close $googleimdbSock
      return 0 
    }
  }
}
proc imdbtextsplit {text limit} {
  set text [split [string trimright $text " "] " "]
  set tokens [llength $text]
  set start 0
  set return ""
  while {[llength [lrange $text $start $tokens]] > $limit} {
    incr tokens -1
    if {[llength [lrange $text $start $tokens]] <= $limit} {
      lappend return [join [lrange $text $start $tokens]]
      set start [expr $tokens + 1]
      set tokens [llength $text]
    }
  }
  lappend return [join [lrange $text $start $tokens]]
  return $return
}
proc imdbhex {decimal} { return [format %x $decimal] }
proc imdbdecimal {hex} { return [expr 0x$hex] }
proc imdbdehex {string} {
  regsub -all {^\{|\}$} $string "" string
  set string [subst [regsub -nocase -all {\&#x([0-9a-f]{1,3});} $string {[format %c [imdbdecimal \1]]}]]
  set string [subst [regsub -nocase -all {\&#([0-9]{1,3});} $string {[format %c \1]}]]
  set string [string map {&ndash; - &middot; · &raquo; » &laquo; « &Uuml; Ü &uuml; ü &Aacute; Á &aacute; á &Eacute; \
  É &eacute; é &Iacute; Í &iacute; í &Oacute; Ó &oacute; ó &Ntilde; Ñ &ntilde; ñ &Uacute; Ú &uacute; ú &nbsp; \160 \
  &aelig; æ &quot; \" <b> \002 </b> \002} $string]
  return $string
}
proc imdbstrip {string} {
  regsub -all {<[^<>]+>} $string "" string
  regsub -all {\[\d+\]} $string "" string
  return $string
}
bind pub - [string trimleft $imdb_cmdchar]imdb googleimdbsearch
setudef flag imdb
putlog "\002*Loaded* \002\00301,08IMDb\002\003 \002by Ford_Lawnmower irc.GeekShed.net #Script-Help"

Comments

Sign in to comment.
fahadmehar   -  Oct 26, 2016

Its good TCL but my bot kick for flood.

 Respond  
FordLawnmower   -  Nov 22, 2014

I don't know how this got so screwy. It's updated now!

Hawkee  -  Nov 22, 2014

Are all the mIRC codes working properly now?

Sign in to comment

Nailz   -  Sep 25, 2014

The code snippet is not for imdb but something called "aka"?

 Respond  
nutty   -  Aug 22, 2014

Tested script in newest egg-drop 1.8 works well .. good job and ty for sharing :)

 Respond  
blackvenomm666   -  Aug 21, 2014

as usual ford grea script and well done

 Respond  
prashant179   -  Jan 14, 2014

Hello Mr. FordLawnmower i inform you your this Script Work Awesome but Take Long Time to Get Result approximately take 30 Sec to 90 Sec to get Search result on Channel
-I have no idea what problem in this Script
-otherwise your other Scripts like ~ YouTube URL Checker, Urban Dictionary, Advanced Google & your others | work Like Charm they Get result in 1 sec that is Awesome

  • hope you fix this Problem Soon thank-you :)
 Respond  
jeefo.w32   -  May 14, 2013

still there are some mistakes.. there are 3 mistakes i caught ..

1.director..director..director..director..director..director....

  1.  Stars: Mike Myers , Eddie Murphy , Cameron Diaz</s ( seems code error )
  2. Rating: 5.9 [**] i didnt get what is [***] for.

can we make it titles in order below :

IMDB Title : Run time: Genre: Language: Country:
Director:
Stars:
Description:
Rating: Votes:
IMDB Link:

thank you.

FordLawnmower  -  May 29, 2013

Updated: The site was totally changed again.

jeefo.w32  -  May 30, 2013

Thank you very much FordLawnmower :)

your ,

Rotten Tomato http://www.hawkee.com/snippet/9516/
Google http://www.hawkee.com/snippet/7681/
Wikipedia http://www.hawkee.com/snippet/9492/

scripts also need update i think :/

Sign in to comment

polarisirc   -  Apr 26, 2013

Any chance there may be an update to also get the screens for a movie (oldest screening)?

 Respond  
oenahs   -  Mar 11, 2013

Is there anyway you could add a function to display upcoming movies in user set intervals for posting into a channel?

 Respond  
NTL   -  Feb 19, 2013

Just noticed the director and cast stoped working, can you fix it please FordLawnmower. Keep up the good work :)

just an example:
Title: Identity Thief (2013)
Director: Director: Director: Director: Director: Director: Director: Director: Director: Director: Director: Director: Director: <span class="itemprop"
Cast:

FordLawnmower  -  Feb 19, 2013

@NTL Thanks for the info , I'll post the update now.
These imdb changes usually come in bunches, so I'll try to keep an eye on this script.

Sign in to comment

ThePHX   -  Feb 18, 2013

I noticed, during the imdb searches I've performed that it gives a different rating than what is on imdb. When I search for Wreck It Ralph it shows the rating as 6.5, however when you click on the link the site shows the rating as 7.9. Anyway you could fix that? I have tried...and broke it every time. Thanks a lot for your work!!

FordLawnmower  -  Feb 18, 2013

Good catch ThePHX . The code above is updated. Let me know how it works.

Sign in to comment

pei   -  Dec 13, 2012

FIX IT FIX IT FIX IT FIX IT FIX IT!!! When you !imdb something that doesn't exist, it just returns the IMDB logo in the channel twice. :) FIX IT!

 Respond  
FordLawnmower   -  Dec 08, 2012

Updated. Thanks for noticing pei :)

 Respond  
pei   -  Nov 28, 2012

Also for tv shows how can I made it not put "– " in the title, example: "IMDb Title: Dexter (TV Series 2006– )"
Thanks, great script I have been looking for a working one forever now! :)

 Respond  
pei   -  Nov 28, 2012

Also for tv shows how can I made it not put "– " in the title, example: "IMDb Title: Dexter (TV Series 2006– )"
Thanks, great script I have been looking for a working one forever now! :)

 Respond  
pei   -  Nov 28, 2012

How can I make it not say "See full list of cast and crew" when it outputs the cast and crew? Thanks!

 Respond  
FordLawnmower   -  Oct 10, 2012

Updated to fix broken rating.

 Respond  
FordLawnmower   -  Jun 02, 2012

@Hawkee RottenTomatoes.tcl is done: http://www.hawkee.com/snippet/9516/

 Respond  
FordLawnmower   -  May 29, 2012

@Hawkee That is actually next on my list.
The RT api will look up movies by the imdb id so the search portion of this script can be reused.
I'll put it together in a week or so.

 Respond  
Hawkee   -  May 29, 2012

We need something like this for Rottentomatoes, I prefer their rating system.

 Respond  
FordLawnmower   -  May 29, 2012

@irchainscriptz Thanks :)
I've had some of these tcl scripts on my list for a couple years now.
I'm just now finding the time to write them.

 Respond  
irchainscriptz   -  May 29, 2012

Nice FordLawnmower

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.