This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

imdb-1.1.0.tcl help please

Support & discussion of released scripts, and announcements of new releases.
Post Reply
User avatar
spithash
Master
Posts: 249
Joined: Thu Jul 12, 2007 9:21 am
Location: Libera
Contact:

Post by spithash »

username: it works GREAT :)

Thing is, I'm getting these:

Code: Select all

[17:45:34] <@spithash> !imdb M. Night Shyamalan
[17:45:40] <@nagger> The Sixth Sense (1999) - IMDb - http://www.imdb.com/title/tt0167404/
[17:45:42] <@nagger> Genre: Drama | Mystery | Thriller
[17:45:44] <@nagger> Synopsis: Malcom Crowe is a child psychologist who receives an award on the same night that he is visited by a very unhappy ex-patient. After this encounter, Crowe takes on the task of curing a young boy with the same ills as the ex-patient. This boy "sees dead people". Crowe spends a lot of time with the boy (Cole) much to the dismay of his wife. Cole's mom is at her wit's e
[17:45:46] <@nagger> nd with what to do about her son's increasing problems. Crowe is the boy's only hope.
[17:45:48] <@nagger> Rating: 8.2/10 (242,642 votes) [********--] 28
[17:45:50] <@nagger> Awards:  Nominated for 6 Oscars. Another 31 wins & 37 nominations awards
There are several ' and "
Libera ##rtlsdr & ##re - Nick: spithash
Click here for troll.tcl
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

spithash wrote:username: it works GREAT :)

Thing is, I'm getting these:

Code: Select all

[17:45:34] <@spithash> !imdb M. Night Shyamalan
[17:45:40] <@nagger> The Sixth Sense (1999) - IMDb - http://www.imdb.com/title/tt0167404/
[17:45:42] <@nagger> Genre: Drama | Mystery | Thriller
[17:45:44] <@nagger> Synopsis: Malcom Crowe is a child psychologist who receives an award on the same night that he is visited by a very unhappy ex-patient. After this encounter, Crowe takes on the task of curing a young boy with the same ills as the ex-patient. This boy "sees dead people". Crowe spends a lot of time with the boy (Cole) much to the dismay of his wife. Cole's mom is at her wit's e
[17:45:46] <@nagger> nd with what to do about her son's increasing problems. Crowe is the boy's only hope.
[17:45:48] <@nagger> Rating: 8.2/10 (242,642 votes) [********--] 28
[17:45:50] <@nagger> Awards:  Nominated for 6 Oscars. Another 31 wins & 37 nominations awards
There are several ' and "
It doesn't do transcoding? Why on Earth not?? O_o;;?

Well, add this procedure to the end of the script..(this procedure is ripped from my twitter script).

Code: Select all

