Jump to content

Archived

This topic is now archived and is closed to further replies.

chain

IMDb search for eggdrop

Recommended Posts

  • Administrators

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)

  ##     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 "title duration genre date language country director writer stars"
    set line2 "shortplot rating graph votes comment critic link"
    set line3 "cast plot"
##############################################################################################
##  ##                           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 ""
      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 {$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} {
    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 {<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 $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 {\([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 {– - · · » » « « Ü Ü ü ü Á Á á á É \
  É é é Í Í í í Ó Ó ó ó Ñ Ñ ñ ñ Ú Ú ú ú   \160 \
  æ æ " \" <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"

 

Link to comment
Share on other sites



×
×
  • Create New...