Advertisement
Ford

IMDB tcl / Forced English Title

Jan 1st, 2013
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 {[regexp {content="(http:\/\/www.imdb.com\/title\/.*\/)"} $imdbvar match imdblink]} {
  76.           set imdblink [concat "\017${imdbtags}Link:\017" "${imdblinks}${imdblink}\015"]
  77.         } elseif {[regexp {<title>([^<]*)\s-\sIMDb<\/title>} $imdbvar match imdbtitle]} {
  78.           set imdbtitle [concat "\017${imdbtags}Title:\017${imdbtext}" [imdbdehex $imdbtitle]]
  79.         } elseif {[regexp {class="title-extra"\sitemprop="name">([^<]*)} $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 {[regexp {Sprite\sstar-box-giga-star">\s?(.*?)\s?<\/div>?} $imdbvar match imdbrating]} {
  87.          set imdbgraph "\017${imdbtags}\[${imdbtext}[string repeat "*" [imdbround $imdbrating]]\00314"
  88.          set imdbgraph "${imdbgraph}[string repeat "*" [expr 10 - [imdbround $imdbrating]]]\017${imdbtags}\]\017"
  89.          set imdbrating [concat "\017${imdbtags}Rating:\017${imdbtext}" $imdbrating]
  90.          set imdbtable 0
  91.        } elseif {$imdbtable == "cast_list"} {
  92.          if {[regexp {\/name\/nm.*\/".*>(.*)<\/a>} $imdbvar match imdbcasttemp]} {
  93.             set imdbcast [concat $imdbcast "," [imdbdehex $imdbcasttemp]]
  94.           } elseif {[regexp {<div class=} $imdbvar]} {
  95.             regexp {^\,(.*)} $imdbcast match imdbcast
  96.             set imdbcast [concat "\017${imdbtags}Cast:\017${imdbtext}" $imdbcast]
  97.             set imdbtable 0
  98.           }
  99.         } elseif {$imdbtable == "Language:"} {
  100.           if {[regexp {>(.*?)<\/a>} $imdbvar match imdblanguagetemp]} {
  101.             set imdblanguage [concat $imdblanguage "," [imdbdehex $imdblanguagetemp]]
  102.           } elseif {[regexp {<div class=} $imdbvar]} {
  103.             regexp {^\,(.*)} $imdblanguage match imdblanguage
  104.             set imdblanguage [concat "\017${imdbtags}Language:\017${imdbtext}" $imdblanguage]
  105.             set imdbtable 0
  106.           }
  107.         } elseif {$imdbtable == "Country:"} {
  108.           if {[regexp {>(.*?)<\/a>} $imdbvar match imdbcountrytemp]} {
  109.             set imdbcountry [concat $imdbcountry "," [imdbdehex $imdbcountrytemp]]
  110.           } elseif {[regexp {<div class=} $imdbvar]} {
  111.             regexp {^\,(.*)} $imdbcountry match imdbcountry
  112.             set imdbcountry [concat "\017${imdbtags}Country:\017${imdbtext}" $imdbcountry]
  113.             set imdbtable 0
  114.           }
  115.         } elseif {$imdbtable == "Genres:"} {
  116.           if {[regexp {>(.*?)<\/a>} $imdbvar match imdbgenretemp]} {
  117.             set imdbgenre [concat $imdbgenre "," [imdbdehex $imdbgenretemp]]
  118.           } elseif {[regexp {<div class=} $imdbvar]} {
  119.             regexp {^\,(.*)} $imdbgenre match imdbgenre
  120.             set imdbgenre [concat "\017${imdbtags}Genre:\017${imdbtext}" $imdbgenre]
  121.             set imdbtable 0
  122.           }
  123.         } elseif {$imdbtable == "Director:"} {
  124.           if {[regexp {"name">(.*?)<\/span>} $imdbvar match imdbdirectortemp]} {
  125.             set imdbdirector [concat $imdbdirector "," [imdbdehex $imdbdirectortemp]]
  126.           } elseif {[regexp {<div class=} $imdbvar]} {
  127.             regexp {^\,(.*)} $imdbdirector match imdbdirector
  128.             set imdbdirector [concat "\017${imdbtags}Director:\017${imdbtext}" $imdbdirector]
  129.             set imdbtable 0
  130.           }
  131.         } elseif {$imdbtable == "Writer:"} {
  132.           if {[regexp {"name">(.*?)<\/span>} $imdbvar match imdbwritertemp]} {
  133.             set imdbwriter [concat $imdbwriter "," [imdbdehex $imdbwritertemp]]
  134.           } elseif {[regexp {<div class=} $imdbvar]} {
  135.             regexp {^\,(.*)} $imdbwriter match imdbwriter
  136.             set imdbwriter [concat "\017${imdbtags}Writer:\017${imdbtext}" $imdbwriter]
  137.             set imdbtable 0
  138.           }
  139.         } elseif {$imdbtable == "Stars:" && ![string match "*cast and crew*" $imdbvar]} {
  140.           if {[regexp {"name">(.*?)<\/span>} $imdbvar match imdbstarstemp]} {
  141.             set imdbstars [concat $imdbstars "," [imdbdehex $imdbstarstemp]]
  142.           } elseif {[string match "*</div>*" $imdbvar]} {
  143.             regexp {^\,(.*)} $imdbstars match imdbstars
  144.             set imdbstars [concat "\017${imdbtags}Stars:\017${imdbtext}" $imdbstars]
  145.             set imdbtable 0
  146.           }
  147.         } elseif {[regexp {<span\sitemprop="reviewCount">(.*)<\/span>\scritic<\/a>} $imdbvar match imdbcritic]} {
  148.           set imdbcritic [concat "\017${imdbtags}Critics:\017${imdbtext}" [imdbdehex $imdbcritic]]
  149.         } elseif {[regexp {<span\sitemprop="reviewCount">(.*)<\/span>\suser<\/a>} $imdbvar match imdbcomment]} {
  150.           set imdbcomment [concat "\017${imdbtags}Comments:\017${imdbtext}" [imdbdehex $imdbcomment]]
  151.         } elseif {[regexp {<meta name="description"\scontent="(.*?)"\s/>} $imdbvar match imdbshortplot]} {
  152.           set imdbshortplot [concat "\017${imdbtags}Description:\017${imdbtext}" [imdbdehex $imdbshortplot]]
  153.         } elseif {[regexp {<time itemprop="datePublished" datetime=".*">(.*)<\/time>} $imdbvar match imdbdate]} {
  154.           set imdbdate [concat "\017${imdbtags}Published:\017${imdbtext}" [imdbdehex $imdbdate]]
  155.         } elseif {$imdbtable == "Runtime:" && [regexp {<time itemprop="duration" datetime=".*">(.*)<\/time>} $imdbvar match imdbduration]} {
  156.           set imdbduration [concat "\017${imdbtags}Runtime:\017${imdbtext}" [imdbdehex $imdbduration]]
  157.           set imdbtable 0
  158.         } elseif {[string match "*Aspect Ratio:*" $imdbvar] || [string match "*<!-- begin TOP_RHS -->*" $imdbvar]} {
  159.           if {$line1 != ""} {
  160.             imdbmsg $chan $imdblogo $imdbtext [subst [regsub -all -nocase {(\S+)} $line1 {$imdb\1}]]
  161.           }
  162.           if {$line2 != ""} {
  163.             imdbmsg $chan $imdblogo $imdbtext [subst [regsub -all -nocase {(\S+)} $line2 {$imdb\1}]]
  164.           }
  165.           if {$line3 != ""} {
  166.             imdbmsg $chan $imdblogo $imdbtext [subst [regsub -all -nocase {(\S+)} $line3 {$imdb\1}]]
  167.           }
  168.           close $imdbSock
  169.           return 0
  170.         } elseif {[regexp {<span itemprop="ratingCount">(.*?)<\/span>} $imdbvar match imdbvotes]} {
  171.           set imdbvotes [concat "\017${imdbtags}Votes:\017${imdbtext}" $imdbvotes]
  172.         }
  173.       }
  174.     }
  175.       close $imdbSock
  176.       return 0
  177.   }
  178. }
  179. proc imdbround {num} {
  180.   return [expr {round($num)}]
  181. }
  182. proc imdbmsg {chan logo textf text} {
  183.   set text [imdbtextsplit $text 50]
  184.   set counter 0
  185.   while {$counter <= [llength $text]} {
  186.     if {[lindex $text $counter] != ""} {
  187.       putserv "PRIVMSG $chan :${logo} ${textf}[lindex $text $counter]"
  188.     }
  189.     incr counter
  190.   }
  191. }
  192. proc googleimdbsearch {nick host hand chan search} {
  193.   global imdb_lang
  194.   if {[lsearch -exact [channel info $chan] +imdb] != -1} {
  195.     set googleimdbsite "www.google.com"
  196.     set googleimdbsearch [string map {{ } \%20} "${search}"]
  197.     set googleimdburl "/search?q=${googleimdbsearch}+site:imdb.com&rls=${imdb_lang}&hl=${imdb_lang}"
  198.     if {[catch {set googleimdbSock [socket -async $googleimdbsite 80]} sockerr]} {
  199.       putserv "PRIVMSG $chan :$googleimdbsite $googleimdburl $sockerr error"
  200.       return 0
  201.     } else {
  202.       puts $googleimdbSock "GET $googleimdburl HTTP/1.0"
  203.       puts $googleimdbSock "Host: $googleimdbsite"
  204.       puts $googleimdbSock "User-Agent: Opera 9.6"
  205.       puts $googleimdbSock ""
  206.       flush $googleimdbSock
  207.       while {![eof $googleimdbSock]} {
  208.         set googleimdbvar " [gets $googleimdbSock] "
  209.     if {[regexp {<cite>(.*?)<\/cite>} $googleimdbvar match googleimdbresult]} {
  210.           if {[regexp {imdb\.com} $googleimdbresult]} {
  211.             set googleimdbresult [imdbstrip $googleimdbresult]
  212.             regexp {(.*?)\/} $googleimdbresult match imdbsite
  213.             regexp {\.com(.*)} $googleimdbresult match imdburl
  214.             imdb $nick $host $hand $chan "akas.imdb.com" $imdburl
  215.             close $googleimdbSock
  216.         return 0
  217.           }
  218.     }
  219.       }
  220.       putserv "PRIVMSG $chan :\002Nothing found on imdb! Please refine your search and check your spelling."
  221.       close $googleimdbSock
  222.       return 0
  223.     }
  224.   }
  225. }
  226. proc imdbtextsplit {text limit} {
  227.   set text [split $text " "]
  228.   set tokens [llength $text]
  229.   set start 0
  230.   set return ""
  231.   while {[llength [lrange $text $start $tokens]] > $limit} {
  232.     incr tokens -1
  233.     if {[llength [lrange $text $start $tokens]] <= $limit} {
  234.       lappend return [join [lrange $text $start $tokens]]
  235.       set start [expr $tokens + 1]
  236.       set tokens [llength $text]
  237.     }
  238.   }
  239.   lappend return [join [lrange $text $start $tokens]]
  240.   return $return
  241. }
  242. proc imdbhex {decimal} { return [format %x $decimal] }
  243. proc imdbdecimal {hex} { return [expr 0x$hex] }
  244. proc imdbdehex {string} {
  245.   regsub -all {^\{|\}$} $string "" string
  246.   set string [subst [regsub -nocase -all {\&#x([0-9a-f]{1,3});} $string {[format %c [imdbdecimal \1]]}]]
  247.   set string [subst [regsub -nocase -all {\&#([0-9]{1,3});} $string {[format %c \1]}]]
  248.   set string [string map {&ndash; - &middot; · &raquo; » &laquo; « &Uuml; Ü &uuml; ü &Aacute; Á &aacute; á &Eacute; \
  249.   É &eacute; é &Iacute; Í &iacute; í &Oacute; Ó &oacute; ó &Ntilde; Ñ &ntilde; ñ &Uacute; Ú &uacute; ú &nbsp; \160 \
  250.   &aelig; æ &quot; \" <b> \002 </b> \002} $string]
  251.  return $string
  252. }
  253. proc imdbstrip {string} {
  254.  regsub -all {<[^<>]+>} $string "" string
  255.  regsub -all {\[\d+\]} $string "" string
  256.  return $string
  257. }
  258. bind pub - [string trimleft $imdb_cmdchar]imdb googleimdbsearch
  259. setudef flag imdb
  260. 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