http://overfiend.sessionclan.de/scripts/imdb.html
http://members.dandy.net/~fbn/imdb.2112.tcl.txt
none of them works, eggdrop 1.6.18
now iam trying the 2nd one with curl
my code is:
Code: Select all
###############################################################################
# Output Configs:
#
# COOKIES ARE :
# =============
# TITLE = %title | BOLD = %bold
# URL = %url | UNDERLINE = %uline
# DIRECTOR = %name | COLORS = %color#,#
# GENRE = %genre | NEW LINE = \n
# SYNOPSIS = %plot |-----------------------------
# RATING = %rating | !! to reset color code !!
# RATING_BAR = %rbar | !! use %color w/o args !!
# VOTES = %votes |
# RUNTIME = %time |
# AWARDS = %awards |
# BUDGET = %budget |
# SCREENS = %screens |
# TAGLINE = %tagline |
# MPAA = %mpaa |
# COUNTRY = %country |
# LANGUAGE = %language |
# SOUND MIX = %soundmix |
# TOP 250 = %top250 |
# CAST LINES = %castmline |
# WRITING CREDITS = %wcredits |
# rating bar colors
# bracket color:
set barcol1 "14"
# star colors:
set barcol2 "7"
# Number of Cast/actor names to return (castmline) (0 means no limit)
set cast_linelimit "5"
#
#
# RANDOMIZING OUTPUT :
# ====================
# Exemple:
# set random(IMDBIRC-0) "IMDB info for %bold%title%bold Directed by %name"
# set random(IMDBIRC-1) "IMDB info for %title Directed by %bold%name%bold"
# set random(IMDBIRC-2) "IMDB info for %title Directed by %name"
# TYPE --------^ ^
# ID --------^
#
# set announce(IMDBIRC) "random 3"
# TYPE ---------^ ^ ^
# RANDOM ----------^ ^
# # OF IDS ---------^
#
# exemple random announces:
# set announce(IMDBIRC) "random 3"
# set random(IMDBIRC-0) "IMDB info for %bold%title%bold Directed by %name -> rated %uline%rating%uline (%votes votes) - genre: %genre - runtime: %time mins >> URL: %uline%url%uline >> Budget: %budget >> Screens: (USA) %screens"
# set random(IMDBIRC-1) "TITLE: %bold%title%bold - DIRECTOR: %name - RATE: %rating by %votes users - GENRE: %genre - RUNTIME: %time mins - URL: %url - BUDGET: %budget - SCREENS: (USA) %screens"
# set random(IMDBIRC-2) "%bold%title%bold - %url\n%boldDirected by:%bold %name\n%boldGenre:%bold %genre\n%boldTagline:%bold %tagline\n%boldSynopsis:%bold %plot\n%boldRating:%bold %rating (%votes votes) top 250:%bold%top250%bold\n%boldMPAA:%bold %mpaa\n%boldRuntime:%bold %time mins.\n%boldCountry:%bold %country\n%boldLanguage:%bold %language\n%boldSound Mix:%bold %soundmix\n%boldBudget:%bold %budget \n%boldOpening Weekend:%bold (USA) %screens"
#
# example normal announce:
#set announce(IMDBIRC) "%bold%title%bold - %url\nGenre: %genre\nTagline: %tagline\nSynopsis: %plot\nRating: %rating (%votes votes) %rbar %color3%top250%color\nAwards: %awards\nRuntime: %time mins."
# This is what I use -Rosc
set announce(IMDBIRC) "%bold%title%bold - %url\n \
%boldTagline :%bold %tagline \n \
%boldGenre :%bold %genre \n \
%boldAwards :%bold %awards \n \
%boldRating :%bold %rating (%votes votes) %rbar %top250 \n \
%boldMPAA :%bold %mpaa \n \
%boldDirector:%bold %name \n \
%boldWriter :%bold %wcredits \n \
%boldRuntime :%bold %time \n \
%boldCountry :%bold %country\n \
%boldLanguage:%bold %language\n \
%boldBudget :%bold %budget\n \
%bold1st week:%bold %screens\n \
%boldSound :%bold %soundmix \n \
%boldPlot :%bold %plot \n \
%boldCast :%bold (Showing first $cast_linelimit only)\n%castmline\
"
# end output config section
#####################################################################################
# Other Configs:
# Channels to allow public use in:
set imdbchans "#xxx"
# http connection timeout (milliseconds - 1/1000ths sec.)
set imdb_timeout "30000"
# flood-control:
set queue_enabled 1
# max requests:
set queue_size 5
# per ? seconds:
set queue_time 30
# for in-channel .imdb request: (1) == send output to channel (0) send output to PRIVMSG
set pub_or_not 1
# You can choose to use the http package, or the program 'curl' for grabbing the html data
# (maybe this should use the socket code instead of curl? meh, I'm too lazy to port it -rosc)
# set IMDB_ALTERNATIVE 0 = use the internal tcl http 2.3 package
# set IMDB_ALTERNATIVE 1 = use the external curl program
set IMDB_ALTERNATIVE 1
# set here the location path where to find 'curl' if using IMDB_ALTERNATIVE 1
set binary(CURL) "/usr/local/bin/curl"
#################################################################
# DO NOT MODIFY BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING! #
#################################################################
if { $IMDB_ALTERNATIVE == 0 } {package require http 2.3}
bind pub -|- .imdb imdb_proc
set instance 0
set warn_msg 0
proc htmlcodes {tempfile} {
set mapfile [string map {" ' & & [ ( \ / ] ) { ( } ) £ £ ¨ ¨ © © « « ® ® ¡ ¡ ¿ ¿} $tempfile]
set mapfile [string map {´ ´ · · ¹ ¹ » » ¼ ¼ ½ ½ ¾ ¾ À À Á Á Â Â } $mapfile]
set mapfile [string map {Ã Ã Ä Ä Å Å Æ Æ Ç Ç È È É É Ê Ê Ë Ë Ì Ì Í Í Î Î Ï Ï Ð Ð Ñ Ñ Ò Ò Ó Ó Ô Ô Õ Õ Ö Ö } $mapfile]
set mapfile [string map {× × Ø Ø Ù Ù Ú Ú Û Û Ü Ü Ý Ý Þ Þ ß ß à à á á â â ã ã ä ä å å æ æ ç ç è è é é ê ê } $mapfile]
set mapfile [string map {ë ë ì ì í í î î ï ï ð ð ñ ñ ò ò ó ó ô ô õ õ ö ö ÷ ÷ ø ø ù ù ú ú û û ü ü ý ý þ þ } $mapfile]
set mapfile [string map { "" & "&"} $mapfile]
return $mapfile
}
proc replacevar {strin what withwhat} {
set output $strin
set replacement $withwhat
set cutpos 0
while { [string first $what $output] != -1 } {
set cutstart [expr [string first $what $output] - 1]
set cutstop [expr $cutstart + [string length $what] + 1]
set output [string range $output 0 $cutstart]$replacement[string range $output $cutstop end]
}
return $output
}
proc findnth {strin what count} {
set ret 0
for {set x 0} {$x < $count} {incr x} {
set ret [string first $what $strin [expr $ret + 1]]
}
return $ret
}
proc imdb_proc { nick uhost handle chan arg } {
global cast_linelimit instance queue_size queue_time queue_enabled IMDB_ALTERNATIVE
global imdb_timeout barcol1 barcol2 pub_or_not announce random warn_msg binary
# channel_check permission
if {[lsearch -exact $::imdbchans $chan] == -1} {return}
# public or private
if {$pub_or_not == 1 } {
set toput "PRIVMSG $chan"
} else {
set toput "PRIVMSG $nick"
}
# if no arg passed, show help
if {$arg == ""} {
puthelp "$toput :IMDb \002Syntax: .imdb <movie title>\002 exemple: .imdb Beautiful Mind"
return
}
#flood-control
if {$queue_enabled == 1} {
#flooded?
if { $instance >= $queue_size } {
if { $warn_msg == 0 } {
set warn_msg 1
putquick "$toput :Flood-Control: Request for \"$arg\" from user \"$nick\" will not be answered."
putquick "$toput :Flood-Control: Maximum of $queue_size requests every $queue_time seconds."
utimer 120 wmsg
}
return
}
incr instance
utimer [set queue_time] decr_inst
}
# initial search
set imdburl "http://www.imdb.com"
set imdbsearchurl "http://akas.imdb.com/find?tt=on;nm=on;mx=5;"
set searchString [string map {\ %20 & %26 , %2C . %20} $arg]
if { $IMDB_ALTERNATIVE == 0 } {
set page [::http::config -useragent "MSIE 6.0"]
catch {set page [::http::geturl ${imdbsearchurl}q=$searchString -timeout $imdb_timeout]} error
if {[string match -nocase "*couldn't open socket*" $error]} {
puthelp "$toput :Error - couldn't connect..Try again later"
::http::Finish $page
return
}
if {[::http::status $page] == "timeout"} {
puthelp "$toput :\002Connection to imdb.com timed out while doing initial search.\002"
::http::Finish $page
return
}
set html [::http::data $page]
::http::Finish $page
} else {
catch { exec $binary(CURL) "${imdbsearchurl}q=$searchString" } html
}
#if redirect necessary, find first link and redirect
if {([regexp {<title>IMDb.*Search} $html] == 1)} {
set ttcode "0000001"
set start "0"
#start from the headline
regexp -indices {<h1>IMDb.*Search</h1>} $html start
set temp [string range $html [lindex $start 1] end]
#dealing with different search results
set hit 0
if { [regexp -indices {Popular Titles} $temp tstart] } {
set temp2 [string range $temp [lindex $tstart 1] end]
regexp {<a.*?>(.*?)</a>} $temp2 dummy title
if { [string equal -nocase $title $arg] } {
set temp $temp2
set hit 1
}
}
if { $hit == 0 } {
if { [regexp -indices {Exact Matches} $temp start] } {
#putcmdlog "start1 $start"
} elseif { [regexp -indices {Titles} $temp start] } {
#putcmdlog "start2 $start"
} else {
puthelp "$toput :No useful results."
return
}
set temp [string range $temp [lindex $start 1] end]
}
#searching for first ttcode
if {[regexp {/title/tt[0-9]+} $temp ttcode]} {
set pos [string last / $ttcode] ; incr pos
set ttcode [string range $ttcode $pos end]
}
# for bogus ttcode
if { $ttcode == "0000001" } {
puthelp "$toput :Sorry, I couldn't find that title.."
return
}
set newurl "$imdburl/title/$ttcode/"
# get the page redirected to
unset html
if {$IMDB_ALTERNATIVE == 0} {
set page [::http::config -useragent "MSIE 6.0"]
catch {set page [::http::geturl $newurl -timeout $imdb_timeout]} error
if {[string match -nocase "*couldn't open socket*" $error]} {
puthelp "$toput :Error: couldn't connect..Try again later"
::http::Finish $page
return
}
if {[::http::status $page]=="timeout"} {
puthelp "$toput :\002Connection to imdb.com timed out.\002"
::http::Finish $page
return
}
set html [::http::data $page]
::http::Finish $page
} else {
catch { exec $binary(CURL) "$newurl" } html
}
# if no redirect happened, then get first page on match
} else {
set location ""
if { $IMDB_ALTERNATIVE == 0 } {
upvar 0 $page oldpage
regexp {title/tt[0-9]+/} $oldpage(meta) location
} else {
set result [catch { exec $binary(CURL) -i "${imdbsearchurl}q=$searchString" } oldpage]
regexp {title/tt[0-9]+/} $oldpage location
}
set newurl "$imdburl/$location"
if { $location != "" } {
if { $IMDB_ALTERNATIVE == 0 } {
unset html
set page [::http::config -useragent "MSIE 6.0"]
catch {set page [::http::geturl $newurl -timeout $imdb_timeout]} error
if {[string match -nocase "*couldn't open socket*" $error]} {
puthelp "$toput :Error: couldn't connect..Try again later"
::http::Finish $page
return
}
if {[::http::status $page]=="timeout"} {
puthelp "$toput :\002Connection to imdb.com timed out.\002"
::http::Finish $page
return
}
set html [::http::data $page]
::http::Finish $page
} else {
unset html
catch { exec $binary(CURL) "$newurl" } html
}
} else {
puthelp "$toput :I can't find that title..Sorry.."
return
}
}
# for bogus searches
if {[string length $newurl] == 0} {
puthelp "$toput :Sorry, I can't find that title.."
return
}
# decide on output
if { ! [string compare [lindex $announce(IMDBIRC) 0] "random"] && [string is alnum -strict [lindex $announce(IMDBIRC) 1]] == 1 } {
set output $random(IMDBIRC\-[rand [lindex $announce(IMDBIRC) 1]])
} else {
set output $announce(IMDBIRC)
}
# collect output
set title "N/A" ; set name "N/A" ; set genre "N/A" ; set tagline "N/A"
set plot "N/A" ; set rating "N/A" ; set votes "N/A" ; set mpaa "N/A"
set runtime "N/A" ; set budget "N/A" ; set screens "N/A" ; set country "N/A"
set language "N/A" ; set soundmix "N/A" ; set top250 ""; set awards "N/A"
set rating_bar ""; set cast_multiline "N/A"; set wcredits "N/A"
## get title
if {[regexp {<title>[^<]+} $html title]} {
set pos [expr [string last > $title] + 1]
set title [string range $title $pos end]
set title [htmlcodes $title]
}
## get director
if {[regexp {<h5>Directed by</h5>\n(.*?)\n} $html dummy name]} {
set name [string map {(more) "" <br> ""} $name]
set name [string map {<br/> " -\ "} $name]
regsub -all {<[^>]+>} $name {} name
set name [htmlcodes $name]
}
## get writing credits
if {[regexp {<h5>Writing credits.*?</h5>(.*?)<br/>\n} $html dummy wcredits]} {
regsub {\n} $wcredits {} wcredits
regsub {>more<} $wcredits {} wcredits
set wcredits [string map {(more) "" <br> ""} $wcredits]
set wcredits [string map {"&<br>" "& " <br/> " -\ "} $wcredits]
regsub -all {<[^>]+>} $wcredits {} wcredits
set wcredits [htmlcodes $wcredits]
}
## get genre
if {[regexp {<a href=./Sections/Genres[^\n]+} $html genre]} {
regsub {>more<} $genre {} genre
regsub -all {<[^\>]*>} $genre {} genre
regsub {\(.*\)} $genre {} genre
}
## get tagline
if {[regexp {<h5>Tagline:</h5>(.*?)<.*?>} $html dummy tagline]} {
regsub -all {<[^\>]*>} $tagline {} tagline
set tagline [string trim $tagline]
set tagline [htmlcodes $tagline]
}
## get plot
if { [regexp {<h5>Plot Outline:</h5>(.*?)</div>} $html dummy plot] || [regexp {<h5>Plot Summary:</h5>(.*?)</div>} $html dummy plot] } {
regsub {\n} $plot {} plot
regsub {>more<} $plot {} plot
set plot [string map {(more) "" "(view trailer)" "" } $plot]
regsub -all {<[^\>]*>} $plot {} plot
set plot [string trim $plot]
set plot [htmlcodes $plot]
}
## get iMDb rating
if {[regexp {<b>User Rating:</b>.*?<b>(\d.\d/10)</b> \(<a href="ratings">(.*?) votes</a>\)} $html dummy rating votes]} {
#rating bar code
set goldstars [expr round(($rating / 10) * 100)]
set greystars [expr 10 - $goldstars]
# generating the rating bar
set marker "*"
set rating_bar "$barcol1\[$barcol2"
for {set i2 0} {$i2 < $goldstars} {incr i2 1} {
set rating_bar "$rating_bar$marker"
}
set marker "-"
set rating_bar "$rating_bar14"
for {set i3 0} {$i3 < $greystars} {incr i3 1} {
set rating_bar "$rating_bar$marker"
}
set rating_bar "$rating_bar$barcol1\]"
#end rating bar code
}
## get TOP 250
if {[regexp {>Top 250: (.*?)</a>} $html dummy top250]} {
set top250 "\002Top 250:\002 $top250"
} elseif {[regexp {>Bottom 100: (.*?)</a>} $html dummy top250]} {
set top250 "\002Bottom 100:\002 $top250"
}
## get MPAA
if {[regexp {<a href="/mpaa">.*?</h5>(.*?)</div>} $html dummy mpaa]} {
regsub -all {\n} $mpaa {} mpaa
set mpaa [htmlcodes $mpaa]
set mpaa [string trim $mpaa]
}
## get runtime
if {[regexp {<h5>Runtime:</h5>(.*?)</div>} $html dummy runtime]} {
regsub -all {\n} $runtime {} runtime
}
## get awards
if {[regexp {<h5>Awards:</h5>(.*?)<a} $html dummy awards]} {
regsub -all {[\n]} $awards {} awards
set awards [string trim $awards]
set awards [string map {& " & "} $awards]
set awards [htmlcodes $awards]
}
## get country
if {[regexp {<a href=./Sections/Countries[^\n]+} $html country]} {
regsub -all {<[^\>]*>} $country {} country
}
## get language
if {[regexp {<a href=./Sections/Languages[^\n]+} $html language]} {
regsub -all {<[^\>]*>} $language {} language
}
## get soundmix
if {[regexp {<a href=./List.sound-mix=[^\n]+} $html soundmix]} {
regsub -all {<[^\>]*>} $soundmix {} soundmix
}
## get cast
if {[regexp {<table class="cast">(.*?)</div>} $html dummy cast]} {
regsub -all {<td class=\"nm\">} $cast \n cast_multiline
regsub -all {<[^\>]*>} $cast_multiline {} cast_multiline
set cast_multiline [string map {"rest of cast listed alphabetically: " \n} $cast_multiline]
set cast_multiline [htmlcodes $cast_multiline]
set cast_multiline [string trim $cast_multiline]
if { $cast_linelimit > 0 } {
set nthoccur [expr [findnth $cast_multiline \n $cast_linelimit] - 1]
if {$nthoccur > 0} {set cast_multiline [string range $cast_multiline 0 $nthoccur]}
}
}
# do we need the second page?
if {[string match "*%budget*" $output] || [string match "*%screens*" $output]} {
unset html
if { $IMDB_ALTERNATIVE == 0 } {
set page2 [::http::config -useragent "MSIE 6.0"]
catch {set page2 [::http::geturl ${newurl}business -timeout $imdb_timeout]} error
if {[string match -nocase "*couldn't open socket*" $error]} {
puthelp "$toput :Error: couldn't connect..Try again later"
::http::Finish $page2
return
}
if {[::http::status $page2]=="timeout"} {
puthelp "$toput :\002Connection to imdb.com timed out.\002"
::http::Finish $page2
return
}
set html [::http::data $page2]
::http::Finish $page2
} else {
catch { exec $binary(CURL) "${newurl}business" } html
}
## get budget
if {[regexp {<h5>Budget</h5>(.*?)<br/>} $html dummy budget]} {
regsub {\n} $budget {} budget
set budget [string map {€ € £ £ } $budget]
}
## get screens
if {[regexp {<h5>Opening Weekend</h5>(.*?)<br/>} $html dummy screens]} {
regsub -all {\n} $screens {} screens
regsub -all {<a href.*?>} $screens {} screens
regsub -all {</a>} $screens {} screens
}
}
## output results
set output [replacevar $output "%bold" "\002"]
set output [replacevar $output "%color" "\003"]
set output [replacevar $output "%uline" "\037"]
set output [replacevar $output "%title" $title]
set output [replacevar $output "%url" $newurl]
set output [replacevar $output "%name" $name]
set output [replacevar $output "%genre" $genre]
set output [replacevar $output "%tagline" $tagline]
set output [replacevar $output "%plot" $plot]
set output [replacevar $output "%rating" $rating]
set output [replacevar $output "%rbar" $rating_bar]
set output [replacevar $output "%votes" $votes]
set output [replacevar $output "%top250" $top250]
set output [replacevar $output "%mpaa" $mpaa]
set output [replacevar $output "%time" $runtime]
set output [replacevar $output "%awards" $awards]
set output [replacevar $output "%country" $country]
set output [replacevar $output "%language" $language]
set output [replacevar $output "%soundmix" $soundmix]
set output [replacevar $output "%budget" $budget]
set output [replacevar $output "%screens" $screens]
set output [replacevar $output "%castmline" $cast_multiline]
set output [replacevar $output "%wcredits" $wcredits]
foreach line [split $output "\n"] {
if {![regexp N/A $line]} {
#putcmdlog "line2 '$line'"
puthelp "$toput :$line"
}
}
}
proc decr_inst { } {
global instance
if { $instance > 0 } { incr instance -1 }
}
proc wmsg { } {
global warn_msg
set warn_msg 0
}
if { $IMDB_ALTERNATIVE == 0 } { set using "Http Package" } else { set using "Curl" }
putlog "IMDB b+ by OV2 loaded - using \002$using\002"
sometimes its says in partyline
Tcl error [imdb_handler]: can't read "location": no such variable
pls help