proc imdb_decode {text {char "utf-8"} } {
	# code below is neccessary to prevent numerous html markups
	# from appearing in the output (ie, ", ᘧ, etc)
	# stolen (borrowed is a better term) from tcllib's htmlparse ;)
	# works unpatched utf-8 or not, unlike htmlparse::mapEscapes
	# which will only work properly patched....
	set escapes {
		  \xa0 ¡ \xa1 ¢ \xa2 £ \xa3 ¤ \xa4
		¥ \xa5 ¦ \xa6 § \xa7 ¨ \xa8 © \xa9
		ª \xaa « \xab ¬ \xac ­ \xad ® \xae
		¯ \xaf ° \xb0 ± \xb1 ² \xb2 ³ \xb3
		´ \xb4 µ \xb5 ¶ \xb6 · \xb7 ¸ \xb8
		¹ \xb9 º \xba » \xbb ¼ \xbc ½ \xbd
		¾ \xbe ¿ \xbf À \xc0 Á \xc1 Â \xc2
		Ã \xc3 Ä \xc4 Å \xc5 Æ \xc6 Ç \xc7
		È \xc8 É \xc9 Ê \xca Ë \xcb Ì \xcc
		Í \xcd Î \xce Ï \xcf Ð \xd0 Ñ \xd1
		Ò \xd2 Ó \xd3 Ô \xd4 Õ \xd5 Ö \xd6
		× \xd7 Ø \xd8 Ù \xd9 Ú \xda Û \xdb
		Ü \xdc Ý \xdd Þ \xde ß \xdf à \xe0
		á \xe1 â \xe2 ã \xe3 ä \xe4 å \xe5
		æ \xe6 ç \xe7 è \xe8 é \xe9 ê \xea
		ë \xeb ì \xec í \xed î \xee ï \xef
		ð \xf0 ñ \xf1 ò \xf2 ó \xf3 ô \xf4
		õ \xf5 ö \xf6 ÷ \xf7 ø \xf8 ù \xf9
		ú \xfa û \xfb ü \xfc ý \xfd þ \xfe
		ÿ \xff ƒ \u192 Α \u391 Β \u392 Γ \u393 Δ \u394
		Ε \u395 Ζ \u396 Η \u397 Θ \u398 Ι \u399
		Κ \u39A Λ \u39B Μ \u39C Ν \u39D Ξ \u39E
		Ο \u39F Π \u3A0 Ρ \u3A1 Σ \u3A3 Τ \u3A4
		Υ \u3A5 Φ \u3A6 Χ \u3A7 Ψ \u3A8 Ω \u3A9
		α \u3B1 β \u3B2 γ \u3B3 δ \u3B4 ε \u3B5
		ζ \u3B6 η \u3B7 θ \u3B8 ι \u3B9 κ \u3BA
		λ \u3BB μ \u3BC ν \u3BD ξ \u3BE ο \u3BF
		π \u3C0 ρ \u3C1 ς \u3C2 σ \u3C3 τ \u3C4
		υ \u3C5 φ \u3C6 χ \u3C7 ψ \u3C8 ω \u3C9
		ϑ \u3D1 ϒ \u3D2 ϖ \u3D6 • \u2022
		… \u2026 ′ \u2032 ″ \u2033 ‾ \u203E
		⁄ \u2044 ℘ \u2118 ℑ \u2111 ℜ \u211C
		™ \u2122 ℵ \u2135 ← \u2190 ↑ \u2191
		→ \u2192 ↓ \u2193 ↔ \u2194 ↵ \u21B5
		⇐ \u21D0 ⇑ \u21D1 ⇒ \u21D2 ⇓ \u21D3 ⇔ \u21D4
		∀ \u2200 ∂ \u2202 ∃ \u2203 ∅ \u2205
		∇ \u2207 ∈ \u2208 ∉ \u2209 ∋ \u220B ∏ \u220F
		∑ \u2211 − \u2212 ∗ \u2217 √ \u221A
		∝ \u221D ∞ \u221E ∠ \u2220 ∧ \u2227 ∨ \u2228
		∩ \u2229 ∪ \u222A ∫ \u222B ∴ \u2234 ∼ \u223C
		≅ \u2245 ≈ \u2248 ≠ \u2260 ≡ \u2261 ≤ \u2264
		≥ \u2265 ⊂ \u2282 ⊃ \u2283 ⊄ \u2284 ⊆ \u2286
		⊇ \u2287 ⊕ \u2295 ⊗ \u2297 ⊥ \u22A5
		⋅ \u22C5 ⌈ \u2308 ⌉ \u2309 ⌊ \u230A
		⌋ \u230B 〈 \u2329 〉 \u232A ◊ \u25CA
		♠ \u2660 ♣ \u2663 ♥ \u2665 ♦ \u2666
		" \x22 & \x26 < \x3C > \x3E O&Elig; \u152 œ \u153
		Š \u160 š \u161 Ÿ \u178 ˆ \u2C6
		˜ \u2DC   \u2002   \u2003   \u2009
		‌ \u200C ‍ \u200D ‎ \u200E ‏ \u200F – \u2013
		— \u2014 ‘ \u2018 ’ \u2019 ‚ \u201A
		“ \u201C ” \u201D „ \u201E † \u2020
		‡ \u2021 ‰ \u2030 ‹ \u2039 › \u203A
		€ \u20AC &apos; \u0027 ‎ "" ‏ "" 
	};
	if {![string equal $char [encoding system]]} { set text [encoding convertfrom $char $text] }
	set text [string map [list "\]" "\\\]" "\[" "\\\[" "\$" "\\\$" """ "\\"" "\" "\\\"] [string map -nocase $escapes $text]]
	regsub -all -- {&#([[:digit:]]{1,5});} $text {[format %c [string trimleft "\1" "0"]]} text
	regsub -all -- {&#x([[:xdigit:]]{1,4});} $text {[format %c [scan "\1" %x]]} text
	catch { set text "[subst "$text"]" }
	if {![string equal $char [encoding system]]} { set text [encoding convertto $char $text] }
	return "$text"
}
Then find this code...

Code: Select all

foreach line [split $output "\n"] {
Change it to look like this...

Code: Select all

foreach line [split [imdb_decode $output] "\n"] {
Now it will transcode html entities correctly.
<@bionic> Тёмный рыцарь (2008) - IMDb (Batman: The Dark Knight) - http://www.imdb.com/title/tt0468569/
Yes, it will even render that Russian correctly now. :)
User avatar
spithash
Master
Posts: 249
Joined: Thu Jul 12, 2007 9:21 am
Location: Libera
Contact:

Post by spithash »

speechles: I get this after doing so,

Code: Select all

[19:58:16] <nagger> [19:58] Tcl error [imdb_proc]: invalid command name "imdb_decode"
[19:58:31] <nagger> [19:58] Tcl error in script for 'timer2':
[19:58:31] <nagger> [19:58] invalid command name "decr_inst"
Libera ##rtlsdr & ##re - Nick: spithash
Click here for troll.tcl
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Are you sure you followed my full post and advice? --reread it again to be sure--

The procedure name I use _is_ imdb_decode. I told you to put it at the end, which _would_ make a difference if we were compiling it. As references to objects need to have the object defined before you can reference the object. Unless that object is the object referencing itself, such as recursion. But being as tcl is interpreted, it shouldn't matter where you place procedures or make invocations.

The other error you get is coming from something else:

Code: Select all

[19:58:31] <nagger> [19:58] Tcl error in script for 'timer2':
[19:58:31] <nagger> [19:58] invalid command name "decr_inst" 
Where a timer/utimer is being called and invoking a procedure "decr_inst" which doesnt't exist. Possibly a required package missing without the package being required?
Last edited by speechles on Wed Oct 27, 2010 8:16 pm, edited 1 time in total.
User avatar
spithash
Master
Posts: 249
Joined: Thu Jul 12, 2007 9:21 am
Location: Libera
Contact:

Post by spithash »

Code: Select all

###############################################################################
##     This iMDB.tcl requires Eggdrop1.6.0 or higher                         ##
##                  (c) 2003 by B0unTy                                       ##
##                                                                           ##
##  changed by username                                                      ##
##  19.10.2010                                                               ##
##  *fixed page parsing errors                                               ##
##                                                                           ##
##  changed by OV2                                                           ##
##  05.01.2010                                                               ##
##    *fixed remaining bugs with imdb changes                                ##
##                                                                           ##
##  02.01.2010                                                               ##
##    *modified for imdb page changes                                        ##
##                                                                           ##
##  16.09.2008                                                               ##
##    *modified for new imdb page                                            ##
##                                                                           ##
##  25.05.2008                                                               ##
##    *plot works again                                                      ##
##                                                                           ##
##  19.05.2008                                                               ##
##    *fixed the non-working cookies (cert, soundmix ...)                    ##
##    * "|" characters in cookies are displayed again                        ##
##                                                                           ##
##  21.09.2007                                                               ##
##    *multiline color/underline/bold were broken                            ##
##    +added single-line cast (%castline)                                    ##
##    +added the remaining information from imdb (color, cert, etc...)       ##
##                                                                           ##
##  17.07.2007                                                               ##
##    *fix for the exact title matching                                      ##
##    *exact name matches are no longer confused with exact title matches    ##
##                                                                           ##
##  27.06.2007                                                               ##
##    *works with new imdb search page                                       ##
##    *%uline works again                                                    ##
##                                                                           ##
##  09.04.2007:                                                              ##
##    *fixed director/s writer/s                                             ##
##    +added support for plot keywords                                       ##
##    +added support for user comment line                                   ##
##                                                                           ##
##  28.02.2007:                                                              ##
##    *ratings work again                                                    ##
##    *director and writing credits work again                               ##
##                                                                           ##
##  25.02.2007:                                                              ##
##    *fixed some bugs of the previous changes (thanks to rosc2112)          ##
##                                                                           ##
##  24.02.2007:                                                              ##
##    *bold/underline/color in front of the multiline cast will now be       ##
##     applied to each of the cast lines                                     ##
##    *the | character is now used to declare sections in the announce line  ##
##     if any variable in a section is not found on the imdb page, the       ##
##     corresponding section will not be displayed in the output             ##
##     (see the default announce line for an example)                        ##
##                                                                           ##
##  22.02.2007:                                                              ##
##    *incorporated some code from rosc2112's version                        ##
##    *some small fixes                                                      ##
##                                                                           ##
##  20.02.2007:                                                              ##
##    *changed regexp queries to accomodate the new imdb layout              ##
##    *cleaned up the unneccesary post-regexp code                           ##
##                                                                           ##
##  14.05.2006:                                                              ##
##    *fixed plot outline not showing completely if it included links        ##
##      (thanks to darkwing for finding the bug)                             ##
##    +added support for awards (thanks to rosc2112)                         ##
##    +added support for the cast list (be careful with the limit)           ##
##    +added support for writing credits                                     ##
##                                                                           ##
##  21.01.2006:                                                              ##
##    *fixed problem with irregular search-result pages from imdb            ##
##                                                                           ##
##  31.08.2005:                                                              ##
##    *changed search result priority again:                                 ##
##      1. popular match where the title=search string                       ##
##      2. exact matches                                                     ##
##      3. first title on page                                               ##
##    *fixed missig warn_msg var                                             ##
##                                                                           ##
##  until 24.06.2005:                                                        ##
##    *works with new IMDB                                                   ##
##    *works with (hopefully) all search results (popular/exact/partial)     ##
##    +added timeouts (20secs)                                               ##
##    +added bottom 100 support                                              ##
##    +added rating bar from chilla's imdb-script                            ##
##    +added flood control                                                   ##
##    *small speedup (if your output does not include %screens or %budget    ##
##    *changed proc name to improve compatibility with other scripts         ##
##    *changed search result priority to {exact->first displayed}            ##
##                                                                           ##
###############################################################################
##                                                                           ##
## INSTALL:                                                                  ##
## ========                                                                  ##
##   1- Copy iMDB.tcl in your dir scripts/                                   ##
##   2- Add iMDB.tcl in your eggdrop.conf:                                   ##
##        source scripts/imdb.tcl                                            ##
##                                                                           ##
##   For each channel you want users to use !imdb cmd                        ##
##   Just type in partyline: .chanset #channel +imdb                         ##
##                                                                           ##
###############################################################################
# COOKIES ARE :
# =============
# TITLE             = %title               |    BOLD           = %bold
# URL               = %url                 |    UNDERLINE      = %uline
# DIRECTOR          = %name                |    COLORS         = %color#,#
# GENRE             = %genre               |    NEW LINE       = \n
# PLOT OUTLINE      = %plot                |-----------------------------
# RATING            = %rating              |    !! to reset color code !!
# RATING_BAR        = %rbar                |    !! use %color w/o args !!
# VOTES             = %votes               |
# RUNTIME           = %time (numbers only) |    "|" declares a section
# AWARDS            = %awards              |    if any cookie in a section
# BUDGET            = %budget              |    is empty the whole section
# SCREENS           = %screens             |    is removed from the output
# TAGLINE           = %tagline             |    (end section with "|")
# MPAA              = %mpaa                |
# COUNTRY           = %country             |
# LANGUAGE          = %language            |
# SOUND MIX         = %soundmix            |
# TOP 250           = %top250              |
# CAST LINES        = %castmline           |
# CAST SNGLELINE    = %castline            |
# WRITING CREDITS   = %wcredits            |
# PLOT KEYWORDS     = %keywords            |
# COMMENT LINE      = %comment             |
# RELEASE DATE      = %reldate             |
# MOVIE COLOR       = %mcolor              |
# ASPECT RATIO      = %aspect              |
# CERTIFICATION     = %cert                |
# LOCATIONS         = %locations           |
# COMPANY           = %company             |
#
# + 19.10.2010
# Also Known As     = %aka
#
# 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.

# example normal announce:
# set announce(IMDBIRC) "%bold%title%bold - %url\n|Rating: %rating (%votes votes) %rbar| |%top250|\n|%plot|"
# set announce(IMDBIRC) "%bold%title%bold |\[%time mins - %mcolor\]| - %url\n|Genre: %genre|\n|Tagline: %tagline|\n|Synopsis: %plot|\n|Rating: %rating (%votes votes) %rbar| |%color3%top250%color|\n|Awards: %awards|"

#set announce(IMDBIRC) "%bold%title%bold - %url\n|%boldGenre:%bold %genre|\n|Plot %boldKeywords:%bold %keywords|\n|%boldTagline:%bold %tagline|\n|%boldSynopsis:%bold %plot|\n|%boldRating:%bold %rating (%votes votes) %rbar| |%color3%top250%color|\n|%boldComment:%bold %comment|\n|%boldAwards:%bold %awards|\n|%boldRuntime:%bold %time mins.|"
#set announce(IMDBIRC) "%bold%title%bold (%aka) - %url\n|%boldGenre:%bold %genre|\n|Director: %name|\n|Writers: %wcredits|\n|Release Date: %reldate|\n|Cast: %castline|\n|Country: %country|\n|Language: %language|\n|Color: %mcolor|\n|Plot Keywords: %keywords|\n|Tagline: %tagline|\n|Synopsis: %plot|\n|Rating: %rating (%votes votes) %rbar|\n|Top 250: %color03%top250%color|\n|Locations: %locations|\n|Comment: %comment|\n|Awards: %awards|\n|Runtime: %time.|\n|MPAA: %mpaa|\n|Sound Mix: %soundmix|\n|Aspect Ratio: %aspect|\n|Company: %company|\n|Budget: %budget|\n|Screens: %screens|"
set announce(IMDBIRC) "%bold%title%bold - %url\n|%boldGenre:%bold %genre|\n|%boldSynopsis:%bold %plot|\n|%boldRating:%bold %rating (%votes votes) %rbar| |%color3%top250%color|\n|%boldAwards:%bold %awards|\n|"

#trigger command in channel
set trigger "!imdb"

#rating bar color
#bracket
set barcol1 "14"
#stars
set barcol2 "7"
#cast count to return on multiline and single line (0 means no limit)
set cast_linelimit "5"

#http connection timeout (milliseconds)
set imdb_timeout "25000"

#flood-control
set queue_enabled 1
#max requests
set queue_size 4
#per ? seconds
set queue_time 20

# for a channel !imdb request
# set to 1 = all results will be sent publicly to the channel
# set to 0 = all results will be sent as private notice
set pub_or_not 1

# use or not the imdb debugger (1=enable debug  0=disable debug)
set IMDB_DEBUG 0

# set IMDB_ALTERNATIVE 0 = use the internal tcl http 2.3 package
# set IMDB_ALTERNATIVE 1 = use the external curl 6.0+
set IMDB_ALTERNATIVE 0

# set here the location path where find curl 6.0+
set binary(CURL) "/path/to/curl"
# note for windrop: use normal slashes, e.g. C:/path/to/curl.exe

#################################################################
# DO NOT MODIFY BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING!  #
#################################################################
if { $IMDB_ALTERNATIVE == 0 } { package require http 2.3 }
setudef flag imdb

bind pub -|- $trigger imdb_proc

set instance 0
set warn_msg 0

proc htmlcodes {tempfile} {
#    set mapfile [string map {" \" & & ' ' ' ' [ ( \ / ] ) { ( } )   " " ? ? ? ? © © « « ­ ­ ® ® ? ? ? ? } $tempfile]
#    set mapfile [string map {? ? · · ^(1) ^(1) » » 1/4 1/4 1/2 1/2 3/4 3/4 A` A` A' A' A^ A^ } $mapfile]
#    set mapfile [string map {A~ A~ A" A" A* A* ? ? C, C, E` E` E' E' E^ E^ E" E" I` I` I' I' I^ I^ I" I" ? ? N~ N~ O` O` O' O' O^ O^ O~ O~ O" O" } $mapfile]
#    set mapfile [string map {? ? ? ? U` U` U' U' U^ U^ U" U" Y' Y' ? ? ? ? a` a` a' a' a^ a^ a~ a~ a" a" a* a* ? ? c, c, e` e` e' e' e^ e^ } $mapfile]
#    set mapfile [string map {e" e" i` i` i' i' i^ i^ i" i" ? ? n~ n~ o` o` o' o' o^ o^ o~ o~ o" o" ? ? ? ? u` u` u' u' u^ u^ u" u" y' y' ? ? } $mapfile]
     set mapfile [string map {  "" & "&" " \"} $tempfile]
    return $mapfile
} 

proc channel_check_imdb { chan } {
    foreach setting [channel info $chan] {
        if {[regexp -- {^[\+-]} $setting]} {
            if {![string compare "+imdb" $setting]} {
                set permission 1
                break
            } else {
                set permission 0
            }
        }
    }
    return $permission
}

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_timeout barcol1 barcol2 IMDB_DEBUG pub_or_not announce random warn_msg trigger binary IMDB_ALTERNATIVE
    # channel_check permission
    set permission_result [channel_check_imdb $chan]
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG permission_result == $permission_result" }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG instance == $instance" }
    if { $permission_result == 0} { return }
    # public or private
    if {$pub_or_not == 1 } { set toput "PRIVMSG $chan" } else { set toput "NOTICE $nick" }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG toput_result == $toput" }
    # if no arg passed, show help
    if {$arg == ""} {
        if { $IMDB_ALTERNATIVE == 0 } { set using "Http 2.3+" } else { set using "Curl 6.0+" }
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG no arg passed, show help" }
        puthelp "$toput :IMDb info script \002v05.01.2010\002 using \002$using\002"
        puthelp "$toput :\002Syntax: $trigger <movie title>\002 example: $trigger Beautiful Mind"
        return
    }

    #flood-control
    if { $queue_enabled == 1 } {
       #flooded?
       if { $instance >= $queue_size } {
          if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG flood detected" }
          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
       if { $IMDB_DEBUG == 1 } { putlog "IMDB_DEBUG new instance == $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} $arg]
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG searchString: \"$searchString\"" }
    if { $IMDB_ALTERNATIVE == 0 } {
        set page [::http::config -useragent "MSIE 6.0"]
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG ${imdbsearchurl}q=$searchString" }
        if [catch {set page [::http::geturl ${imdbsearchurl}q=$searchString -timeout $imdb_timeout]} error] {
            puthelp "$toput :Error retrieving URL... 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 (search page), find first link and redirect
    if { ([regexp {<title>IMDb.*Search} $html] == 1) } {
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG redirect 1" }
        set ttcode "0000001"
        set start "0"
        set temp $html

        #dealing with different search results
        set hit 0
        if { [regexp -indices {Popular Titles} $temp tstart] } {
           if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG found popular titles" }
           set temp2 [string range $temp [lindex $tstart 1] end]
           regexp {1\..*?<a.*?>(.*?)</a>} $temp2 dummy title
           if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG compare $title == $arg" }
           if { [string equal -nocase $title $arg] } {
              if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG equals - displaying first popular match" }
              set temp $temp2
              set hit 1
           } else {
              if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG not equal - searching for exact match" }
           }

        }
        if { $hit == 0 } {
           if { [regexp -indices {Titles \(Exact Matches\)} $temp start] } {
              if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG displaying exact match" }
           } elseif { [regexp -indices {Titles} $temp start] } {
              if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG no exact match - displaying first title on page" }
           } else {
                puthelp "$toput :No useful results."
                if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG no titles results found" }
                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 :No no no! I can't find that!"
            if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG bogus ttcode" }
            return
        }
        set newurl "$imdburl/title/$ttcode/"
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG redirect 1 = $newurl" }
        # get the page redirected to
        unset html
        if { $IMDB_ALTERNATIVE == 0 } {
            set page [::http::config -useragent "MSIE 6.0"]
            set page [::http::geturl $newurl -timeout $imdb_timeout]
            if [catch {set page [::http::geturl $newurl -timeout $imdb_timeout]} error] {
                puthelp "$toput :Error retrieving URL... 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 necessary (only one match in meta), then go there
    } else {
        set location ""
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG redirect 0" }
        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]
            putlog $oldpage
            regexp {title/tt[0-9]+/} $oldpage location
        }
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG redirect 0 Location == $location" }
        set newurl "$imdburl/$location"
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG redirect 0 = $newurl" }
        if { $location != "" } {
            if { $IMDB_ALTERNATIVE == 0 } {
                unset html
                set page [::http::config -useragent "MSIE 6.0"]
                if [catch {set page [::http::geturl $newurl -timeout $imdb_timeout]} error] {
                    puthelp "$toput :Error retrieving URL... 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 :Error in search mechanics - you probably need a newer version."
            return
        }

    }
    # for bogus searches
    if {[string length $newurl] == 0} {
        puthelp "$toput :No no no! I can't find that!"
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG bogus searches" }
        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 aka "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 "top/bottom:N/A"; set awards "N/A"; set rating_bar ""; set cast_multiline "N/A"; set wcredits "N/A";
    set keywords "N/A"; set comment "N/A"; set reldate "N/A"; set cast_line "N/A"; set movie_color "N/A"; set aspect_ratio "N/A";
    set cert "N/A"; set film_locations "N/A"; set company "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]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG title == $title" }
    
    ## get aka
    if [regexp {<h4 class="inline">Also Known As:</h4>(.*?)</div>} $html dummy aka] {
        regsub -all {<[^\>]*>} $aka {} aka
        set aka [string map {"See more" "" \n "" & " & " » ""} $aka]
        set aka [string trim $aka]
        set aka [htmlcodes $aka]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG aka == $aka" }
  
    ## get director
    if [regexp {<h4 class="inline">.*?Director:.*?</h4>(.*?)</div>} $html dummy name] {
        regsub -all {\n[ ]*} $name {} name
        set name [string map {"&<br/>" "& " "<br/>" ", " "See more" ""} $name]
        regsub -all {<[^>]+>} $name {} name
        set name [string trim $name]
        regsub -all {,$} $name {} name
        set name [htmlcodes $name]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG director == $name" }
    ## get writing credits
    if [regexp {<h4 class="inline">.*?Writers:.*?</h4>(.*?)</div>} $html dummy wcredits] {
        regsub -all {\n[ ]*} $wcredits {} wcredits
        set wcredits [string map {"See more" "" "<br/> " "" "&<br/>" "& " "&<br/>" "& " "<br/>" ", " "»" ""} $wcredits]
        regsub -all {<[^>]+>} $wcredits {} wcredits
        set wcredits [string trim $wcredits]
        regsub -all {,$} $wcredits {} wcredits
        set wcredits [htmlcodes $wcredits]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG writer == $wcredits" }
    # release date
    if {[regexp {<h4 class="inline">Release Date:</h4>(.*?)</div>} $html dummy reldate]} {
        regsub -all {<[^\>]*>} $reldate {} reldate
        set reldate [string map {"See more" "" \n "" & " & "} $reldate]
        set reldate [string trim $reldate]
        set reldate [htmlcodes $reldate]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG release date == $reldate" }
    ## get genre
    if [regexp {<h4 class="inline">Genres:</h4>(.*?)</div>} $html dummy genre] {
        set genre [string map {"See more" ""   " "} $genre]
        regsub -all {<[^\>]*>} $genre {} genre
        set genre [string map {"|" "||" } $genre]
        set genre [string trim $genre]
        regsub {\(.*\)} $genre {} genre
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG genre == $genre" }
    ## get tagline
    if [regexp {<h4 class="inline">Taglines:</h4>(.*?)<span .*?>} $html dummy tagline] {
        set tagline [string map {"See more" "" } $tagline]
        regsub -all {<[^\>]*>} $tagline {} tagline
        set tagline [string trim $tagline]
        set tagline [htmlcodes $tagline]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG tagline == $tagline" }
    ## get plot outline
    if { [regexp {<h2>Storyline</h2>(.*?)<em .*?>} $html dummy plot] || [regexp {<h5>Plot Summary:</h5>(.*?)</div>} $html dummy plot] } {
        set plot [string map {"See more" "" "(view trailer)" "" "full summary" "" "add synopsis" "" "full synopsis (warning! may contain spoilers)" "" "full synopsis" "" " | " ""} $plot]
        regsub -all {<[^\>]*>} $plot {} plot
        set plot [string trim $plot]
        set plot [htmlcodes $plot]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG plot == $plot" }
    ## get plot keywords
    if [regexp {<h4 class="inline">Plot Keywords:</h4>(.*?)</div>} $html dummy keywords] {
       set keywords [string map {"See more" "" \n ""   " " » ""} $keywords]
       regsub -all {<[^\>]*>} $keywords {} keywords
       set keywords [string map {"|" "||"} $keywords]
       set keywords [string trim $keywords]
       set keywords [htmlcodes $keywords]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG keywords == $keywords" }
    ## get awards
    if [regexp {<strong>Top 250 .*?</strong></a>(.*?)</div>} $html dummy awards] {
       set awards [string map {"See more" "" \n "" » ""} $awards]
       regsub -all {<[^\>]*>} $awards { } awards
       set awards [string trim [join $awards]]
       set awards [htmlcodes $awards]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG awards == $awards" }
    ## get comment
    if [regexp {<h2>User Reviews</h2>(.*?)</strong>} $html dummy comment] {
       set comment [string map {"See more" "" \n ""} $comment]
       regsub -all {<[^\>]*>} $comment {} comment
       set comment [string trim [join $comment]]
       set comment [htmlcodes $comment]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG comment == $comment" }
    ## get iMDb rating

                                                                
    if [regexp {<b>((.*?)</b><span class="mellow">/10)</span>.*?<a .*? href="ratings".*?>(.*?) votes</a>} $html dummy rating goldstars votes] {

        regsub -all {<[^\>]*>} $rating {} rating
        #rating bar code
        set goldstars [expr round($goldstars)]
        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

    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG rating == $rating | votes == $votes | rating bar == $rating_bar" }
    ## get TOP 250
    if [regexp {<strong>Top 250 #([\d]+)</strong>} $html dummy top250] {
    } elseif [regexp {>(Bottom 100: #[\d]+)</a>} $html dummy top250] {
    }

    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG top250 == $top250" }
    ## get MPAA
    if [regexp {<h4>Motion Picture Rating.*?</h4>(.*?)<span .*?>} $html dummy mpaa] {
        regsub -all {<[^\>]*>} $mpaa {} mpaa
        #regsub {MPAA: } $mpaa {} mpaa
        set mpaa [string trim $mpaa]
        set mpaa [htmlcodes $mpaa]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG mpaa == $mpaa" }
    ## get runtime
    if [regexp {<h4 class="inline">Runtime:</h4>(.*?)</div>} $html dummy runtime] {
        regsub -all {[\n\s]+} $runtime {} runtime
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG runtime == $runtime" }
    ## get country
    if [regexp {<h4 class="inline">Country:</h4>(.*?)</div>} $html dummy country] {
        set country [string map {  " "} $country]
        regsub -all {<[^\>]*>} $country {} country
        set country [string map {"|" "||" } $country]
        regsub -all {[\n]+} $country {} country
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG country == $country" }
    ## get language
    if [regexp {<h4 class="inline">Language:</h4>(.*?)</div>} $html dummy language] {
        set language [string map {"See more" "" \n ""   " " » ""} $language]
        regsub -all {<[^\>]*>} $language {} language
        regsub -all {[\n]+} $language {} language
        set language [string map {"|" "||"} $language]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG language == $language" }
    ## get movie color
    if [regexp {<h4 class="inline">Color:</h4>(.*?)</div>} $html dummy movie_color] {
        regsub -all {<[^\>]*>} $movie_color {} movie_color
        regsub -all {[\n\s]+} $movie_color {} movie_color
        set movie_color [string trim $movie_color]
        set movie_color [string map {"|" "||"} $movie_color]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG movie_color == $movie_color" }
    ## get aspect ratio
    if [regexp {<h4 class="inline">Aspect Ratio:</h4>(.*?)</div>} $html dummy aspect_ratio] {
        regsub -all {<[^\>]*>} $aspect_ratio {} aspect_ratio
        set aspect_ratio [string map {"more" "" } $aspect_ratio]
        set aspect_ratio [string trim $aspect_ratio]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG aspect_ratio == $aspect_ratio" }
    ## get soundmix
    if [regexp {<h4 class="inline">Sound Mix:</h4>(.*?)</div>} $html dummy soundmix] {
        set soundmix [string map {"See more" "" \n ""   "" » ""} $soundmix]
        regsub -all {<[^\>]*>} $soundmix {} soundmix
        regsub -all {[\n]+} $soundmix {} soundmix
        set soundmix [string map {"|" "||"} $soundmix]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG soundmix == $soundmix" }
    ## get certification
    if [regexp {<h5>Certification:</h5>\n(.*?)</div>} $html dummy cert] {
        regsub -all {<[^\>]*>} $cert {} cert
        regsub -all {[\n]+} $cert {} cert
        set cert [string map {"|" "||"} $cert]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG cert == $cert" }
    ## get locations
    if { [regexp {<h4 class="inline">Filming Locations:</h4>(.*?)</div>} $html dummy film_locations] } {
        set film_locations [string map {"See more" ""  » ""} $film_locations]
        regsub -all {<[^\>]*>} $film_locations {} film_locations
        regsub -all {[\n\s]+} $film_locations { } film_locations
        set film_locations [string trim $film_locations]
        set film_locations [htmlcodes $film_locations]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG film_locations == $film_locations" }
    ## get company
    if [regexp {<h3>Company Credits</h3>(.*?)</div>} $html dummy company] {
        set company [string map {"See more" ""   "" » ""} $company]
        regsub -all {<[^\>]*>} $company {} company
        regsub -all {[\n\s]+} $company { } company

        set company [string trim $company]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG company == $company" }
   
    ## get cast
    if [regexp {<table class="cast_list">(.*?)</table>} $html dummy cast] {
        regsub -all {</tr>.*?<tr.*?>} $cast "\n" cast_multiline
        regsub -all {[\n]+} $cast_multiline {} cast_multiline
        regsub -all {<[^\>]*>} $cast_multiline {} cast_multiline
        set cast_multiline [string map {"rest of cast listed alphabetically:" \n} $cast_multiline]
        set cast_multiline [string trim [join [htmlcodes $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]}
        }
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG cast_multiline == $cast_multiline" }
    ## fill singleline
    regsub -all {\n} $cast_multiline " / " cast_line
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG cast_line == $cast_line" }

        ## get budget
        if [regexp {<h4 class="inline">Budget:</h4> (.*?)</div>} $html dummy budget] {
           regsub -all {[\n]+} $budget {} budget
           set budget [string map {&#136; &#136; ? ?} $budget]
        }
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG budget == $budget" }
        ## get screens
        if [regexp {<h4 class="inline">Opening Weekend:</h4>\n(.*?Screens\))} $html dummy screens] {
           regsub -all {[\n]+} $screens { } screens
           regsub -all {<[^\>]*>} $screens {} screens
           set screens [htmlcodes $screens]
        }
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG screens == $screens" }

    ## output results
   
    set output [replacevar $output "%title" $title]
    set output [replacevar $output "%aka" $aka]
    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 "%keywords" $keywords]
    set output [replacevar $output "%awards" $awards]
    set output [replacevar $output "%comment" $comment]
    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 "%country" $country]
    set output [replacevar $output "%language" $language]
    set output [replacevar $output "%mcolor" $movie_color]
    set output [replacevar $output "%aspect" $aspect_ratio]
    set output [replacevar $output "%soundmix" $soundmix]
    set output [replacevar $output "%cert" $cert]
    set output [replacevar $output "%locations" $film_locations]
    set output [replacevar $output "%company" $company]
    set output [replacevar $output "%budget" $budget]
    set output [replacevar $output "%screens" $screens]
    set output [replacevar $output "%reldate" $reldate]
    set checkvar ""
    regexp {.*?%castmline} $output checkvar
    if { [expr [regexp -all {%uline} $checkvar] % 2] == 1 } {
        set cast_multiline [string map {"\n" "\n%uline"} $cast_multiline]
    }
    if { [expr [regexp -all {%bold} $checkvar] % 2] == 1 } {
        set cast_multiline [string map {"\n" "\n%bold"} $cast_multiline]
    }
    if { [regexp {.*%color([\d]+(?:,[\d]+)?)[^\n]*?%castmline} $checkvar dummy colormline] } {
        regsub -all {\n} $cast_multiline "\n%color$colormline" cast_multiline
    }
    set output [replacevar $output "%castmline" $cast_multiline]
    set output [replacevar $output "%castline" $cast_line]
    set output [replacevar $output "%wcredits" $wcredits]
    regsub -all {\|[^\|]*?N/A[^\|]*?\|} $output "" output
    set output [string map {"||" "|" "|" ""} $output]
    regsub -all {\n[\n\s]*\n} $output "\n" output
    set output [string trim $output]
    set output [replacevar $output "%bold" "\002"]
    set output [replacevar $output "%color" "\003"]
    set output [replacevar $output "%uline" "\037"]
#    foreach line [split $output "\n"] {
    foreach line [split [imdb_decode $output] "\n"] {
        while {$line != ""} {
            puthelp "$toput :[string range $line 0 399]"
            set line [string range $line 400 end]
        } 
    }
}

proc decr_inst { } {
     global IMDB_DEBUG instance
     if { $instance > 0 } { incr instance -1 }
     if { $IMDB_DEBUG == 1 } { putlog "IMDB_DEBUG instance decreased by timer to: $instance" }
}

proc wmsg { } {
     global warn_msg
     set warn_msg 0
}
proc imdb_decode {text {char "utf-8"} } {
   # code below is neccessary to prevent numerous html markups
   # from appearing in the output (ie, ", ?, etc)
   # stolen (borrowed is a better term) from tcllib's htmlparse ;)
   # works unpatched utf-8 or not, unlike htmlparse::mapEscapes
   # which will only work properly patched....
   set escapes {
        \xa0 ¡ \xa1 ¢ \xa2 £ \xa3 ¤ \xa4
      ¥ \xa5 ¦ \xa6 § \xa7 ¨ \xa8 © \xa9
      ª \xaa « \xab ¬ \xac ­ \xad ® \xae
      ¯ \xaf ° \xb0 ± \xb1 ² \xb2 ³ \xb3
      ´ \xb4 µ \xb5 ¶ \xb6 · \xb7 ¸ \xb8
      ¹ \xb9 º \xba » \xbb ¼ \xbc ½ \xbd
      ¾ \xbe ¿ \xbf À \xc0 Á \xc1 Â \xc2
      Ã \xc3 Ä \xc4 Å \xc5 Æ \xc6 Ç \xc7
      È \xc8 É \xc9 Ê \xca Ë \xcb Ì \xcc
      Í \xcd Î \xce Ï \xcf Ð \xd0 Ñ \xd1
      Ò \xd2 Ó \xd3 Ô \xd4 Õ \xd5 Ö \xd6
      × \xd7 Ø \xd8 Ù \xd9 Ú \xda Û \xdb
      Ü \xdc Ý \xdd Þ \xde ß \xdf à \xe0
      á \xe1 â \xe2 ã \xe3 ä \xe4 å \xe5
      æ \xe6 ç \xe7 è \xe8 é \xe9 ê \xea
      ë \xeb ì \xec í \xed î \xee ï \xef
      ð \xf0 ñ \xf1 ò \xf2 ó \xf3 ô \xf4
      õ \xf5 ö \xf6 ÷ \xf7 ø \xf8 ù \xf9
      ú \xfa û \xfb ü \xfc ý \xfd þ \xfe
      ÿ \xff ƒ \u192 Α \u391 Β \u392 Γ \u393 Δ \u394
      Ε \u395 Ζ \u396 Η \u397 Θ \u398 Ι \u399
      Κ \u39A Λ \u39B Μ \u39C Ν \u39D Ξ \u39E
      Ο \u39F Π \u3A0 Ρ \u3A1 Σ \u3A3 Τ \u3A4
      Υ \u3A5 Φ \u3A6 Χ \u3A7 Ψ \u3A8 Ω \u3A9
      α \u3B1 β \u3B2 γ \u3B3 δ \u3B4 ε \u3B5
      ζ \u3B6 η \u3B7 θ \u3B8 ι \u3B9 κ \u3BA
      λ \u3BB μ \u3BC ν \u3BD ξ \u3BE ο \u3BF
      π \u3C0 ρ \u3C1 ς \u3C2 σ \u3C3 τ \u3C4
      υ \u3C5 φ \u3C6 χ \u3C7 ψ \u3C8 ω \u3C9
      ϑ \u3D1 ϒ \u3D2 ϖ \u3D6 • \u2022
      … \u2026 ′ \u2032 ″ \u2033 ‾ \u203E
      ⁄ \u2044 ℘ \u2118 ℑ \u2111 ℜ \u211C
      ™ \u2122 ℵ \u2135 ← \u2190 ↑ \u2191
      → \u2192 ↓ \u2193 ↔ \u2194 ↵ \u21B5
      ⇐ \u21D0 ⇑ \u21D1 ⇒ \u21D2 ⇓ \u21D3 ⇔ \u21D4
      ∀ \u2200 ∂ \u2202 ∃ \u2203 ∅ \u2205
      ∇ \u2207 ∈ \u2208 ∉ \u2209 ∋ \u220B ∏ \u220F
      ∑ \u2211 − \u2212 ∗ \u2217 √ \u221A
      ∝ \u221D ∞ \u221E ∠ \u2220 ∧ \u2227 ∨ \u2228
      ∩ \u2229 ∪ \u222A ∫ \u222B ∴ \u2234 ∼ \u223C
      ≅ \u2245 ≈ \u2248 ≠ \u2260 ≡ \u2261 ≤ \u2264
      ≥ \u2265 ⊂ \u2282 ⊃ \u2283 ⊄ \u2284 ⊆ \u2286
      ⊇ \u2287 ⊕ \u2295 ⊗ \u2297 ⊥ \u22A5
      ⋅ \u22C5 ⌈ \u2308 ⌉ \u2309 ⌊ \u230A
      ⌋ \u230B 〈 \u2329 〉 \u232A ◊ \u25CA
      ♠ \u2660 ♣ \u2663 ♥ \u2665 ♦ \u2666
      " \x22 & \x26 < \x3C > \x3E O&Elig; \u152 œ \u153
      Š \u160 š \u161 Ÿ \u178 ˆ \u2C6
      ˜ \u2DC   \u2002   \u2003   \u2009
      ‌ \u200C ‍ \u200D ‎ \u200E ‏ \u200F – \u2013
      — \u2014 ‘ \u2018 ’ \u2019 ‚ \u201A
      “ \u201C ” \u201D „ \u201E † \u2020
      ‡ \u2021 ‰ \u2030 ‹ \u2039 › \u203A
      € \u20AC &apos; \u0027 ‎ "" ‏ ""
   };
   if {![string equal $char [encoding system]]} { set text [encoding convertfrom $char $text] }
   set text [string map [list "\]" "\\\]" "\[" "\\\[" "\$" "\\\$" "\"" "\\\"" "\\" "\\\\"] [string map -nocase $escapes $text]]
   regsub -all -- {&#([[:digit:]]{1,5});} $text {[format %c [string trimleft "\1" "0"]]} text
   regsub -all -- {&#x([[:xdigit:]]{1,4});} $text {[format %c [scan "\1" %x]]} text
   catch { set text "[subst "$text"]" }
   if {![string equal $char [encoding system]]} { set text [encoding convertto $char $text] }
   return "$text"
}
}
putlog "IMDB info version 19.10.2010 loaded"
There ya go :)
Libera ##rtlsdr & ##re - Nick: spithash
Click here for troll.tcl
User avatar
Anahel
Halfop
Posts: 48
Joined: Fri Jul 03, 2009 6:18 pm
Location: Dom!

Post by Anahel »

speechles wrote:
spithash wrote:username: it works GREAT :)

Thing is, I'm getting these:

Code: Select all

[17:45:34] <@spithash> !imdb M. Night Shyamalan
[17:45:40] <@nagger> The Sixth Sense (1999) - IMDb - http://www.imdb.com/title/tt0167404/
[17:45:42] <@nagger> Genre: Drama | Mystery | Thriller
[17:45:44] <@nagger> Synopsis: Malcom Crowe is a child psychologist who receives an award on the same night that he is visited by a very unhappy ex-patient. After this encounter, Crowe takes on the task of curing a young boy with the same ills as the ex-patient. This boy "sees dead people". Crowe spends a lot of time with the boy (Cole) much to the dismay of his wife. Cole's mom is at her wit's e
[17:45:46] <@nagger> nd with what to do about her son's increasing problems. Crowe is the boy's only hope.
[17:45:48] <@nagger> Rating: 8.2/10 (242,642 votes) [********--] 28
[17:45:50] <@nagger> Awards:  Nominated for 6 Oscars. Another 31 wins & 37 nominations awards
There are several ' and "
It doesn't do transcoding? Why on Earth not?? O_o;;?

Well, add this procedure to the end of the script..(this procedure is ripped from my twitter script).

Code: Select all

proc imdb_decode {text {char "utf-8"} } {
	# code below is neccessary to prevent numerous html markups
	# from appearing in the output (ie, ", ᘧ, etc)
	# stolen (borrowed is a better term) from tcllib's htmlparse ;)
	# works unpatched utf-8 or not, unlike htmlparse::mapEscapes
	# which will only work properly patched....
	set escapes {
		  \xa0 ¡ \xa1 ¢ \xa2 £ \xa3 ¤ \xa4
		¥ \xa5 ¦ \xa6 § \xa7 ¨ \xa8 © \xa9
		ª \xaa « \xab ¬ \xac ­ \xad ® \xae
		¯ \xaf ° \xb0 ± \xb1 ² \xb2 ³ \xb3
		´ \xb4 µ \xb5 ¶ \xb6 · \xb7 ¸ \xb8
		¹ \xb9 º \xba » \xbb ¼ \xbc ½ \xbd
		¾ \xbe ¿ \xbf À \xc0 Á \xc1 Â \xc2
		Ã \xc3 Ä \xc4 Å \xc5 Æ \xc6 Ç \xc7
		È \xc8 É \xc9 Ê \xca Ë \xcb Ì \xcc
		Í \xcd Î \xce Ï \xcf Ð \xd0 Ñ \xd1
		Ò \xd2 Ó \xd3 Ô \xd4 Õ \xd5 Ö \xd6
		× \xd7 Ø \xd8 Ù \xd9 Ú \xda Û \xdb
		Ü \xdc Ý \xdd Þ \xde ß \xdf à \xe0
		á \xe1 â \xe2 ã \xe3 ä \xe4 å \xe5
		æ \xe6 ç \xe7 è \xe8 é \xe9 ê \xea
		ë \xeb ì \xec í \xed î \xee ï \xef
		ð \xf0 ñ \xf1 ò \xf2 ó \xf3 ô \xf4
		õ \xf5 ö \xf6 ÷ \xf7 ø \xf8 ù \xf9
		ú \xfa û \xfb ü \xfc ý \xfd þ \xfe
		ÿ \xff ƒ \u192 Α \u391 Β \u392 Γ \u393 Δ \u394
		Ε \u395 Ζ \u396 Η \u397 Θ \u398 Ι \u399
		Κ \u39A Λ \u39B Μ \u39C Ν \u39D Ξ \u39E
		Ο \u39F Π \u3A0 Ρ \u3A1 Σ \u3A3 Τ \u3A4
		Υ \u3A5 Φ \u3A6 Χ \u3A7 Ψ \u3A8 Ω \u3A9
		α \u3B1 β \u3B2 γ \u3B3 δ \u3B4 ε \u3B5
		ζ \u3B6 η \u3B7 θ \u3B8 ι \u3B9 κ \u3BA
		λ \u3BB μ \u3BC ν \u3BD ξ \u3BE ο \u3BF
		π \u3C0 ρ \u3C1 ς \u3C2 σ \u3C3 τ \u3C4
		υ \u3C5 φ \u3C6 χ \u3C7 ψ \u3C8 ω \u3C9
		ϑ \u3D1 ϒ \u3D2 ϖ \u3D6 • \u2022
		… \u2026 ′ \u2032 ″ \u2033 ‾ \u203E
		⁄ \u2044 ℘ \u2118 ℑ \u2111 ℜ \u211C
		™ \u2122 ℵ \u2135 ← \u2190 ↑ \u2191
		→ \u2192 ↓ \u2193 ↔ \u2194 ↵ \u21B5
		⇐ \u21D0 ⇑ \u21D1 ⇒ \u21D2 ⇓ \u21D3 ⇔ \u21D4
		∀ \u2200 ∂ \u2202 ∃ \u2203 ∅ \u2205
		∇ \u2207 ∈ \u2208 ∉ \u2209 ∋ \u220B ∏ \u220F
		∑ \u2211 − \u2212 ∗ \u2217 √ \u221A
		∝ \u221D ∞ \u221E ∠ \u2220 ∧ \u2227 ∨ \u2228
		∩ \u2229 ∪ \u222A ∫ \u222B ∴ \u2234 ∼ \u223C
		≅ \u2245 ≈ \u2248 ≠ \u2260 ≡ \u2261 ≤ \u2264
		≥ \u2265 ⊂ \u2282 ⊃ \u2283 ⊄ \u2284 ⊆ \u2286
		⊇ \u2287 ⊕ \u2295 ⊗ \u2297 ⊥ \u22A5
		⋅ \u22C5 ⌈ \u2308 ⌉ \u2309 ⌊ \u230A
		⌋ \u230B 〈 \u2329 〉 \u232A ◊ \u25CA
		♠ \u2660 ♣ \u2663 ♥ \u2665 ♦ \u2666
		" \x22 & \x26 < \x3C > \x3E O&Elig; \u152 œ \u153
		Š \u160 š \u161 Ÿ \u178 ˆ \u2C6
		˜ \u2DC   \u2002   \u2003   \u2009
		‌ \u200C ‍ \u200D ‎ \u200E ‏ \u200F – \u2013
		— \u2014 ‘ \u2018 ’ \u2019 ‚ \u201A
		“ \u201C ” \u201D „ \u201E † \u2020
		‡ \u2021 ‰ \u2030 ‹ \u2039 › \u203A
		€ \u20AC &apos; \u0027 ‎ "" ‏ "" 
	};
	if {![string equal $char [encoding system]]} { set text [encoding convertfrom $char $text] }
	set text [string map [list "\]" "\\\]" "\[" "\\\[" "\$" "\\\$" """ "\\"" "\" "\\\"] [string map -nocase $escapes $text]]
	regsub -all -- {&#([[:digit:]]{1,5});} $text {[format %c [string trimleft "\1" "0"]]} text
	regsub -all -- {&#x([[:xdigit:]]{1,4});} $text {[format %c [scan "\1" %x]]} text
	catch { set text "[subst "$text"]" }
	if {![string equal $char [encoding system]]} { set text [encoding convertto $char $text] }
	return "$text"
}
Then find this code...

Code: Select all

foreach line [split $output "\n"] {
Change it to look like this...

Code: Select all

foreach line [split [imdb_decode $output] "\n"] {
Now it will transcode html entities correctly.
<@bionic> Тёмный рыцарь (2008) - IMDb (Batman: The Dark Knight) - http://www.imdb.com/title/tt0468569/
Yes, it will even render that Russian correctly now. :)

yay, it works great :D

Code: Select all

<+Nekomimi> Den sjette sans (1999) - IMDb (El sexto sentido) - http://www.imdb.com/title/tt0167404/
<+Nekomimi> Gatunek: Drama | Mystery | Thriller
<+Nekomimi> Data wydania: 6 January 2000(Denmark)
<+Nekomimi> Opis: Malcom Crowe is a child psychologist who receives an award on the same night that he is visited by a very unhappy ex-patient. After this encounter, Crowe takes on the task of curing a young boy with the same ills as the ex-patient. This boy "sees dead people". Crowe spends a lot of time with the boy (Cole) much to the dismay of his wife. Cole's mom is at her wit's end with what to do about
<+Nekomimi>  her son's increasing problems. Crowe is the boy's only hope.
<+Nekomimi> Ocena: 8.2/10 (242,642 glosow) [********--]
<+Nekomimi> Top 250: 128
<+Nekomimi> Nagrody:  Nominated for 6 Oscars. Another 31 wins & 37 nominations awards 
<+Nekomimi> Czas trwania: 107min.

spithash http://sakura.pastebin.com/ixEL1vzg <- my scritp,

btw, how to force script to use english names? my bot is in denmark (i use my friend shell to host it) and i'd want to have english (or polish) names instead of dutch, and is it possible to change number of characters in synopis (instead of making another line bot could just cut all lines that are over limit)
User avatar
spithash
Master
Posts: 249
Joined: Thu Jul 12, 2007 9:21 am
Location: Libera
Contact:

Post by spithash »

Thanks, it works great, It was just a wrong paste I did, I am sorry speechles :D

It was my editor's issue :)

The script works awesomely :lol:
[14:40:52] <@spithash> !imdb M. Night Shyamalan
[14:40:57] <@nagger> The Sixth Sense (1999) - IMDb - http://www.imdb.com/title/tt0167404/
[14:40:59] <@nagger> Genre: Drama | Mystery | Thriller
[14:41:01] <@nagger> Synopsis: Malcom Crowe is a child psychologist who receives an award on the same night that he is visited by a very unhappy ex-patient. After this encounter, Crowe takes on t
curing a young boy with the same ills as the ex-patient. This boy "sees dead people". Crowe spends a lot of time with the boy (Cole) much to the dismay of his wife. Cole's mo
wit's end with what to do a
[14:41:03] <@nagger> bout her son's increasing problems. Crowe is the boy's only hope.
[14:41:05] <@nagger> Rating: 8.2/10 (242,692 votes) [********--] 29
[14:41:07] <@nagger> Awards: Nominated for 6 Oscars. Another 31 wins & 37 nominations awards
Libera ##rtlsdr & ##re - Nick: spithash
Click here for troll.tcl
3
3kilos
Voice
Posts: 1
Joined: Sun Feb 27, 2011 9:01 am

Post by 3kilos »

i was also wondering if it is possible to force the bot to output in english, my bot is hosted in hungary and i dont understand what it says!
r
rtrain
Voice
Posts: 1
Joined: Mon Mar 07, 2011 11:05 am

Post by rtrain »

3kilos wrote:i was also wondering if it is possible to force the bot to output in english, my bot is hosted in hungary and i dont understand what it says!
3kilos, look for your set announce line and remove the # from the first and add a # to the second so it looks like this:

set announce(IMDBIRC) "%bold%title%bold - %url\n|%boldGenre:%bold %genre|\n|Plot Keywords: %keywords|\n|Tagline: %tagline|\n|Synopsis: %plot|\n|Rating: %rating (%votes votes) %rbar| |%color3%top250%color|\n|Comment: %comment|\n|Awards: %awards|\n|Runtime: %time mins.|"
#set announce(IMDBIRC) "%bold%title%bold (%aka) - %url\n|%boldGatunek:%bold %genre|\n|%boldData wydania:%bold %reldate|\n|%boldOpis:%bold %plot|\n|%boldOcena:%bold %rating (%votes glosow) %rbar|\n|%boldTop 250:%bold %color03%top250%color|\n|%boldNagrody:%bold %awards|\n|%boldCzas trwania:%bold %time."

That should get you back to English if I'm understanding your issue correctly.

-rt
User avatar
Anahel
Halfop
Posts: 48
Joined: Fri Jul 03, 2009 6:18 pm
Location: Dom!

Post by Anahel »

That should get you back to English if I'm understanding your issue correctly.
nope... imdb is using geolocation and display stuff in language from place where bot is hosted (in my example in france so i get replies from imdb in french)

i see you just commented my little translation of output (it's in polish not in hungarian...)
g
goalie204
Halfop
Posts: 44
Joined: Thu Apr 28, 2011 7:31 pm

Post by goalie204 »

<goalie> !imdb bad boy boddy
<secksy> Error retrieving URL... try again later.


[secksy(dcc)] [14:35] IMDB_DEBUG permission_result == 1
..[secksy(dcc)] [14:35] IMDB_DEBUG instance == 0
..[secksy(dcc)] [14:35] IMDB_DEBUG toput_result == PRIVMSG #criminal
..[secksy(dcc)] [14:35] IMDB_DEBUG new instance == 1
..[secksy(dcc)] [14:35] IMDB_DEBUG searchString: "bad%20boy%20boddy"
..[secksy(dcc)] [14:35] IMDB_DEBUG http://akas.imdb.com/find?tt=on;nm=on;m ... oy%20boddy
..[secksy(dcc)] [14:35] Tcl error [imdb_proc]: can't read "state(status)": no such variable



EDIT: looks like a bad http.tcl was screwing me up, got rid of it and everything works again. Can someone link the latest working one?
User avatar
spithash
Master
Posts: 249
Joined: Thu Jul 12, 2007 9:21 am
Location: Libera
Contact:

Post by spithash »

I believe they changed imdb's website a bit and the rating does not appear at all in the results. let us know if anyone's interested to fix it. :D

Code: Select all

###############################################################################
##     This iMDB.tcl requires Eggdrop1.6.0 or higher                         ##
##                  (c) 2003 by B0unTy                                       ##
##                                                                           ##
##  changed by username                                                      ##
##  19.10.2010                                                               ##
##  *fixed page parsing errors                                               ##
##                                                                           ##
##  changed by OV2                                                           ##
##  05.01.2010                                                               ##
##    *fixed remaining bugs with imdb changes                                ##
##                                                                           ##
##  02.01.2010                                                               ##
##    *modified for imdb page changes                                        ##
##                                                                           ##
##  16.09.2008                                                               ##
##    *modified for new imdb page                                            ##
##                                                                           ##
##  25.05.2008                                                               ##
##    *plot works again                                                      ##
##                                                                           ##
##  19.05.2008                                                               ##
##    *fixed the non-working cookies (cert, soundmix ...)                    ##
##    * "|" characters in cookies are displayed again                        ##
##                                                                           ##
##  21.09.2007                                                               ##
##    *multiline color/underline/bold were broken                            ##
##    +added single-line cast (%castline)                                    ##
##    +added the remaining information from imdb (color, cert, etc...)       ##
##                                                                           ##
##  17.07.2007                                                               ##
##    *fix for the exact title matching                                      ##
##    *exact name matches are no longer confused with exact title matches    ##
##                                                                           ##
##  27.06.2007                                                               ##
##    *works with new imdb search page                                       ##
##    *%uline works again                                                    ##
##                                                                           ##
##  09.04.2007:                                                              ##
##    *fixed director/s writer/s                                             ##
##    +added support for plot keywords                                       ##
##    +added support for user comment line                                   ##
##                                                                           ##
##  28.02.2007:                                                              ##
##    *ratings work again                                                    ##
##    *director and writing credits work again                               ##
##                                                                           ##
##  25.02.2007:                                                              ##
##    *fixed some bugs of the previous changes (thanks to rosc2112)          ##
##                                                                           ##
##  24.02.2007:                                                              ##
##    *bold/underline/color in front of the multiline cast will now be       ##
##     applied to each of the cast lines                                     ##
##    *the | character is now used to declare sections in the announce line  ##
##     if any variable in a section is not found on the imdb page, the       ##
##     corresponding section will not be displayed in the output             ##
##     (see the default announce line for an example)                        ##
##                                                                           ##
##  22.02.2007:                                                              ##
##    *incorporated some code from rosc2112's version                        ##
##    *some small fixes                                                      ##
##                                                                           ##
##  20.02.2007:                                                              ##
##    *changed regexp queries to accomodate the new imdb layout              ##
##    *cleaned up the unneccesary post-regexp code                           ##
##                                                                           ##
##  14.05.2006:                                                              ##
##    *fixed plot outline not showing completely if it included links        ##
##      (thanks to darkwing for finding the bug)                             ##
##    +added support for awards (thanks to rosc2112)                         ##
##    +added support for the cast list (be careful with the limit)           ##
##    +added support for writing credits                                     ##
##                                                                           ##
##  21.01.2006:                                                              ##
##    *fixed problem with irregular search-result pages from imdb            ##
##                                                                           ##
##  31.08.2005:                                                              ##
##    *changed search result priority again:                                 ##
##      1. popular match where the title=search string                       ##
##      2. exact matches                                                     ##
##      3. first title on page                                               ##
##    *fixed missig warn_msg var                                             ##
##                                                                           ##
##  until 24.06.2005:                                                        ##
##    *works with new IMDB                                                   ##
##    *works with (hopefully) all search results (popular/exact/partial)     ##
##    +added timeouts (20secs)                                               ##
##    +added bottom 100 support                                              ##
##    +added rating bar from chilla's imdb-script                            ##
##    +added flood control                                                   ##
##    *small speedup (if your output does not include %screens or %budget    ##
##    *changed proc name to improve compatibility with other scripts         ##
##    *changed search result priority to {exact->first displayed}            ##
##                                                                           ##
###############################################################################
##                                                                           ##
## INSTALL:                                                                  ##
## ========                                                                  ##
##   1- Copy iMDB.tcl in your dir scripts/                                   ##
##   2- Add iMDB.tcl in your eggdrop.conf:                                   ##
##        source scripts/imdb.tcl                                            ##
##                                                                           ##
##   For each channel you want users to use !imdb cmd                        ##
##   Just type in partyline: .chanset #channel +imdb                         ##
##                                                                           ##
###############################################################################
# COOKIES ARE :
# =============
# TITLE             = %title               |    BOLD           = %bold
# URL               = %url                 |    UNDERLINE      = %uline
# DIRECTOR          = %name                |    COLORS         = %color#,#
# GENRE             = %genre               |    NEW LINE       = \n
# PLOT OUTLINE      = %plot                |-----------------------------
# RATING            = %rating              |    !! to reset color code !!
# RATING_BAR        = %rbar                |    !! use %color w/o args !!
# VOTES             = %votes               |
# RUNTIME           = %time (numbers only) |    "|" declares a section
# AWARDS            = %awards              |    if any cookie in a section
# BUDGET            = %budget              |    is empty the whole section
# SCREENS           = %screens             |    is removed from the output
# TAGLINE           = %tagline             |    (end section with "|")
# MPAA              = %mpaa                |
# COUNTRY           = %country             |
# LANGUAGE          = %language            |
# SOUND MIX         = %soundmix            |
# TOP 250           = %top250              |
# CAST LINES        = %castmline           |
# CAST SNGLELINE    = %castline            |
# WRITING CREDITS   = %wcredits            |
# PLOT KEYWORDS     = %keywords            |
# COMMENT LINE      = %comment             |
# RELEASE DATE      = %reldate             |
# MOVIE COLOR       = %mcolor              |
# ASPECT RATIO      = %aspect              |
# CERTIFICATION     = %cert                |
# LOCATIONS         = %locations           |
# COMPANY           = %company             |
#
# + 19.10.2010
# Also Known As     = %aka
#
# 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.

# example normal announce:
# set announce(IMDBIRC) "%bold%title%bold - %url\n|Rating: %rating (%votes votes) %rbar| |%top250|\n|%plot|"
# set announce(IMDBIRC) "%bold%title%bold |\[%time mins - %mcolor\]| - %url\n|Genre: %genre|\n|Tagline: %tagline|\n|Synopsis: %plot|\n|Rating: %rating (%votes votes) %rbar| |%color3%top250%color|\n|Awards: %awards|"

#set announce(IMDBIRC) "%bold%title%bold - %url\n|%boldGenre:%bold %genre|\n|Plot %boldKeywords:%bold %keywords|\n|%boldTagline:%bold %tagline|\n|%boldSynopsis:%bold %plot|\n|%boldRating:%bold %rating (%votes votes) %rbar| |%color3%top250%color|\n|%boldComment:%bold %comment|\n|%boldAwards:%bold %awards|\n|%boldRuntime:%bold %time mins.|"
#set announce(IMDBIRC) "%bold%title%bold (%aka) - %url\n|%boldGenre:%bold %genre|\n|Director: %name|\n|Writers: %wcredits|\n|Release Date: %reldate|\n|Cast: %castline|\n|Country: %country|\n|Language: %language|\n|Color: %mcolor|\n|Plot Keywords: %keywords|\n|Tagline: %tagline|\n|Synopsis: %plot|\n|Rating: %rating (%votes votes) %rbar|\n|Top 250: %color03%top250%color|\n|Locations: %locations|\n|Comment: %comment|\n|Awards: %awards|\n|Runtime: %time.|\n|MPAA: %mpaa|\n|Sound Mix: %soundmix|\n|Aspect Ratio: %aspect|\n|Company: %company|\n|Budget: %budget|\n|Screens: %screens|"
set announce(IMDBIRC) "%bold%title%bold - %url\n|%boldGenre:%bold %genre|\n|%boldSynopsis:%bold %plot|\n|%boldRating:%bold %rating (%votes votes) %rbar| |%color3%top250%color|\n|%boldAwards:%bold %awards|\n|"

#trigger command in channel
set trigger "!imdb"

#rating bar color
#bracket
set barcol1 "14"
#stars
set barcol2 "7"
#cast count to return on multiline and single line (0 means no limit)
set cast_linelimit "5"

#http connection timeout (milliseconds)
set imdb_timeout "25000"

#flood-control
set queue_enabled 1
#max requests
set queue_size 2
#per ? seconds
set queue_time 30

# for a channel !imdb request
# set to 1 = all results will be sent publicly to the channel
# set to 0 = all results will be sent as private notice
set pub_or_not 1

# use or not the imdb debugger (1=enable debug  0=disable debug)
set IMDB_DEBUG 0

# set IMDB_ALTERNATIVE 0 = use the internal tcl http 2.3 package
# set IMDB_ALTERNATIVE 1 = use the external curl 6.0+
set IMDB_ALTERNATIVE 0

# set here the location path where find curl 6.0+
set binary(CURL) "/path/to/curl"
# note for windrop: use normal slashes, e.g. C:/path/to/curl.exe
#################################################################
# DO NOT MODIFY BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING!  #
#################################################################
if { $IMDB_ALTERNATIVE == 0 } { package require http 2.3 }
setudef flag imdb

bind pub -|- $trigger imdb_proc

set instance 0
set warn_msg 0

proc htmlcodes {tempfile} {
#    set mapfile [string map {& & ' ' ' ' [ ( \ / ] ) { ( } )   " " ? ? ? ? © © « « ­ ­ ® ® ? ? ? ? } $tempfile]
#    set mapfile [string map {? ? · · ^(1) ^(1) » » 1/4 1/4 1/2 1/2 3/4 3/4 A` A` A' A' A^ A^ } $mapfile]
#    set mapfile [string map {A~ A~ A" A" A* A* ? ? C, C, E` E` E' E' E^ E^ E" E" I` I` I' I' I^ I^ I" I" ? ? N~ N~ O` O` O' O' O^ O^ O~ O~ O" O" } $mapfile]
#    set mapfile [string map {? ? ? ? U` U` U' U' U^ U^ U" U" Y' Y' ? ? ? ? a` a` a' a' a^ a^ a~ a~ a" a" a* a* ? ? c, c, e` e` e' e' e^ e^ } $mapfile]
#    set mapfile [string map {e" e" i` i` i' i' i^ i^ i" i" ? ? n~ n~ o` o` o' o' o^ o^ o~ o~ o" o" ? ? ? ? u` u` u' u' u^ u^ u" u" y' y' ? ? } $mapfile]
     set mapfile [string map {  "" & "&" " \"} $tempfile]
    return $mapfile
} 

proc channel_check_imdb { chan } {
    foreach setting [channel info $chan] {
        if {[regexp -- {^[\+-]} $setting]} {
            if {![string compare "+imdb" $setting]} {
                set permission 1
                break
            } else {
                set permission 0
            }
        }
    }
    return $permission
}

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_timeout barcol1 barcol2 IMDB_DEBUG pub_or_not announce random warn_msg trigger binary IMDB_ALTERNATIVE
    # channel_check permission
    set permission_result [channel_check_imdb $chan]
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG permission_result == $permission_result" }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG instance == $instance" }
    if { $permission_result == 0} { return }
    # public or private
    if {$pub_or_not == 1 } { set toput "PRIVMSG $chan" } else { set toput "NOTICE $nick" }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG toput_result == $toput" }
    # if no arg passed, show help
    if {$arg == ""} {
        if { $IMDB_ALTERNATIVE == 0 } { set using "Http 2.3+" } else { set using "Curl 6.0+" }
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG no arg passed, show help" }
        puthelp "$toput :IMDb info script \002v05.01.2010\002 using \002$using\002"
        puthelp "$toput :\002Syntax: $trigger <movie title>\002 example: $trigger Beautiful Mind"
        return
    }

    #flood-control
    if { $queue_enabled == 1 } {
       #flooded?
       if { $instance >= $queue_size } {
          if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG flood detected" }
          if { $warn_msg == 0 } {
             set warn_msg 1
             putserv "$toput :Flood-Control: Request for \"$arg\" from user \"$nick\" will not be answered due to flood-faggotry. idiot."
 #            putserv "$toput :Flood-Control: Maximum of $queue_size requests every $queue_time seconds."
             utimer 120 wmsg
          }
          return
       }
       incr instance
       if { $IMDB_DEBUG == 1 } { putlog "IMDB_DEBUG new instance == $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} $arg]
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG searchString: \"$searchString\"" }
    if { $IMDB_ALTERNATIVE == 0 } {
        set page [::http::config -useragent "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3"]
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG ${imdbsearchurl}q=$searchString" }
        if [catch {set page [::http::geturl ${imdbsearchurl}q=$searchString -timeout $imdb_timeout]} error] {
            puthelp "$toput :Error retrieving URL... 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 (search page), find first link and redirect
    if { ([regexp {<title>IMDb.*Search} $html] == 1) } {
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG redirect 1" }
        set ttcode "0000001"
        set start "0"
        set temp $html

        #dealing with different search results
        set hit 0
        if { [regexp -indices {Popular Titles} $temp tstart] } {
           if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG found popular titles" }
           set temp2 [string range $temp [lindex $tstart 1] end]
           regexp {1\..*?<a.*?>(.*?)</a>} $temp2 dummy title
           if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG compare $title == $arg" }
           if { [string equal -nocase $title $arg] } {
              if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG equals - displaying first popular match" }
              set temp $temp2
              set hit 1
           } else {
              if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG not equal - searching for exact match" }
           }

        }
        if { $hit == 0 } {
           if { [regexp -indices {Titles \(Exact Matches\)} $temp start] } {
              if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG displaying exact match" }
           } elseif { [regexp -indices {Titles} $temp start] } {
              if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG no exact match - displaying first title on page" }
           } else {
                puthelp "$toput :No useful results."
                if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG no titles results found" }
                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 :No no no! I can't find that!"
            if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG bogus ttcode" }
            return
        }
        set newurl "$imdburl/title/$ttcode/"
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG redirect 1 = $newurl" }
        # get the page redirected to
        unset html
        if { $IMDB_ALTERNATIVE == 0 } {
            set page [::http::config -useragent "MSIE 6.0"]
            set page [::http::geturl $newurl -timeout $imdb_timeout]
            if [catch {set page [::http::geturl $newurl -timeout $imdb_timeout]} error] {
                puthelp "$toput :Error retrieving URL... 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 necessary (only one match in meta), then go there
    } else {
        set location ""
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG redirect 0" }
        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]
            putlog $oldpage
            regexp {title/tt[0-9]+/} $oldpage location
        }
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG redirect 0 Location == $location" }
        set newurl "$imdburl/$location"
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG redirect 0 = $newurl" }
        if { $location != "" } {
            if { $IMDB_ALTERNATIVE == 0 } {
                unset html
                set page [::http::config -useragent "MSIE 6.0"]
                if [catch {set page [::http::geturl $newurl -timeout $imdb_timeout]} error] {
                    puthelp "$toput :Error retrieving URL... 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 :Error in search mechanics - you probably need a newer version."
            return
        }

    }
    # for bogus searches
    if {[string length $newurl] == 0} {
        puthelp "$toput :No no no! I can't find that!"
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG bogus searches" }
        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 aka "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 "top/bottom:N/A"; set awards "N/A"; set rating_bar ""; set cast_multiline "N/A"; set wcredits "N/A";
    set keywords "N/A"; set comment "N/A"; set reldate "N/A"; set cast_line "N/A"; set movie_color "N/A"; set aspect_ratio "N/A";
    set cert "N/A"; set film_locations "N/A"; set company "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]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG title == $title" }
    
    ## get aka
    if [regexp {<h4 class="inline">Also Known As:</h4>(.*?)</div>} $html dummy aka] {
        regsub -all {<[^\>]*>} $aka {} aka
        set aka [string map {"See more" "" \n "" & " & " » ""} $aka]
        set aka [string trim $aka]
        set aka [htmlcodes $aka]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG aka == $aka" }
  
    ## get director
    if [regexp {<h4 class="inline">.*?Director:.*?</h4>(.*?)</div>} $html dummy name] {
        regsub -all {\n[ ]*} $name {} name
        set name [string map {"&<br/>" "& " "<br/>" ", " "See more" ""} $name]
        regsub -all {<[^>]+>} $name {} name
        set name [string trim $name]
        regsub -all {,$} $name {} name
        set name [htmlcodes $name]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG director == $name" }
    ## get writing credits
    if [regexp {<h4 class="inline">.*?Writers:.*?</h4>(.*?)</div>} $html dummy wcredits] {
        regsub -all {\n[ ]*} $wcredits {} wcredits
        set wcredits [string map {"See more" "" "<br/> " "" "&<br/>" "& " "&<br/>" "& " "<br/>" ", " "»" ""} $wcredits]
        regsub -all {<[^>]+>} $wcredits {} wcredits
        set wcredits [string trim $wcredits]
        regsub -all {,$} $wcredits {} wcredits
        set wcredits [htmlcodes $wcredits]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG writer == $wcredits" }
    # release date
    if {[regexp {<h4 class="inline">Release Date:</h4>(.*?)</div>} $html dummy reldate]} {
        regsub -all {<[^\>]*>} $reldate {} reldate
        set reldate [string map {"See more" "" \n "" & " & "} $reldate]
        set reldate [string trim $reldate]
        set reldate [htmlcodes $reldate]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG release date == $reldate" }
    ## get genre
    if [regexp {<h4 class="inline">Genres:</h4>(.*?)</div>} $html dummy genre] {
        set genre [string map {"See more" ""   " "} $genre]
        regsub -all {<[^\>]*>} $genre {} genre
        set genre [string map {"|" "||" } $genre]
        set genre [string trim $genre]
        regsub {\(.*\)} $genre {} genre
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG genre == $genre" }
    ## get tagline
    if [regexp {<h4 class="inline">Taglines:</h4>(.*?)<span .*?>} $html dummy tagline] {
        set tagline [string map {"See more" "" } $tagline]
        regsub -all {<[^\>]*>} $tagline {} tagline
        set tagline [string trim $tagline]
        set tagline [htmlcodes $tagline]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG tagline == $tagline" }
    ## get plot outline
    if { [regexp {<h2>Storyline</h2>(.*?)<em .*?>} $html dummy plot] || [regexp {<h5>Plot Summary:</h5>(.*?)</div>} $html dummy plot] } {
        set plot [string map {"See more" "" "(view trailer)" "" "full summary" "" "add synopsis" "" "full synopsis (warning! may contain spoilers)" "" "full synopsis" "" " | " ""} $plot]
        regsub -all {<[^\>]*>} $plot {} plot
        set plot [string trim $plot]
        set plot [htmlcodes $plot]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG plot == $plot" }
    ## get plot keywords
    if [regexp {<h4 class="inline">Plot Keywords:</h4>(.*?)</div>} $html dummy keywords] {
       set keywords [string map {"See more" "" \n ""   " " » ""} $keywords]
       regsub -all {<[^\>]*>} $keywords {} keywords
       set keywords [string map {"|" "||"} $keywords]
       set keywords [string trim $keywords]
       set keywords [htmlcodes $keywords]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG keywords == $keywords" }
    ## get awards
    if [regexp {<strong>Top 250 .*?</strong></a>(.*?)</div>} $html dummy awards] {
       set awards [string map {"See more" "" \n "" » ""} $awards]
       regsub -all {<[^\>]*>} $awards { } awards
       set awards [string trim [join $awards]]
       set awards [htmlcodes $awards]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG awards == $awards" }
    ## get comment
    if [regexp {<h2>User Reviews</h2>(.*?)</strong>} $html dummy comment] {
       set comment [string map {"See more" "" \n ""} $comment]
       regsub -all {<[^\>]*>} $comment {} comment
       set comment [string trim [join $comment]]
       set comment [htmlcodes $comment]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG comment == $comment" }
    ## get iMDb rating

                                                                
    if [regexp {<b>((.*?)</b><span class="mellow">/10)</span>.*?<a .*? href="ratings".*?>(.*?) votes</a>} $html dummy rating goldstars votes] {

        regsub -all {<[^\>]*>} $rating {} rating
        #rating bar code
        set goldstars [expr round($goldstars)]
        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

    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG rating == $rating | votes == $votes | rating bar == $rating_bar" }
    ## get TOP 250
    if [regexp {<strong>Top 250 #([\d]+)</strong>} $html dummy top250] {
    } elseif [regexp {>(Bottom 100: #[\d]+)</a>} $html dummy top250] {
    }

    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG top250 == $top250" }
    ## get MPAA
    if [regexp {<h4>Motion Picture Rating.*?</h4>(.*?)<span .*?>} $html dummy mpaa] {
        regsub -all {<[^\>]*>} $mpaa {} mpaa
        #regsub {MPAA: } $mpaa {} mpaa
        set mpaa [string trim $mpaa]
        set mpaa [htmlcodes $mpaa]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG mpaa == $mpaa" }
    ## get runtime
    if [regexp {<h4 class="inline">Runtime:</h4>(.*?)</div>} $html dummy runtime] {
        regsub -all {[\n\s]+} $runtime {} runtime
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG runtime == $runtime" }
    ## get country
    if [regexp {<h4 class="inline">Country:</h4>(.*?)</div>} $html dummy country] {
        set country [string map {  " "} $country]
        regsub -all {<[^\>]*>} $country {} country
        set country [string map {"|" "||" } $country]
        regsub -all {[\n]+} $country {} country
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG country == $country" }
    ## get language
    if [regexp {<h4 class="inline">Language:</h4>(.*?)</div>} $html dummy language] {
        set language [string map {"See more" "" \n ""   " " » ""} $language]
        regsub -all {<[^\>]*>} $language {} language
        regsub -all {[\n]+} $language {} language
        set language [string map {"|" "||"} $language]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG language == $language" }
    ## get movie color
    if [regexp {<h4 class="inline">Color:</h4>(.*?)</div>} $html dummy movie_color] {
        regsub -all {<[^\>]*>} $movie_color {} movie_color
        regsub -all {[\n\s]+} $movie_color {} movie_color
        set movie_color [string trim $movie_color]
        set movie_color [string map {"|" "||"} $movie_color]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG movie_color == $movie_color" }
    ## get aspect ratio
    if [regexp {<h4 class="inline">Aspect Ratio:</h4>(.*?)</div>} $html dummy aspect_ratio] {
        regsub -all {<[^\>]*>} $aspect_ratio {} aspect_ratio
        set aspect_ratio [string map {"more" "" } $aspect_ratio]
        set aspect_ratio [string trim $aspect_ratio]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG aspect_ratio == $aspect_ratio" }
    ## get soundmix
    if [regexp {<h4 class="inline">Sound Mix:</h4>(.*?)</div>} $html dummy soundmix] {
        set soundmix [string map {"See more" "" \n ""   "" » ""} $soundmix]
        regsub -all {<[^\>]*>} $soundmix {} soundmix
        regsub -all {[\n]+} $soundmix {} soundmix
        set soundmix [string map {"|" "||"} $soundmix]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG soundmix == $soundmix" }
    ## get certification
    if [regexp {<h5>Certification:</h5>\n(.*?)</div>} $html dummy cert] {
        regsub -all {<[^\>]*>} $cert {} cert
        regsub -all {[\n]+} $cert {} cert
        set cert [string map {"|" "||"} $cert]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG cert == $cert" }
    ## get locations
    if { [regexp {<h4 class="inline">Filming Locations:</h4>(.*?)</div>} $html dummy film_locations] } {
        set film_locations [string map {"See more" ""  » ""} $film_locations]
        regsub -all {<[^\>]*>} $film_locations {} film_locations
        regsub -all {[\n\s]+} $film_locations { } film_locations
        set film_locations [string trim $film_locations]
        set film_locations [htmlcodes $film_locations]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG film_locations == $film_locations" }
    ## get company
    if [regexp {<h3>Company Credits</h3>(.*?)</div>} $html dummy company] {
        set company [string map {"See more" ""   "" » ""} $company]
        regsub -all {<[^\>]*>} $company {} company
        regsub -all {[\n\s]+} $company { } company

        set company [string trim $company]
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG company == $company" }
   
    ## get cast
    if [regexp {<table class="cast_list">(.*?)</table>} $html dummy cast] {
        regsub -all {</tr>.*?<tr.*?>} $cast "\n" cast_multiline
        regsub -all {[\n]+} $cast_multiline {} cast_multiline
        regsub -all {<[^\>]*>} $cast_multiline {} cast_multiline
        set cast_multiline [string map {"rest of cast listed alphabetically:" \n} $cast_multiline]
        set cast_multiline [string trim [join [htmlcodes $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]}
        }
    }
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG cast_multiline == $cast_multiline" }
    ## fill singleline
    regsub -all {\n} $cast_multiline " / " cast_line
    if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG cast_line == $cast_line" }

        ## get budget
        if [regexp {<h4 class="inline">Budget:</h4> (.*?)</div>} $html dummy budget] {
           regsub -all {[\n]+} $budget {} budget
           set budget [string map {? ? ? ?} $budget]
        }
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG budget == $budget" }
        ## get screens
        if [regexp {<h4 class="inline">Opening Weekend:</h4>\n(.*?Screens\))} $html dummy screens] {
           regsub -all {[\n]+} $screens { } screens
           regsub -all {<[^\>]*>} $screens {} screens
           set screens [htmlcodes $screens]
        }
        if {$IMDB_DEBUG == 1} { putlog "IMDB_DEBUG screens == $screens" }

    ## output results
   
    set output [replacevar $output "%title" $title]
    set output [replacevar $output "%aka" $aka]
    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 "%keywords" $keywords]
    set output [replacevar $output "%awards" $awards]
    set output [replacevar $output "%comment" $comment]
    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 "%country" $country]
    set output [replacevar $output "%language" $language]
    set output [replacevar $output "%mcolor" $movie_color]
    set output [replacevar $output "%aspect" $aspect_ratio]
    set output [replacevar $output "%soundmix" $soundmix]
    set output [replacevar $output "%cert" $cert]
    set output [replacevar $output "%locations" $film_locations]
    set output [replacevar $output "%company" $company]
    set output [replacevar $output "%budget" $budget]
    set output [replacevar $output "%screens" $screens]
    set output [replacevar $output "%reldate" $reldate]
    set checkvar ""
    regexp {.*?%castmline} $output checkvar
    if { [expr [regexp -all {%uline} $checkvar] % 2] == 1 } {
        set cast_multiline [string map {"\n" "\n%uline"} $cast_multiline]
    }
    if { [expr [regexp -all {%bold} $checkvar] % 2] == 1 } {
        set cast_multiline [string map {"\n" "\n%bold"} $cast_multiline]
    }
    if { [regexp {.*%color([\d]+(?:,[\d]+)?)[^\n]*?%castmline} $checkvar dummy colormline] } {
        regsub -all {\n} $cast_multiline "\n%color$colormline" cast_multiline
    }
    set output [replacevar $output "%castmline" $cast_multiline]
    set output [replacevar $output "%castline" $cast_line]
    set output [replacevar $output "%wcredits" $wcredits]
    regsub -all {\|[^\|]*?N/A[^\|]*?\|} $output "" output
    set output [string map {"||" "|" "|" ""} $output]
    regsub -all {\n[\n\s]*\n} $output "\n" output
    set output [string trim $output]
    set output [replacevar $output "%bold" "\002"]
    set output [replacevar $output "%color" "\003"]
    set output [replacevar $output "%uline" "\037"]
    foreach line [split [imdb_decode $output] "\n"] {
        while {$line != ""} {
            puthelp "$toput :[string range $line 0 399]"
            set line [string range $line 400 end]
        } 
    }
}

proc decr_inst { } {
     global IMDB_DEBUG instance
     if { $instance > 0 } { incr instance -1 }
     if { $IMDB_DEBUG == 1 } { putlog "IMDB_DEBUG instance decreased by timer to: $instance" }
}

proc wmsg { } {
     global warn_msg
     set warn_msg 0
}

proc imdb_decode {text {char "utf-8"} } {
   # code below is neccessary to prevent numerous html markups
   # from appearing in the output (ie, ", ?, etc)
   # stolen (borrowed is a better term) from tcllib's htmlparse ;)
   # works unpatched utf-8 or not, unlike htmlparse::mapEscapes
   # which will only work properly patched....
   set escapes {
        \xa0 ¡ \xa1 ¢ \xa2 £ \xa3 ¤ \xa4
      ¥ \xa5 ¦ \xa6 § \xa7 ¨ \xa8 © \xa9
      ª \xaa « \xab ¬ \xac ­ \xad ® \xae
      ¯ \xaf ° \xb0 ± \xb1 ² \xb2 ³ \xb3
      ´ \xb4 µ \xb5 ¶ \xb6 · \xb7 ¸ \xb8
      ¹ \xb9 º \xba » \xbb ¼ \xbc ½ \xbd
      ¾ \xbe ¿ \xbf À \xc0 Á \xc1 Â \xc2
      Ã \xc3 Ä \xc4 Å \xc5 Æ \xc6 Ç \xc7
      È \xc8 É \xc9 Ê \xca Ë \xcb Ì \xcc
      Í \xcd Î \xce Ï \xcf Ð \xd0 Ñ \xd1
      Ò \xd2 Ó \xd3 Ô \xd4 Õ \xd5 Ö \xd6
      × \xd7 Ø \xd8 Ù \xd9 Ú \xda Û \xdb
      Ü \xdc Ý \xdd Þ \xde ß \xdf à \xe0
      á \xe1 â \xe2 ã \xe3 ä \xe4 å \xe5
      æ \xe6 ç \xe7 è \xe8 é \xe9 ê \xea
      ë \xeb ì \xec í \xed î \xee ï \xef
      ð \xf0 ñ \xf1 ò \xf2 ó \xf3 ô \xf4
      õ \xf5 ö \xf6 ÷ \xf7 ø \xf8 ù \xf9
      ú \xfa û \xfb ü \xfc ý \xfd þ \xfe
      ÿ \xff ƒ \u192 Α \u391 Β \u392 Γ \u393 Δ \u394
      Ε \u395 Ζ \u396 Η \u397 Θ \u398 Ι \u399
      Κ \u39A Λ \u39B Μ \u39C Ν \u39D Ξ \u39E
      Ο \u39F Π \u3A0 Ρ \u3A1 Σ \u3A3 Τ \u3A4
      Υ \u3A5 Φ \u3A6 Χ \u3A7 Ψ \u3A8 Ω \u3A9
      α \u3B1 β \u3B2 γ \u3B3 δ \u3B4 ε \u3B5
      ζ \u3B6 η \u3B7 θ \u3B8 ι \u3B9 κ \u3BA
      λ \u3BB μ \u3BC ν \u3BD ξ \u3BE ο \u3BF
      π \u3C0 ρ \u3C1 ς \u3C2 σ \u3C3 τ \u3C4
      υ \u3C5 φ \u3C6 χ \u3C7 ψ \u3C8 ω \u3C9
      ϑ \u3D1 ϒ \u3D2 ϖ \u3D6 • \u2022
      … \u2026 ′ \u2032 ″ \u2033 ‾ \u203E
      ⁄ \u2044 ℘ \u2118 ℑ \u2111 ℜ \u211C
      ™ \u2122 ℵ \u2135 ← \u2190 ↑ \u2191
      → \u2192 ↓ \u2193 ↔ \u2194 ↵ \u21B5
      ⇐ \u21D0 ⇑ \u21D1 ⇒ \u21D2 ⇓ \u21D3 ⇔ \u21D4
      ∀ \u2200 ∂ \u2202 ∃ \u2203 ∅ \u2205
      ∇ \u2207 ∈ \u2208 ∉ \u2209 ∋ \u220B ∏ \u220F
      ∑ \u2211 − \u2212 ∗ \u2217 √ \u221A
      ∝ \u221D ∞ \u221E ∠ \u2220 ∧ \u2227 ∨ \u2228
      ∩ \u2229 ∪ \u222A ∫ \u222B ∴ \u2234 ∼ \u223C
      ≅ \u2245 ≈ \u2248 ≠ \u2260 ≡ \u2261 ≤ \u2264
      ≥ \u2265 ⊂ \u2282 ⊃ \u2283 ⊄ \u2284 ⊆ \u2286
      ⊇ \u2287 ⊕ \u2295 ⊗ \u2297 ⊥ \u22A5
      ⋅ \u22C5 ⌈ \u2308 ⌉ \u2309 ⌊ \u230A
      ⌋ \u230B 〈 \u2329 〉 \u232A ◊ \u25CA
      ♠ \u2660 ♣ \u2663 ♥ \u2665 ♦ \u2666
      " \x22 & \x26 < \x3C > \x3E O&Elig; \u152 œ \u153
      Š \u160 š \u161 Ÿ \u178 ˆ \u2C6
      ˜ \u2DC   \u2002   \u2003   \u2009
      ‌ \u200C ‍ \u200D ‎ \u200E ‏ \u200F – \u2013
      — \u2014 ‘ \u2018 ’ \u2019 ‚ \u201A
      “ \u201C ” \u201D „ \u201E † \u2020
      ‡ \u2021 ‰ \u2030 ‹ \u2039 › \u203A
      € \u20AC &apos; \u0027 ‎ "" ‏ ""
   };
   if {![string equal $char [encoding system]]} { set text [encoding convertfrom $char $text] }
   set text [string map [list "\]" "\\\]" "\[" "\\\[" "\$" "\\\$" "\"" "\\\"" "\\" "\\\\"] [string map -nocase $escapes $text]]
   regsub -all -- {&#([[:digit:]]{1,5});} $text {[format %c [string trimleft "\1" "0"]]} text
   regsub -all -- {&#x([[:xdigit:]]{1,4});} $text {[format %c [scan "\1" %x]]} text
   catch { set text "[subst "$text"]" }
   if {![string equal $char [encoding system]]} { set text [encoding convertto $char $text] }
   return "$text"
}

putlog "IMDB info version 19.10.2010 loaded"
The code is not just b0unty's imdb.tcl. I added a few stuff for transcoding that I took from speechless's other script(s) and it was his suggestion too.

I will be thankful if someone wants to fix this rating issue. 8)
Libera ##rtlsdr & ##re - Nick: spithash
Click here for troll.tcl
g
goalie204
Halfop
Posts: 44
Joined: Thu Apr 28, 2011 7:31 pm

Post by goalie204 »

any fix for the rating change on the imdb site yet?
Z
Znuff
Voice
Posts: 9
Joined: Mon May 17, 2010 1:00 am

Post by Znuff »

Here's an updated version, which fixes several parsing errors and adds some other things - just read the changelog.

Code is too long to post here, download from link below:

http://z.linge-ma.ws/eggdrop/imdb.tcl
User avatar
spithash
Master
Posts: 249
Joined: Thu Jul 12, 2007 9:21 am
Location: Libera
Contact:

Post by spithash »

Znuff, awesome man. works like a charm.

This is how I truncated some extra lines that I thought were useless and the output is 2 to 3 lines (rarely 4) depending on the plot text. try it!

Code: Select all

set announce(IMDBIRC) "%bold%title%bold - %url - %boldDirected by:%bold %name - %boldGenre:%bold %genre - %boldRating:%bold %rating (%votes votes) - %boldRuntime:%bold %time mins.\n%boldSynopsis:%bold %plot"
:)
Libera ##rtlsdr & ##re - Nick: spithash
Click here for troll.tcl
Post Reply