Advertisement
Ford

IMDb.tcl for eggdrop

May 28th, 2012
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 13.10 KB | None | 0 0
  1. ##############################################################################################
  2. ##  ##     imdb.tcl for eggdrop by Ford_Lawnmower irc.geekshed.net #Script-Help         ##  ##
  3. ##############################################################################################
  4. ## To use this script you must set channel flag +imdb (ie .chanset #chan +imdb)             ##
  5. ##############################################################################################
  6. ##############################################################################################
  7. ##  ##                             Start Setup.                                         ##  ##
  8. ##############################################################################################
  9. ## Change imdb_cmdchar to the character you want to use.                                    ##
  10. set imdb_cmdchar "!"
  11. ## Change imdb_lang to the 2 digit language code you want to use                            ##
  12. set imdb_lang "en"
  13. proc imdb {nick host hand chan imdbsite imdburl} {
  14.   if {[lsearch -exact [channel info $chan] +imdb] != -1} {
  15. ## Change the characters between the "" below to change the logo shown with each result.    ##
  16.     set imdblogo "\002\00301,08IMDb\017"
  17. ## Change the format codes between the "" below to change the color/state of the text.      ##
  18.     set imdbtext "\0034"
  19. ## Change the format codes between the "" below to change the color/state of the tags.      ##
  20.     set imdbtags "\002"
  21. ## Change the format codes between the "" below to change the color/state of the links.     ##
  22.     set imdblinks "\037\002"
  23. ## You may adjust how the results are printed by changing line1, line2 and line3            ##
  24. ## Valid items are as follows: cast language country genre director writer stars link title ##
  25. ## plot rating critic comment shortplot date duration votes title logo graph                ##
  26.     set line1 "title duration genre date language country director writer stars"
  27.     set line2 "shortplot rating graph votes comment critic link"
  28.     set line3 ""
  29. ##############################################################################################
  30. ##  ##                           End Setup.                                              ## ##
  31. ############################################################################################## 
  32.     if {[catch {set imdbSock [socket -async $imdbsite 80]} sockerr]} {
  33.       putserv "PRIVMSG $chan :$imdbsite $imdburl $sockerr error"
  34.       return 0
  35.       } else {
  36.       puts $imdbSock "GET $imdburl HTTP/1.0"
  37.       puts $imdbSock "Host: $imdbsite"
  38.       puts $imdbSock "User-Agent: Opera 9.6"
  39.       puts $imdbSock ""
  40.       flush $imdbSock
  41.       set imdbtable 0
  42.       set imdbtitle ""
  43.       set imdbcast ""
  44.       set imdblanguage ""
  45.       set imdbcountry ""
  46.       set imdbgenre ""
  47.       set imdbdirector ""
  48.       set imdbwriter ""
  49.       set imdbstars ""
  50.       set imdblink ""
  51.       set imdbtitle ""
  52.       set imdbplot ""
  53.       set imdbrating ""
  54.       set imdbcritic ""
  55.       set imdbcomment ""
  56.       set imdbshortplot ""
  57.       set imdbdate ""
  58.       set imdbduration ""
  59.       set imdbvotes ""
  60.       set imdbgraph ""
  61.       while {![eof $imdbSock]} {
  62.         set imdbvar " [gets $imdbSock] "
  63.         if {[regexp {may refer to:} $imdbvar] || [regexp {HTTP\/1\.0 403} $imdbvar]} {
  64.            putserv "PRIVMSG $chan :\002Nothing found on imdb! Please refine your search and check your spelling."
  65.            close $imdbSock
  66.        return 0
  67.         } elseif {[string match "*<table class=*" $imdbvar]} {
  68.           regexp {"(.*?)"} $imdbvar match imdbtable
  69.         } elseif {[string match "*<h4 class=\"inline\">*</h4>*" $imdbvar]} {
  70.           regexp {>(.*?)<\/h4>} $imdbvar match imdbtable
  71.         } elseif {[string match "*Director:*" $imdbvar]} {
  72.           set imdbtable "Director:"
  73.         } elseif {[string match "*Writer:*" $imdbvar]} {
  74.           set imdbtable "Writer:"
  75.         } elseif {[string match "*<div class=\"star-box-giga-star\">*" $imdbvar]} {
  76.           set imdbtable "Rating:"
  77.         } elseif {[regexp {content="(http:\/\/www.imdb.com\/title\/.*\/)"} $imdbvar match imdblink]} {
  78.           set imdblink [concat "\017${imdbtags}Link:\017" "${imdblinks}${imdblink}\015"]
  79.         } elseif {[regexp {<title>([^<]*)\s-\sIMDb<\/title>} $imdbvar match imdbtitle]} {
  80.           set imdbtitle [concat "\017${imdbtags}Title:\017${imdbtext}" [imdbdehex $imdbtitle]]
  81.         } elseif {[string match "*<h2>Storyline</h2>*" $imdbvar]} {
  82.           set imdbtable "plot:"
  83.         } elseif {$imdbtable == "plot:" && [string match "*<p>*" $imdbvar]} {
  84.           set imdbplot [concat "\017${imdbtags}Plot:\017${imdbtext}" [imdbdehex [imdbstrip $imdbvar]]]
  85.           set imdbtable 0
  86.         } elseif {$imdbtable == "Rating:"} {
  87.           set imdbrating [imdbstrip $imdbvar]
  88.           set imdbgraph "\017${imdbtags}\[${imdbtext}[string repeat "*" [imdbround $imdbrating]]\00314"
  89.           set imdbgraph "${imdbgraph}[string repeat "*" [expr 10 - [imdbround $imdbrating]]]\017${imdbtags}\]\017"
  90.           set imdbrating [concat "\017${imdbtags}Rating:\017${imdbtext}" $imdbrating]
  91.           set imdbtable 0
  92.         } elseif {$imdbtable == "cast_list"} {
  93.           if {[regexp {\/name\/nm.*\/".*>(.*)<\/a>} $imdbvar match imdbcasttemp]} {
  94.            set imdbcast [concat $imdbcast "," [imdbdehex $imdbcasttemp]]
  95.          } elseif {[regexp {<div class=} $imdbvar]} {
  96.            regexp {^\,(.*)} $imdbcast match imdbcast
  97.            set imdbcast [concat "\017${imdbtags}Cast:\017${imdbtext}" $imdbcast]
  98.            set imdbtable 0
  99.          }
  100.        } elseif {$imdbtable == "Language:"} {
  101.          if {[regexp {>(.*?)<\/a>} $imdbvar match imdblanguagetemp]} {
  102.            set imdblanguage [concat $imdblanguage "," [imdbdehex $imdblanguagetemp]]
  103.          } elseif {[regexp {<div class=} $imdbvar]} {
  104.            regexp {^\,(.*)} $imdblanguage match imdblanguage
  105.            set imdblanguage [concat "\017${imdbtags}Language:\017${imdbtext}" $imdblanguage]
  106.            set imdbtable 0
  107.          }
  108.        } elseif {$imdbtable == "Country:"} {
  109.          if {[regexp {>(.*?)<\/a>} $imdbvar match imdbcountrytemp]} {
  110.            set imdbcountry [concat $imdbcountry "," [imdbdehex $imdbcountrytemp]]
  111.          } elseif {[regexp {<div class=} $imdbvar]} {
  112.            regexp {^\,(.*)} $imdbcountry match imdbcountry
  113.            set imdbcountry [concat "\017${imdbtags}Country:\017${imdbtext}" $imdbcountry]
  114.            set imdbtable 0
  115.          }
  116.        } elseif {$imdbtable == "Genres:"} {
  117.          if {[regexp {>(.*?)<\/a>} $imdbvar match imdbgenretemp]} {
  118.            set imdbgenre [concat $imdbgenre "," [imdbdehex $imdbgenretemp]]
  119.          } elseif {[regexp {<div class=} $imdbvar]} {
  120.            regexp {^\,(.*)} $imdbgenre match imdbgenre
  121.            set imdbgenre [concat "\017${imdbtags}Genre:\017${imdbtext}" $imdbgenre]
  122.            set imdbtable 0
  123.          }
  124.        } elseif {$imdbtable == "Director:"} {
  125.          if {[regexp {>(.*?)<\/a>} $imdbvar match imdbdirectortemp]} {
  126.            set imdbdirector [concat $imdbdirector "," [imdbdehex $imdbdirectortemp]]
  127.          } elseif {[regexp {<div class=} $imdbvar]} {
  128.            regexp {^\,(.*)} $imdbdirector match imdbdirector
  129.            set imdbdirector [concat "\017${imdbtags}Director:\017${imdbtext}" $imdbdirector]
  130.            set imdbtable 0
  131.          }
  132.        } elseif {$imdbtable == "Writer:"} {
  133.          if {[regexp {>(.*?)<\/a>} $imdbvar match imdbwritertemp]} {
  134.            set imdbwriter [concat $imdbwriter "," [imdbdehex $imdbwritertemp]]
  135.          } elseif {[regexp {<div class=} $imdbvar]} {
  136.            regexp {^\,(.*)} $imdbwriter match imdbwriter
  137.            set imdbwriter [concat "\017${imdbtags}Writer:\017${imdbtext}" $imdbwriter]
  138.            set imdbtable 0
  139.          }
  140.        } elseif {$imdbtable == "Stars:"} {
  141.          if {[regexp {>(.*?)<\/a>} $imdbvar match imdbstarstemp]} {
  142.            set imdbstars [concat $imdbstars "," [imdbdehex $imdbstarstemp]]
  143.          } elseif {[string match "*</div>*" $imdbvar]} {
  144.            regexp {^\,(.*)} $imdbstars match imdbstars
  145.            set imdbstars [concat "\017${imdbtags}Stars:\017${imdbtext}" $imdbstars]
  146.            set imdbtable 0
  147.          }
  148.        } elseif {[regexp {<span\sitemprop="reviewCount">(.*)<\/span>\scritic<\/a>} $imdbvar match imdbcritic]} {
  149.          set imdbcritic [concat "\017${imdbtags}Critics:\017${imdbtext}" [imdbdehex $imdbcritic]]
  150.        } elseif {[regexp {<span\sitemprop="reviewCount">(.*)<\/span>\suser<\/a>} $imdbvar match imdbcomment]} {
  151.          set imdbcomment [concat "\017${imdbtags}Comments:\017${imdbtext}" [imdbdehex $imdbcomment]]
  152.        } elseif {[regexp {<meta name="description"\scontent="(.*?)"\s/>} $imdbvar match imdbshortplot]} {
  153.          set imdbshortplot [concat "\017${imdbtags}Description:\017${imdbtext}" [imdbdehex $imdbshortplot]]
  154.        } elseif {[regexp {<time itemprop="datePublished" datetime=".*">(.*)<\/time>} $imdbvar match imdbdate]} {
  155.          set imdbdate [concat "\017${imdbtags}Published:\017${imdbtext}" [imdbdehex $imdbdate]]
  156.        } elseif {$imdbtable == "Runtime:" && [regexp {<time itemprop="duration" datetime=".*">(.*)<\/time>} $imdbvar match imdbduration]} {
  157.          set imdbduration [concat "\017${imdbtags}Runtime:\017${imdbtext}" [imdbdehex $imdbduration]]
  158.          set imdbtable 0
  159.        } elseif {[string match "*Aspect Ratio:*" $imdbvar] || [string match "*<!-- begin BOTTOM_AD -->*" $imdbvar]} {
  160.          if {$line1 != ""} {
  161.            imdbmsg $chan $imdblogo $imdbtext [subst [regsub -all -nocase {(\S+)} $line1 {$imdb\1}]]
  162.          }
  163.          if {$line2 != ""} {
  164.            imdbmsg $chan $imdblogo $imdbtext [subst [regsub -all -nocase {(\S+)} $line2 {$imdb\1}]]
  165.          }
  166.          if {$line3 != ""} {
  167.            imdbmsg $chan $imdblogo $imdbtext [subst [regsub -all -nocase {(\S+)} $line3 {$imdb\1}]]
  168.          }
  169.        } elseif {[regexp {<span itemprop="ratingCount">(.*?)<\/span>} $imdbvar match imdbvotes]} {
  170.          set imdbvotes [concat "\017${imdbtags}Votes:\017${imdbtext}" $imdbvotes]
  171.        }
  172.      }
  173.    }
  174.      close $imdbSock
  175.      return 0
  176.  }
  177. }
  178. proc imdbround {num} {
  179.  return [expr {round($num)}]
  180. }
  181. proc imdbmsg {chan logo textf text} {
  182.  set text [imdbtextsplit $text 50]
  183.  set counter 0
  184.  while {$counter <= [llength $text]} {
  185.    if {[lindex $text $counter] != ""} {
  186.      putserv "PRIVMSG $chan :${logo} ${textf}[lindex $text $counter]"
  187.    }
  188.    incr counter
  189.  }
  190. }
  191. proc googleimdbsearch {nick host hand chan search} {
  192.  global imdb_lang
  193.  if {[lsearch -exact [channel info $chan] +imdb] != -1} {
  194.    set googleimdbsite "www.google.com"
  195.    set googleimdbsearch [string map {{ } \%20} "${search}"]
  196.    set googleimdburl "/search?q=${googleimdbsearch}+site:imdb.com&rls=${imdb_lang}&hl=${imdb_lang}"
  197.    if {[catch {set googleimdbSock [socket -async $googleimdbsite 80]} sockerr]} {
  198.      putserv "PRIVMSG $chan :$googleimdbsite $googleimdburl $sockerr error"
  199.      return 0
  200.    } else {
  201.      puts $googleimdbSock "GET $googleimdburl HTTP/1.0"
  202.      puts $googleimdbSock "Host: $googleimdbsite"
  203.      puts $googleimdbSock "User-Agent: Opera 9.6"
  204.      puts $googleimdbSock ""
  205.      flush $googleimdbSock
  206.      while {![eof $googleimdbSock]} {
  207.        set googleimdbvar " [gets $googleimdbSock] "
  208.     if {[regexp {<cite>(.*?)<\/cite>} $googleimdbvar match googleimdbresult]} {
  209.          if {[regexp {imdb\.com} $googleimdbresult]} {
  210.            set googleimdbresult [imdbstrip $googleimdbresult]
  211.            regexp {(.*?)\/} $googleimdbresult match imdbsite
  212.            regexp {\.com(.*)} $googleimdbresult match imdburl
  213.            imdb $nick $host $hand $chan $imdbsite $imdburl
  214.            close $googleimdbSock
  215.         return 0
  216.          }
  217.     }
  218.      }
  219.      putserv "PRIVMSG $chan :\002Nothing found on imdb! Please refine your search and check your spelling."
  220.      close $googleimdbSock
  221.      return 0
  222.    }
  223.  }
  224. }
  225. proc imdbtextsplit {text limit} {
  226.  set text [split $text " "]
  227.  set tokens [llength $text]
  228.  set start 0
  229.  set return ""
  230.  while {[llength [lrange $text $start $tokens]] > $limit} {
  231.    incr tokens -1
  232.    if {[llength [lrange $text $start $tokens]] <= $limit} {
  233.      lappend return [join [lrange $text $start $tokens]]
  234.      set start [expr $tokens + 1]
  235.      set tokens [llength $text]
  236.    }
  237.  }
  238.  lappend return [join [lrange $text $start $tokens]]
  239.  return $return
  240. }
  241. proc imdbhex {decimal} { return [format %x $decimal] }
  242. proc imdbdecimal {hex} { return [expr 0x$hex] }
  243. proc imdbdehex {string} {
  244.  regsub -all {^\{|\}$} $string "" string
  245.  set string [subst [regsub -nocase -all {\&#x([0-9a-f]{1,3});} $string {[format %c [imdbdecimal \1]]}]]
  246.  set string [subst [regsub -nocase -all {\&#([0-9]{1,3});} $string {[format %c \1]}]]
  247.  set string [string map {&quot; \" &middot; · &amp; & <b> \002 </b> \002} $string]
  248.  return $string
  249. }
  250. proc imdbstrip {string} {
  251.  regsub -all {<[^<>]+>} $string "" string
  252.  regsub -all {\[\d+\]} $string "" string
  253.  return $string
  254. }
  255. bind pub - [string trimleft $imdb_cmdchar]imdb googleimdbsearch
  256. setudef flag imdb
  257. putlog "\002*Loaded* \002\00301,08IMDb\002\003 \002by Ford_Lawnmower irc.GeekShed.net #Script-Help"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement