Another update!
-Added s and b switches. The s switch will also show the seeds and leechers for displayed torrents. The b switch lets you sort by either: Seeds, leechers/peers, date, or size.
Example: '!torrent -rsb 2 seeds something' will give you the torrent with the second most seeds for "Something".
-Added a right click screen which lets you set options, user friendly search, and advertise.
-Added an options dialog. At the moment it only has the options to always show seeds and leechers. (So you dont always have to use the s switch) And you can set a default sorting method, with this if you always want it to sort by most seeds or date etc... You can set that.
Update: Now you can use the -r switch to find a specific result. For example:
!torrent -r 13 titties
^Would give you the 13th result for "titties"
Or you can do it with the alias if your not using a bot:
/torrentsearch -r 13 titties
^Will give the same results.
This is my first script to do anything with sockets and I think it turned out quite well :D
Just load in a bot, or yourself, and when someone types "!torrent " The script will search thepiratebay.org for torrents related to your query and msg the channel something similar to this:
[4:42:19][NIGathan] !torrent test
[4:42:27][~DOOM_BOT] Approx. 1000 Results found for "test" at http://thepiratebay.org/search/test/0/99/0.
[4:42:27][~DOOM_BOT] Result 1: Cat: Audio > Audio books Title: test (http://thepiratebay.org/torrent/4377021/test)
[4:42:27][~DOOM_BOT] Result 2: Cat: Video > Movies Title: Heath Ledger Movie Collection 14+1 movies (http://thepiratebay.org/torrent/4377484/Heath_Ledger_Movie_Collection_14_1_movies)
[4:42:27][~DOOM_BOT] Result 3: Cat: Audio > Sound clips Title: The Mancow Show 03 Sept 2008 NOT CF (http://thepiratebay.org/torrent/4377459/The_Mancow_Show_03_Sept_2008_NOT_CF)
I originally tried to write this searching http://isohunt.com but after seeing the sockread it wasnt possible D:
Some searches may take longer than others... Ive seen it take close to two minutes for the results so be patient.
Menu * {
NIGathan's !Torrent
.Options:torrentopt
.Search TPB:torrentseard
.Advertise:describe $active is using NIGathan's !Torrent search. (http://www.hawkee.com/snippet/5061/)
}
alias torrentseard {
unset %t.*
if (%to.optsp != 1) {
if ($?!="Show seeds and leechers?" == $true) set %t.switches -s
}
set %t.resu $?="Find a specific result? $crlf $+ Cancel or leave blank to get the first 3."
:one
if (%t.resu != $null && %t.resu !isnum) { set %t.resu $?="Invalid input. Must be a number. $crlf $+ Find a specific result? $crlf $+ Cancel or leave blank to get the first 3." | goto one }
if (%t.resu) {
if (%t.switches) { set %t.switches %t.switches $+ r }
else { set %t.switches -r }
}
set %t.search $?="What would you like to search for? $crlf $+ Leave blank or click cancel to cancel."
if (%t.search == $null) { unset %t.* | halt }
echo -a torrentsearch: %t.switches %t.resu %t.search
torrentsearch %t.switches %t.resu %t.search
}
alias torrentopt {
dialog -m torrentopts torrentopts
if (%to.optsp == 1) did -c torrentopts 1
did -a torrentopts 5 Description
did -a torrentopts 5 Seeds
did -a torrentopts 5 Leechers/Peers
did -a torrentopts 5 Size
did -a torrentopts 5 Date
did -c torrentopts 5 %to.sort
}
dialog torrentopts {
title "!Torrent Options"
option dbu
size 1 1 110 75
check "Always display seeds/leechers?" 1, 2 1 85 10
text "If this is checked the 's' switch will not be necessary. Although if the 's' switch is seen, it will do the opposite." 2, 2 10 110 20
button "Apply", 3, 2 63 55 10, ok
button "Cancel", 4, 58 63 50 10, cancel
combo 5, 55 40 50 10, drop
text "Default sort method:", 6, 3 42 50 10
box "", 7, 1 35 108 18
}
on *:DIALOG:torrentopts:sclick:3: {
if ($did(torrentopts,1).state == 1) set %to.optsp 1
else set %to.optsp 0
set %to.sort $replace($did(torrentopts,5).seltext,Description,1,Seeds,2,Leechers/Peers,3,Size,4,Date,5)
}
alias torrentsearch {
;window -ak0 @Torrent
set %t.search $1-
set %t.page 0
set %t.sort $replacex(%to.sort,1,99,2,7,3,9,4,5,5,3)
if (%to.optsp == 1) { set %t.seeddis 1 }
if ($left($1,1) == -) {
set %t.switches $mid($1,2-)
set %t.search $2-
if (r isin %t.switches) {
if ($calc($2 / 31) <= 1) {
set %t.tores $2
set %t.resu $2
set %t.search $3-
}
else if ($calc($2 / 31) > 1) {
set %t.page $gettok($calc($2 / 31),1,46)
set %t.tores $calc($2 - ( %t.page * 31))
set %t.resu $2
set %t.search $3-
}
}
if (s isin %t.switches) {
if (%to.optsp == 1) { set %t.seeddis 0 }
else { set %t.seeddis 1 }
}
if (b isin %t.switches) {
if (r isin %t.switches && $2 isnum) {
if (* $+ $3 $+ * iswm %to.sorts) { set %t.sort $replace($3,seeds,7,size,5,leechers,9,peers,9,date,3) | set %t.search $4- }
else if (%t.chan) msg %t.chan I cannot sort by $3 $+ . I can only sort by: %to.sorts $+ .
else echo -a I cannot sort by $3 $+ . I can only sort by: %to.sorts $+ .
}
else if (r isin %t.switches && $3 isnum) {
if (* $+ $2 $+ * iswm %to.sorts) { set %t.sort $replace($2,seeds,7,size,5,leechers,9,peers,9,date,3) | set %t.search $4- }
else if (%t.chan) msg %t.chan I cannot sort by $2 $+ . I can only sort by: %to.sorts $+ .
else echo -a I cannot sort by $2 $+ . I can only sort by: %to.sorts $+ .
if ($calc($3 / 31) <= 1) {
set %t.tores $3
set %t.resu $3
}
else if ($calc($3 / 31) > 1) {
set %t.page $gettok($calc($3 / 31),1,46)
set %t.tores $calc($3 - ( %t.page * 31))
set %t.resu $3
}
}
else if (r !isin %t.switches) {
if (* $+ $2 $+ * iswm %to.sorts) {
set %t.sort $replace($2,seeds,7,size,5,leechers,9,peers,9,date,3)
set %t.search $3-
}
else if (%t.chan) msg %t.chan I cannot sort by $2 $+ . I can only sort by: %to.sorts $+ .
else echo -a I cannot sort by $2 $+ . I can only sort by: %to.sorts $+ .
}
else {
if (%t.chan) msg %t.chan Invalid parameters.
else echo -a Invalid parameters.
}
}
}
set %t.tor 1
set %t.acheck <h2><span>Search results: *
set %t.catcheck <td class="vertTh"><a href="/browse/*
set %t.torcheck <td><a href="/torrent/*
set %t.link $+(http://thepiratebay.org/search/,$phex(%t.search),/,%t.page,/,%t.sort,/0)
set %t.none No hits. Try adding an asterisk
set %t.catr $+($chr(38),gt,$chr(59))
set %t.spcheck <td align="right">
sockopen tpb thepiratebay.org 80
sockmark tpb %t.search
}
on *:TEXT:!torrent *:#: {
set %t.chan $chan
torrentsearch $2-
}
on *:SOCKOPEN:tpb: {
sockwrite -n $sockname GET $+(/search/,$phex($gettok($sock($sockname).mark,1-,32)),/,%t.page,/,%t.sort,/0) HTTP/1.0
sockwrite -n $sockname Host: thepiratebay.org
sockwrite $sockname $crlf
}
on *:SOCKREAD:tpb: {
if ($sockerr) { msg %t.chan Error reading socket info. Please try again. | halt }
var %t.sockshit
sockread %t.sockshit
if (%t.acheck iswm %t.sockshit) {
if (%t.none isin %t.sockshit) { msg %t.chan No results found for " $+ %t.search $+ ". Try adding an asterisk to your search phrase. | unset %t.* | halt }
set %t.ares $gettok(%t.sockshit,$calc($findtok(%t.sockshit,$chr(40) $+ approx,32)+1),32)
}
if (%t.ares < 1) { msg %t.chan Thepiratebay.org returned no results for: " $+ %t.search $+ ". | unset %t.* | halt }
if (%t.tores == $null) {
if ((%t.catcheck iswm %t.sockshit) && %t.tor == 3) { set %t.cat3 $replacex($gettok(%t.sockshit,3,62),%t.catr,$chr(62),</a, ) }
if ((%t.torcheck iswm %t.sockshit) && (title="Details isin %t.sockshit) && %t.tor == 3) {
set %t.tor3 $replacex($gettok(%t.sockshit,3,62),>,$chr(62),</a, )
set %t.link3 http://thepiratebay.org $+ $gettok(%t.sockshit,2,34)
if (%t.seeddis == 1) {
set %t.spc 1
set %t.upc 0
}
else { inc %t.tor }
}
if (%t.seeddis == 1) {
if ((%t.spcheck isin %t.sockshit) && (%t.spc == 1 && %t.upc == 2) && %t.tor == 3) {
set %t.leech3 $remove(%t.sockshit,%t.spcheck,</td>)
unset %t.spc
unset %t.upc
inc %t.tor
}
if ((%t.spcheck isin %t.sockshit) && (%t.spc == 1 && %t.upc == 1) && %t.tor == 3) {
set %t.seed3 $remove(%t.sockshit,%t.spcheck,</td>)
inc %t.upc
}
if ((%t.spcheck isin %t.sockshit) && (%t.spc == 1 && %t.upc == 0) && %t.tor == 3) { inc %t.upc }
}
if ((%t.catcheck iswm %t.sockshit) && %t.tor == 2) { set %t.cat2 $replacex($gettok(%t.sockshit,3,62),%t.catr,$chr(62),</a, ) }
if ((%t.torcheck iswm %t.sockshit) && (title="Details isin %t.sockshit) && %t.tor == 2) {
set %t.tor2 $replacex($gettok(%t.sockshit,3,62),>,$chr(62),</a, )
set %t.link2 http://thepiratebay.org $+ $gettok(%t.sockshit,2,34)
if (%t.seeddis == 1) {
set %t.spc 1
set %t.upc 0
}
else { inc %t.tor }
}
if (%t.seeddis == 1) {
if ((%t.spcheck isin %t.sockshit) && (%t.spc == 1 && %t.upc == 2) && %t.tor == 2) {
set %t.leech2 $remove(%t.sockshit,%t.spcheck,</td>)
unset %t.spc
unset %t.upc
inc %t.tor
}
if ((%t.spcheck isin %t.sockshit) && (%t.spc == 1 && %t.upc == 1) && %t.tor == 2) {
set %t.seed2 $remove(%t.sockshit,%t.spcheck,</td>)
inc %t.upc
}
if ((%t.spcheck isin %t.sockshit) && (%t.spc == 1 && %t.upc == 0) && %t.tor == 2) { inc %t.upc }
}
if ((%t.catcheck iswm %t.sockshit) && %t.tor == 1) { set %t.cat1 $replacex($gettok(%t.sockshit,3,62),%t.catr,$chr(62),</a, ) }
if ((%t.torcheck iswm %t.sockshit) && (title="Details isin %t.sockshit) && %t.tor == 1) {
set %t.tor1 $replacex($gettok(%t.sockshit,3,62),>,$chr(62),</a, )
set %t.link1 http://thepiratebay.org $+ $gettok(%t.sockshit,2,34)
if (%t.seeddis == 1) {
set %t.spc 1
set %t.upc 0
}
else { inc %t.tor }
}
if (%t.seeddis == 1) {
if ((%t.spcheck isin %t.sockshit) && (%t.spc == 1 && %t.upc == 2) && %t.tor == 1) {
set %t.leech1 $remove(%t.sockshit,%t.spcheck,</td>)
unset %t.spc
unset %t.upc
inc %t.tor
}
if ((%t.spcheck isin %t.sockshit) && (%t.spc == 1 && %t.upc == 1) && %t.tor == 1) {
set %t.seed1 $remove(%t.sockshit,%t.spcheck,</td>)
inc %t.upc
}
if ((%t.spcheck isin %t.sockshit) && (%t.spc == 1 && %t.upc == 0) && %t.tor == 1) { inc %t.upc }
}
if (%t.tor == 4 || (%t.sockshit == </html> && %t.tor)) {
if (%t.chan != $null) {
msg %t.chan Approx. %t.ares $+ Results found for " $+ %t.search $+ " at %t.link $+ .
if (%t.seeddis == 1) {
if (%t.link1) msg %t.chan Result 1: Cat: %t.cat1 Title: %t.tor1 Seeds: %t.seed1 Leechers: %t.leech1 ( $+ %t.link1 $+ )
if (%t.link2) msg %t.chan Result 2: Cat: %t.cat2 Title: %t.tor2 Seeds: %t.seed2 Leechers: %t.leech2 ( $+ %t.link2 $+ )
if (%t.link3) msg %t.chan Result 3: Cat: %t.cat3 Title: %t.tor3 Seeds: %t.seed3 Leechers: %t.leech3 ( $+ %t.link3 $+ )
}
else {
if (%t.link1) msg %t.chan Result 1: Cat: %t.cat1 Title: %t.tor1 ( $+ %t.link1 $+ )
if (%t.link2) msg %t.chan Result 2: Cat: %t.cat2 Title: %t.tor2 ( $+ %t.link2 $+ )
if (%t.link3) msg %t.chan Result 3: Cat: %t.cat3 Title: %t.tor3 ( $+ %t.link3 $+ )
}
}
else {
linesep
echo -a Approx. %t.ares $+ Results found for " $+ %t.search $+ " at %t.link $+ .
if (%t.seeddis == 1) {
linesep
if (%t.link1) echo -a Result 1: Cat: %t.cat1 Title: %t.tor1 Seeds: %t.seed1 Leechers: %t.leech1 ( $+ %t.link1 $+ )
if (%t.link2) echo -a Result 2: Cat: %t.cat2 Title: %t.tor2 Seeds: %t.seed2 Leechers: %t.leech2 ( $+ %t.link2 $+ )
if (%t.link3) echo -a Result 3: Cat: %t.cat3 Title: %t.tor3 Seeds: %t.seed3 Leechers: %t.leech3 ( $+ %t.link3 $+ )
linesep
}
else {
linesep
if (%t.link1) echo -a Result 1: Cat: %t.cat1 Title: %t.tor1 ( $+ %t.link1 $+ )
if (%t.link2) echo -a Result 2: Cat: %t.cat2 Title: %t.tor2 ( $+ %t.link2 $+ )
if (%t.link3) echo -a Result 3: Cat: %t.cat3 Title: %t.tor3 ( $+ %t.link3 $+ )
linesep
}
}
unset %t.*
halt
}
}
else {
if (%t.resu > %t.ares) {
if (%t.chan) { msg %t.chan There were only approx. %t.ares $+ results. Please don't try to search beyond that. }
else { linesep | echo -a There were only approx. %t.ares $+ results. Please don't try to search beyond that. | linesep }
unset %t.*
halt
}
if (%t.tor > %t.tores) {
if (%t.chan) {
msg %t.chan Approx. %t.ares $+ Results found for " $+ %t.search $+ " at %t.link $+ .
if (%t.seeddis == 1 && %t.link1) { msg %t.chan Result $+ %t.resu $+ : Cat: %t.cat1 Title: %t.tor1 Seeds: %t.seed1 Leechers: %t.leech1 ( $+ %t.link1 $+ ) }
else if (%t.link1) { msg %t.chan Result $+ %t.resu $+ : Cat: %t.cat1 Title: %t.tor1 ( $+ %t.link1 $+ ) }
}
else {
linesep
echo -a Approx. %t.ares $+ Results found for " $+ %t.search $+ " at %t.link $+ .
if (%t.seeddis == 1) {
if (%t.link1) { echo -a Result $+ %t.resu $+ : Cat: %t.cat1 Title: %t.tor1 Seeds: %t.seed1 Leechers: %t.leech1 ( $+ %t.link1 $+ ) }
}
else if (%t.link1) { echo -a Result $+ %t.resu $+ : Cat: %t.cat1 Title: %t.tor1 ( $+ %t.link1 $+ ) }
linesep
}
unset %t.*
halt
}
if (%t.tor == %t.tores) {
if (%t.catcheck iswm %t.sockshit) { set %t.cat1 $replacex($gettok(%t.sockshit,3,62),%t.catr,$chr(62),</a, ) }
if ((%t.torcheck iswm %t.sockshit) && (title="Details isin %t.sockshit)) {
set %t.tor1 $replacex($gettok(%t.sockshit,3,62),>,$chr(62),</a, )
set %t.link1 http://thepiratebay.org $+ $gettok(%t.sockshit,2,34)
if (%t.seeddis == 1) {
set %t.spc 1
set %t.upc 0
}
else { inc %t.tor }
}
if (%t.seeddis == 1) {
if ((%t.spcheck isin %t.sockshit) && (%t.spc == 1 && %t.upc == 2)) {
set %t.leech1 $remove(%t.sockshit,%t.spcheck,</td>)
unset %t.spc
unset %t.upc
inc %t.tor
}
if ((%t.spcheck isin %t.sockshit) && (%t.spc == 1 && %t.upc == 1)) {
set %t.seed1 $remove(%t.sockshit,%t.spcheck,</td>)
inc %t.upc
}
if ((%t.spcheck isin %t.sockshit) && (%t.spc == 1 && %t.upc == 0)) { inc %t.upc }
}
}
else if (%t.torcheck iswm %t.sockshit) { inc %t.tor }
}
}
;;$phex borrowed from tye's !google script: http://www.hawkee.com/snippet/14/
alias phex {
var %x = 1, %s = $len($1), %r, %w
while (%x <= %s) {
%w = $mid($1,%x,1)
if ($asc(%w) = 32) {
%r = $+(%r,+)
}
elseif ($asc(%w) !isnum 65-90) && ($asc(%w) !isnum 97-122) && ($asc(%w) !isnum 48-57) {
%r = $+(%r,%,$base($asc(%w),10,16,2))
}
else {
%r = $+(%r,%w)
}
inc %x
}
return %r
}
Viper: I started learning with this script, it took me less than two hours to learn AND make it. http://www.mirc.net/projects.php?go=1057960975&get_desc=1 and a few other snippets I had helped.
Thanks greenlanter420 :D
It's easy once you get the hang of it viper, basically all you do is loop through each html line and grab data.
;open the socket with /sockopen [sockname] [www.site.com] 80
on *:sockopen:[sockname]:{
sockwrite -nt $sockname GET [/directory/file.html] HTTP/1.1
sockwrite -nt $sockname Host: [www.site.com]
sockwrite -nt $sockname $crlf
}
on *:sockread:[sockname]:{
var %x
sockread %x
;%x represents the html line
[if (something isin %x) { ;parse the line to get data }]
}
mountaindew: Hmm, thats strange. It happens every time? Or just some of the time?
It always works fine for me, Ill add some checks for it though and see if I can fix it.
greenlanter: I dont think it says anything, as of yet, if there arent any results. When I was writing it I didnt think to search for something that wouldnt have any results. So in other words, Im not exactly sure what to look for to check for that, but Ill add it here pretty soon when I get a chance.
Works for me greenlanter.
NIGathan, for some reason %t.chan is $null when it msg's the Approx...line, it does "msg Approx. ..." and then says Approx. Unkown nick.
msg %t.chan Approx. %t.ares $+ Results found for " $+ %t.search $+ " at %t.link $+ .
Not sure why it works for the lines under it though :/
what does that mean?