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.

Help with tcl, to search subtitles in 1 site

Help for those learning Tcl or writing their own scripts.
Post Reply
u
unb0rn
Voice
Posts: 26
Joined: Mon Sep 08, 2008 8:14 am

Help with tcl, to search subtitles in 1 site

Post by unb0rn »

Hi, i'm trying to make a TCL that searches one website for subtitles, and then give me the link in the irc, but i can't get it to work...
I've been searching here, and in google, and i can't find anything like the one that i want.

I want the tcl to search this site: http://www.legendasdivx.com
I think the search link is this one,
http://www.legendasdivx.com/modules.php ... h&op=_jz00

It's a Portuguese website.

CODE:
set legendas(cmd) "!legendas"
set legendas(help) "\002!legendas\002 \<Filme>"
set legendas(url) "http://www.legendasxvid.net/modules.php ... n=0&query={ }&orderby=dateD"
setudef flag legendas

bind pub - $legendas(cmd) legendas:request

package require http
http::config -useragent "Mozilla/1.0"

proc legendas:request { nick uhost hand chan arg } {
if { [ lsearch -exact [ channel info $chan ] "+legendas" ] == -1 } { return }

global legendas
if {[string match -nocase $arg "help"] || [lindex $arg 0 ] == ""} {
putquick "privmsg $chan :$legendas(help)"
return
}
putlog "\002LEGENDAS\002: !legendas $arg -> $nick@$chan "

set url [append legendas(url) [string map {\ +} $arg]]
putlog "\002URL\002: $url"

set http [ http::geturl $url ]
set html [ http::data $http ]
set num 1

foreach line [ split $html "\n" ] {
if { [ regexp -- {^.*<br><font color\=#008000>(.+).*</font><a class.*$} $line all link ] } {
if { $num > 4 } { break }
incr num
regsub -all -- { -.*-\s*$} $link "" link
set risposta "$answer\002::\002 $link "
}
}
regsub -all -- {\s+} $answer " " answer
putquick "privmsg $chan :\037Legendas\037: $answer"
}
I appreciate the help, 'cos i really want this to work.
Last edited by unb0rn on Fri Sep 12, 2008 12:27 pm, edited 1 time in total.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Your building the url incorrectly.

Code: Select all

Change:
set legendas(url) "http://www.legendasxvid.net/modules.php?name=Downloads&d_op=search&min=0&query={ }&orderby=dateD" 

To:
set legendas(url) "http://www.legendasxvid.net/modules.php?name=Downloads&d_op=search&min=0&query=%%query%%&orderby=dateD"

Change:
set url [append legendas(url) [string map {\ +} $arg]] 

To:
set url $legendas(url)
regsub {%%query%%} $url "[string map {" " "+"} $arg]" url
That should fix it for the most part, assuming your parsing is correct.
u
unb0rn
Voice
Posts: 26
Joined: Mon Sep 08, 2008 8:14 am

Post by unb0rn »

Thank's for the help, but i have no idea what's wrong, now with the url that you gave me, stills doesn't work.

I'm looking at the code, and i cant find the error.

If it isn't asking too much, could you kindly help me with the code?
Maybe a different one or something.
u
unb0rn
Voice
Posts: 26
Joined: Mon Sep 08, 2008 8:14 am

Post by unb0rn »

I even tried to use the normal google tcl, only changing the url, but it doesn't work.

Can you please help me?
u
unb0rn
Voice
Posts: 26
Joined: Mon Sep 08, 2008 8:14 am

Post by unb0rn »

I've tried another one, with the url that you gave me...


### Configuration settings ###

# the triggers: [seperate with spaces]
set google(triggers) "!legendas"

# flags needed to use the trigger [default=everyone]
set google(flags) "-|-"

# channels where the bot doesn't respond to triggers [seperate with spaces]
set google(nopub) ""

# flood protection: seconds between use of the triggers
# to disable: set it to 0
set google(antiflood) 5

# method to send the messages:
# 0 = Private message
# 1 = Public message
# 2 = Private notice
# 3 = Public notice
set google(method) 1

# show how many results? 1, 2 or 3??
set google(results) 3

# show every result on a new line? 0=no 1=yes
set google(perline) 0

set google(version) 0.4

if {[catch { package require http } err]} {
putlog "Cannot load [file tail [info script]]: Problem loading the http package: $err"
return 1
}

if {[info tclversion] < 8.1} {
putlog "Cannot load [file tail [info script]]: You need at least Tcl version 8.1 and you have Tcl version [info tclversion]."
return 1
}

foreach trigger [split $google(triggers)] {
bind pub $google(flags) $trigger google:pub
}
catch { unset trigger }

proc google:output {chan nick output} {
global google

switch $google(method) {
0 { putquick "PRIVMSG $nick :$output" }
1 { putquick "PRIVMSG $chan :$output" }
2 { putquick "NOTICE $nick :$output" }
3 { putquick "NOTICE $chan :$output" }
default { putquick "PRIVMSG $chan :$output" }
}
}

proc google:pub {nick uhost hand chan text} {
global lastbind google

if {[lsearch -exact $google(nopub) [string tolower $chan]] >= 0} { return 0 }

if {[string length [string trim [lindex $text 0]]] == 0} {
putquick "NOTICE $nick :Usage: $lastbind <keywords>"
return 0
}

if {[info exists google(floodprot)]} {
set diff [expr [clock seconds] - $google(floodprot)]
if {$diff < $google(antiflood)} {
putquick "NOTICE $nick :Trigger has just been used! Please wait [expr $google(antiflood) - $diff] seconds..."
return 0
}
catch { unset diff }
}
set google(floodprot) [clock seconds]

regsub -all { } [join $text] {+} search
set google(url) "http://www.legendasxvid.net/modules.php ... erby=dateD"
set google(page) [http::config -useragent "Mozilla"]
if {[catch {set google(page) [http::geturl $google(url) -timeout 15000]} msg]} {
putquick "NOTICE $nick :Can't connect ($msg)"
return 0
}
set google(data) [http::data $google(page)]

if {$google(results) >= 1} {
regexp -nocase {related:(.*?)>} $google(data) t link1
}
if {$google(results) >= 2} {
regexp -nocase {related:.*?>.*?related:(.*?)>} $google(data) t link2
}
if {$google(results) >= 3} {
regexp -nocase {related:.*?>.*?related:.*?>.*?related:(.*?)>} $google(data) t link3
}

if {$google(perline) == 1} {
set separator "\n"
} else {
set separator "-"
}

if {[info exists link3]} {
set output "http://$link1 $separator http://$link2 $separator http://$link3"
} elseif {[info exists link2]} {
set output "http://$link1 $separator http://$link2"
} elseif {[info exists link1]} {
set output "http://$link1"
} else {
set output "Nothing found." <------------------------------------
}

regsub -all {%26} $output {\&} output
regsub -all {%3F} $output {?} output
regsub -all {%3D} $output {=} output

if {$google(perline) == 1} {
foreach line [split $output \n] {
google:output $chan $nick [string trim $line]
}
} else {
google:output $chan $nick [string trim $output]
}

catch { unset output separator t link1 link2 link3 }
catch { http::cleanup $google(page) }

return 0
}

putlog "Google script $google(version) loaded!"


On the irc, it shows: Nothing found.
even if i change that part, i have no ideia what to put there.
u
unb0rn
Voice
Posts: 26
Joined: Mon Sep 08, 2008 8:14 am

Post by unb0rn »

unb0rn wrote:I've tried another one, with the url that you gave me...


### Configuration settings ###

# the triggers: [seperate with spaces]
set google(triggers) "!legendas"

# flags needed to use the trigger [default=everyone]
set google(flags) "-|-"

# channels where the bot doesn't respond to triggers [seperate with spaces]
set google(nopub) ""

# flood protection: seconds between use of the triggers
# to disable: set it to 0
set google(antiflood) 5

# method to send the messages:
# 0 = Private message
# 1 = Public message
# 2 = Private notice
# 3 = Public notice
set google(method) 1

# show how many results? 1, 2 or 3??
set google(results) 3

# show every result on a new line? 0=no 1=yes
set google(perline) 0

set google(version) 0.4

if {[catch { package require http } err]} {
putlog "Cannot load [file tail [info script]]: Problem loading the http package: $err"
return 1
}

if {[info tclversion] < 8.1} {
putlog "Cannot load [file tail [info script]]: You need at least Tcl version 8.1 and you have Tcl version [info tclversion]."
return 1
}

foreach trigger [split $google(triggers)] {
bind pub $google(flags) $trigger google:pub
}
catch { unset trigger }

proc google:output {chan nick output} {
global google

switch $google(method) {
0 { putquick "PRIVMSG $nick :$output" }
1 { putquick "PRIVMSG $chan :$output" }
2 { putquick "NOTICE $nick :$output" }
3 { putquick "NOTICE $chan :$output" }
default { putquick "PRIVMSG $chan :$output" }
}
}

proc google:pub {nick uhost hand chan text} {
global lastbind google

if {[lsearch -exact $google(nopub) [string tolower $chan]] >= 0} { return 0 }

if {[string length [string trim [lindex $text 0]]] == 0} {
putquick "NOTICE $nick :Usage: $lastbind <keywords>"
return 0
}

if {[info exists google(floodprot)]} {
set diff [expr [clock seconds] - $google(floodprot)]
if {$diff < $google(antiflood)} {
putquick "NOTICE $nick :Trigger has just been used! Please wait [expr $google(antiflood) - $diff] seconds..."
return 0
}
catch { unset diff }
}
set google(floodprot) [clock seconds]

regsub -all { } [join $text] {+} search
set google(url) "http://www.legendasxvid.net/modules.php ... erby=dateD"
set google(page) [http::config -useragent "Mozilla"]
if {[catch {set google(page) [http::geturl $google(url) -timeout 15000]} msg]} {
putquick "NOTICE $nick :Can't connect ($msg)"
return 0
}
set google(data) [http::data $google(page)]

if {$google(results) >= 1} {
regexp -nocase {related:(.*?)>} $google(data) t link1
}
if {$google(results) >= 2} {
regexp -nocase {related:.*?>.*?related:(.*?)>} $google(data) t link2
}
if {$google(results) >= 3} {
regexp -nocase {related:.*?>.*?related:.*?>.*?related:(.*?)>} $google(data) t link3
}

if {$google(perline) == 1} {
set separator "\n"
} else {
set separator "-"
}

if {[info exists link3]} {
set output "http://$link1 $separator http://$link2 $separator http://$link3"
} elseif {[info exists link2]} {
set output "http://$link1 $separator http://$link2"
} elseif {[info exists link1]} {
set output "http://$link1"
} else {
set output "Nothing found." <------------------------------------ THIS PART HERE
}

regsub -all {%26} $output {\&} output
regsub -all {%3F} $output {?} output
regsub -all {%3D} $output {=} output

if {$google(perline) == 1} {
foreach line [split $output \n] {
google:output $chan $nick [string trim $line]
}
} else {
google:output $chan $nick [string trim $output]
}

catch { unset output separator t link1 link2 link3 }
catch { http::cleanup $google(page) }

return 0
}

putlog "Google script $google(version) loaded!"
On the irc, it shows: Nothing found.
even if i change that part, i have no ideia what to put there.
Where i have " <------------ THIS PART HERE " if i don't edit that, it will show me on the IRC, what a wrote there, i think that now, the only problem is on the " set output ".
Post Reply