Advertisement
mruno

!imdb 23.May.2017 - working (m.imdb.com)

Oct 2nd, 2013
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 21.34 KB | None | 0 0
  1. ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. ;script !imdb Script
  3. ;version 23.May.2017
  4. ;author mruno
  5. ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  6. ;23.May.2017 fixed movie plot
  7. ;18.NOV.2014 runtime and release date fix for movies like top dog 2014
  8. ;16.NOV.2014 Director Fix
  9. ;JULY.2014: will now detect imdb.com URLs in text and show the info
  10. ;type enable trailer links (when available with: /set %imdb.trailer on
  11. ;
  12. ;actor fixes
  13. ;Removed tagline
  14. ;Fixed new formatting on imdb.com
  15. ;Fixed rating on some titles (John Crowley)
  16. ;added link to trailers
  17. ;
  18. on *:TEXT:*:#: {
  19.   if ($chr(36) isin $2-) return
  20.   if ($1 == !imdb) || ($1 == !imdb2) {
  21.     if (!$findtok(%imdb2,$nick,0,46)) {
  22.       set -u10 %theatre $addtok(%imdb2,$nick,46)
  23.       var %a = imdb2
  24.       if ($hget(%a)) hfree %a
  25.       h %a chan $chan
  26.       h %a cid $cid
  27.       h %a nick $nick
  28.       h %a network $network
  29.       imdb2 $nick $2-
  30.     }
  31.     else .timerimdb2. $+ $nick 1 1 .notice $nick Please wait 10 seconds and try again...
  32.   }
  33.   elseif (*imdb.com/title/tt*/* iswm $1-) {
  34.     var %url $1-
  35.     var %tt $gettok(%url,$calc($findtok(%url,title,47) + 1),47)
  36.     if (tt isin %tt) {
  37.       if (!$findtok(%imdb2,$nick,0,46)) {
  38.         set -u10 %theatre $addtok(%imdb2,$nick,46)
  39.         var %a imdb2
  40.         if ($hget(%a)) hfree %a
  41.         h %a chan $chan
  42.         h %a cid $cid
  43.         h %a nick $nick
  44.         h %a network $network
  45.         imdb2 $nick %tt
  46.       }
  47.     }
  48.   }
  49.   elseif (*imdb.com/name/nm*/* iswm $1-) {
  50.     var %url $1-
  51.     var %tt $gettok(%url,$calc($findtok(%url,name,47) + 1),47)
  52.     if (nm isin %tt) {
  53.       if (!$findtok(%imdb2,$nick,0,46)) {
  54.         set -u10 %theatre $addtok(%imdb2,$nick,46)
  55.         var %a imdb2
  56.         if ($hget(%a)) hfree %a
  57.         h %a chan $chan
  58.         h %a cid $cid
  59.         h %a nick $nick
  60.         h %a network $network
  61.         imdb2 $nick %tt
  62.       }
  63.     }
  64.   }
  65. }
  66. on *:INPUT:#:{
  67.   if ($1 == !imdb) || ($1 == !imdb2) {
  68.     var %a = imdb2
  69.     if ($hget(%a)) hfree %a
  70.     h %a chan $chan
  71.     h %a network $network
  72.     h %a cid $cid
  73.     h %a nick $me
  74.     imdb2 $me $2-
  75.   }
  76. }
  77. alias -l imdbhelp {
  78.   var %cmd = .notice $1
  79.   %cmd !iMDb[2] by mruno. Usage: !imdb [option] <title or ID>
  80.   %cmd Options:
  81.   %cmd       Result types: Movie or Actor (Default is Movies) - "!imdb monica" - Performs a movie search and "!imdb -a monica" will perform an actor search.
  82.   %cmd       List results (Default is 5, Max of 10). Example: "!imdb -l5 hobbit" - Lists the top 5 search results.
  83.   %cmd       Recommended results (Default is 5, Max of 9). "!imdb -r5 hobbit" - Recommends movies based on the movie (or movie code) you specified.
  84. }
  85. alias imdb2 {
  86.   var %h imdb2
  87.   if (!$2) { imdbhelp $1 | return }
  88.   if ($2 == -r) || ($2 == -l) || ($2 == -a) && (!$3) { imdbhelp $1 | return }
  89.   elseif ($left($2,2) == -l) {
  90.     .timerimdb2.gclean 0 60 imdb2.gclean
  91.     var %a, %b, %p, %u, %o, %query
  92.     if ($left($3,2) == tt) && ($remove($3,tt,/) isnum) {
  93.       h %h results 1
  94.       h %h result 1
  95.       h %h query code.movie
  96.     }
  97.     else {
  98.       h %h results $iif($remove($2,-l),$remove($2,-l),5)
  99.       h %h result $iif($remove($2,-l),$remove($2,-l),5)
  100.       h %h query list
  101.     }
  102.  
  103.     set %query $replace($3-,$chr(32),+,.,+,-,+)
  104.     h %h text %query
  105.  
  106.     ;.notice $h(%h ,nick) Searching iMDb.com...
  107.     set %u http://m.imdb.com/find?q= $+ %query
  108.     h %h u %u
  109.     imdb2.download imdb2.search %u imdb2.txt
  110.     ;echo -a ------ %u ---------------
  111.   }
  112.   elseif ($left($2,2) == -r) {
  113.     .timerimdb2.gclean 0 60 imdb2.gclean
  114.     var %a, %b, %p, %u, %o, %query
  115.     h %h results $iif($remove($2,-r),$remove($2,-r),5)
  116.     h %h result $iif($remove($2,-r),$remove($2,-r),5)
  117.     h %h query recommend
  118.  
  119.     set %query $replace($3-,$chr(32),+,.,+,-,+)
  120.     h %h text %query
  121.  
  122.     ;.notice $h(%h ,nick) Searching iMDb.com...
  123.     set %u http://m.imdb.com/find?q= $+ %query
  124.     h %h u %u
  125.     if ($left($3,2) == tt) && ($remove($3,tt,/) isnum) {
  126.       h %h url http://www.imdb.com/title/ $+ $h(%h,text)
  127.       imdb2.download imdb2.results http://m.imdb.com/title/ $+ $h(%h,text) imdb2.txt
  128.     }
  129.     else imdb2.download imdb2.search %u imdb2.txt
  130.  
  131.     ;echo -a ------ %u ---------------
  132.   }
  133.   elseif ($2 == -a) {
  134.     .timerimdb2.gclean 0 60 imdb2.gclean
  135.     var %a, %b, %p, %u, %o, %query
  136.     h %h results 1
  137.     h %h result 1
  138.     h %h query actor
  139.  
  140.     set %query $replace($3-,$chr(32),+,.,+,-,+)
  141.     h %h text %query
  142.  
  143.     ;.notice $h(%h ,nick) Searching iMDb.com...
  144.     set %u http://m.imdb.com/find?q= $+ %query
  145.     h %h u %u
  146.     imdb2.download imdb2.search %u imdb2.txt
  147.     ;echo -a ------ %u ---------------
  148.   }
  149.   else {
  150.     .timerimdb2.gclean 0 60 imdb2.gclean
  151.     var %a, %b, %p, %u, %o, %query
  152.     h %h results 1
  153.     h %h result 1
  154.     if ($left($2,2) == nm) && ($remove($2,nm,/) isnum) h %h query code.actor
  155.     elseif ($left($2,2) == tt) && ($remove($2,tt,/) isnum) h %h query code.movie
  156.     else h %h query movie
  157.  
  158.     set %query $replace($2-,$chr(32),+,.,+,-,+)
  159.     h %h text %query
  160.  
  161.     ;.notice $h(%h,nick) Searching iMDb.com...
  162.     set %u http://m.imdb.com/find?q= $+ %query
  163.     h %h u %u
  164.     imdb2.download imdb2.search %u imdb2.txt
  165.     ;echo -a ------ %u ---------------
  166.   }
  167. }
  168. alias -l imdb2.search {
  169.   ;this alias is triggered once the search page is downloaded
  170.   if ($1 == 1) && ($2 == S_OK) {
  171.     var %a = @imdb2, %b, %d = 0, %e, %z = 0, %t, %cmd, %h = imdb2, %raw, %h = imdb2
  172.     if ($window(%a)) window -c %a
  173.     window -h %a
  174.     loadbuf %a imdb2.txt
  175.  
  176.     ;this removes extra crap from the beginning of the webpage
  177.     ;<a href="/title/
  178.     if ($h(%h,query) == actor) dline %a 1- $+ $calc($fline(%a,*<a href="/name/*,1) - 8)
  179.     elseif ($h(%h,query) == movie) dline %a 1- $+ $calc($fline(%a,*<a href="/title/*,1) - 8)
  180.  
  181.     elseif ($h(%h,query) == code.actor) {
  182.       h %h url http://www.imdb.com/name/ $+ $h(%h,text)
  183.       imdb2.download imdb2.results http://m.imdb.com/name/ $+ $h(%h,text) imdb2.txt
  184.       goto end
  185.     }
  186.     elseif ($h(%h,query) == code.movie) {
  187.       h %h url http://www.imdb.com/title/ $+ $h(%h,text)
  188.       imdb2.download imdb2.results http://m.imdb.com/title/ $+ $h(%h,text) imdb2.txt
  189.       goto end
  190.     }
  191.     elseif ($h(%h,query) == list) {
  192.       dline %a 1- $+ $calc($fline(%a,*<h1>Search results</h1>*,1) - 8)
  193.  
  194.       var %loop = 1
  195.       dualcmd [iMDb] Movie List Results:
  196.       ;while ($fline(%a,**<a href="*" onClick="**,%loop)) {
  197.       while ($fline(%a,*<a href="/title/tt*,%loop)) {
  198.         var %match = $ifmatch
  199.         dualcmd      %loop $+ ) $striphtml($line(%a,%match))   -   Code:  $+ $gettok($line(%a,%match),3,47) $+ 
  200.         inc %loop
  201.         if (%loop > 10) || (%loop > $h(%h,results)) break
  202.       }
  203.       dualcmd Type !imdb <code> for more info
  204.       goto end
  205.     }
  206.     else dline %a 1- $+ $calc($fline(%a,*<a href="/title/*,1) - 8)
  207.  
  208.  
  209.     if ($fline(%a,*<div class="noResults">No Results</div>*,1)) {
  210.       dualcmd No results for: $replace($h(%h,text),+,$chr(32))
  211.       .timerimdb2.gclean 1 60 imdb2.gclean
  212.       return
  213.     }
  214.  
  215.     ;this records initial data from search page.
  216.     set %raw $line(%a,$calc($fline(%a,*<div class="title">*,1) + 1))
  217.     h %h title $striphtml(%raw)
  218.     h %h url http://www.imdb.com $+ $gettok(%raw,2,34)
  219.  
  220.     if ($striphtml($line(%a,$fline(%a,*<div class="detail">*,1)))) h %h cast $ifmatch
  221.     :recommend
  222.     if ($h(%h,query) == recommend) imdb2.download imdb2.recommend http://www.imdb.com $+ $gettok(%raw,2,34) $+ recommendations imdb2.txt
  223.     ;echo -s http://www.imdb.com $+ $gettok(%raw,2,34) $+ recommendations
  224.     else {
  225.       ;time to download the title's webpage
  226.       imdb2.download imdb2.results http://m.imdb.com $+ $gettok(%raw,2,34) imdb2.txt
  227.     }
  228.     :end
  229.   }
  230.   else $iif($h(imdb2,nick) == $me || !$h(imdb2,nick),.notice $me,msg $h(imdb2,chan)) Error downloading data - 1. See  $+ $replace($h(imdb2,u),http://m.,http://www.)
  231.   .timerimdb2.gclean 1 60 imdb2.gclean
  232. }
  233.  
  234. alias -l imdb2.recommend {
  235.   ;this alias parses the recommended info
  236.   if ($1 == 1) && ($2 == S_OK) {
  237.     var %a = @imdb2, %h = imdb2
  238.     if ($window(%a)) window -c %a
  239.     window -h %a
  240.     loadbuf %a imdb2.txt
  241.  
  242.     var %1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %loop = 0, %raw
  243.     if ($fline(%a,*<b>Suggested by the database</b>*,0)) {
  244.       while (%loop < $h(imdb2,result)) {
  245.         inc %loop
  246.  
  247.         set %raw $matchtok($line(%a,$calc($fline(%a,*<b>Suggested by the database</b>*,1) + 4)),<a href="/title/,%loop,44)
  248.  
  249.         if ($striphtml($gettok($gettok(%raw,2,60),2,62))) h %h title $+ %loop $striphtml($gettok($gettok(%raw,2,60),2,62))
  250.         if ($gettok($gettok(%raw,2,40),1,41) isnum) h %h year $+ %loop ( $+ $gettok($gettok(%raw,2,40),1,41) $+ )
  251.         if ($remove($gettok($striphtml(%raw),$gettok($striphtml(%raw),0,41),41),.,$chr(32)) isnum) h %h rating $+ %loop $gettok($striphtml(%raw),$gettok($striphtml(%raw),0,41),41)
  252.         if ($left($gettok($gettok($gettok(%raw,2,60),1,62),3,47),2) == tt) h %h code $+ %loop $gettok($gettok($gettok(%raw,2,60),1,62),3,47)
  253.       }
  254.  
  255.       if ($h(%h,title1)) {
  256.         dualcmd [iMDb] Recommended Movies 14(based on $h(%h,title) $+ ) $+ :
  257.         var %loopecho = 1
  258.         while ($h(%h,title $+ %loopecho)) {
  259.  
  260.           dualcmd      %loopecho $+ ) $h(%h,title $+ %loopecho) $iif($h(%h,year $+ %loopecho),$h(%h,year $+ %loopecho)) $iif($h(%h,rating $+ %loopecho),Rating: $h(%h,rating $+ %loopecho)) $iif($h(%h,code $+ %loopecho),  -   Code:  $+ $h(%h,code $+ %loopecho))
  261.           inc %loopecho
  262.           if (%loopecho > 9) || (%loopecho > $h(%h,results)) break
  263.  
  264.         }
  265.  
  266.         dualcmd Type !imdb <code> for more info
  267.       }
  268.     }
  269.     else dualcmd There are no recommendations for: $h(%h,title)
  270.     .timerimdb2.gclean 1 60 imdb2.gclean
  271.   }
  272.   else $iif($h(imdb2,nick) == $me,.notice $me,msg $h(imdb2,chan)) Error downloading data - 2. See  $+ $replace($h(imdb2,u),http://m.,http://www.)
  273.   .timerimdb2.gclean 1 60 imdb2.gclean
  274. }
  275.  
  276. alias -l imdb2.results {
  277.   ;this alias parses the results info
  278.   if ($1 == 1) && ($2 == S_OK) {
  279.     var %a = @imdb2, %b, %d = 0, %e, %z = 0, %t, %cmd, %h = imdb2, %raw
  280.     if ($window(%a)) window -c %a
  281.     window -h %a
  282.     loadbuf %a imdb2.txt
  283.  
  284.     ;this removes extra crap from the beginning of the webpage
  285.     if (movie isin $h(%h,query)) noop
  286.     else dline %a 1- $+ $calc($fline(%a,*</title>*,1) - 2)
  287.  
  288.     if (/name/ isin $h(%h,url)) {
  289.       ;this is for actors
  290.       if (!$h(%h,title)) h %h title $striphtml($line(%a,$fline(%a,*<div class="title">*,1)))
  291.  
  292.       h %h birthname $striphtml($line(%a,$calc($fline(%a,*<h3>Born</h3>*,1) + 2)))
  293.       h %h birthdate $line(%a,$calc($fline(%a,*<strong>Born:</strong>*,1) + 3)) $line(%a,$calc($fline(%a,*<strong>Born:</strong>*,1) + 5))
  294.       h %h birthplace $striphtml($line(%a,$calc($fline(%a,*<h3>Born</h3>*,1) + 11)))
  295.  
  296.       ;'known for' loop
  297.       var %loop = 1, %titles
  298.       while ($fline(%a,*<a href="/title/*,%loop)) {
  299.         set %titles $addtok( %titles, $striphtml($line(%a,$ifmatch)), 44)
  300.         inc %loop
  301.       }
  302.       h %h knownfor $replace(%titles,$chr(44),$chr(44) $chr(32))
  303.  
  304.       ;h %h Bio $striphtml($line(%a,$calc($fline(%a,*<h1>Mini Biography</h1>*,1) + 2)))
  305.       h %h Bio $line(%a,$calc($fline(%a,*<a href="bio?ref_=m_mn_ov_bio" class="btn-full" > <p>*,1) + 1))
  306.       h %h news $striphtml($line(%a,$calc($fline(%a,*<h1>News</h1>*,1) + 3)))
  307.       if (- imdb !isin $line(%a,$calc($fline(%a,*<h3>Trademark</h3>*,1) + 2))) h %h trademark $v2
  308.  
  309.     }
  310.     else {
  311.       ;this is for movies
  312.       if (!$h(%h,title)) h %h title $remove($striphtml($line(%a,$fline(%a,*<title>*- IMDb*,1))), - IMDb)
  313.  
  314.       if ($h(%h,query) == recommend) {
  315.         imdb2.download imdb2.recommend http://www.imdb.com/title/ $+ $h(%h,text) $+ /recommendations imdb2.txt
  316.         goto endofresults
  317.       }
  318.  
  319.       if ($line(%a,$fline(%a,*<strong>Play Trailer</strong>*,1))) && (%imdb.trailer == on) && ($gettok($gettok($ifmatch,5,47),1,63)) h %h trailer www.imdb.com/video/imdb/ $+ $gettok($gettok($ifmatch,5,47),1,63)
  320.  
  321.       ;<span class="button-1 primary"><a href="/video/imdb/vi2340006169">Watch Trailer</a></span>
  322.  
  323.       ;h %h tagline $striphtml($line(%a,$calc($fline(%a,* $+ $gettok($h(imdb2,title),1,40) $+ *,1) + 1)))
  324.       ;if ($striphtml($line(%a,$calc($fline(%a,*<h1>Director*</h1>*,1) + 2)))) h %h director $ifmatch
  325.       if ($striphtml($line(%a,$calc($fline(%a,*<h3 class="inline-block">Director:</h3>*,1) + 2)))) h %h director $ifmatch
  326.       ;if ($striphtml($line(%a,$calc($fline(%a,*<h1>Release Date</h1>*,1) + 1)))) h %h releasedate $ifmatch
  327.       if ($striphtml($line(%a,$calc($fline(%a,*<h3 class="inline-block">Release Date:</h3>*,1) + 1)))) h %h releasedate $ifmatch
  328.       ;genre loop
  329.       var %loop 0
  330.       while ($fline(%a,*<span class="itemprop" itemprop="genre">*,0) > %loop) {
  331.         inc %loop
  332.         if ($striphtml($line(%a,$calc($fline(%a,*<span class="itemprop" itemprop="genre">*,%loop) + 0)))) h %h genre $addtok($ifmatch,$h(%h,genre),32)
  333.       }
  334.       if ($striphtml($line(%a,$calc($fline(%a,*<time itemprop="duration"*,1) + 1)))) h %h runtime $ifmatch
  335.       if ($len($h(%h,runtime)) > 10) h %h runtime 0
  336.       if ($line(%a,$calc($fline(%a,*<span title="*,1) + 0))) h %h rating $gettok($ifmatch,2,34)
  337.       if ($striphtml($line(%a,$calc($fline(%a,*<p itemprop="description" class="plot-description">*,1) + 1)))) h %h plot $remove($ifmatch,See full summary »)
  338.       if ($striphtml($line(%a,$calc($fline(%a,*<span class="mobile-sprite yellow-star">*,1) + 0)))) {
  339.         var %score $gettok($remove($ifmatch,$chr(32)),1,47)
  340.         var %votes $gettok($ifmatch,3,32)
  341.         if (needs isin %score) || ($remove(%score,.) == Rate this movie) || (!%score) || (!%votes) h %h score none
  342.         else {
  343.           h %h score %score
  344.           h %h votes %votes
  345.         }
  346.       }
  347.     }
  348.     imdb2.complete
  349.  
  350.   }
  351.   else $iif($h(imdb2,nick) == $me,.notice $me,msg $h(imdb2,chan)) Error downloading data - 3. See  $+ $replace($h(imdb2,u),http://m.,http://www.)
  352.   :endofresults
  353.   .timerimdb2.gclean 1 60 imdb2.gclean
  354. }
  355.  
  356. alias -l imdb2.complete {
  357.   ;this alias produces the text
  358.   var %h = imdb2
  359.   if (/name/ isin $h(%h,url)) {
  360.     dualcmd [iMDb] $h(%h,title) $+  $chr(40) 12 $+ $h(%h,url) $+  $chr(41)
  361.     dualcmd $iif($h(%h,birthname),Born: $h(%h,birthname)) $iif($h(%h,birthdate) && java !isin $h(%h,birthdate),Birthday: $h(%h,birthdate)) $iif($h(%h,birthplace) && commentary !isin $h(%h,birthplace),Birthplace: $h(%h,birthplace))
  362.     dualcmd $iif($h(%h,trademark),Trademark: $h(%h,trademark))
  363.     dualcmd $iif($h(%h,knownfor),Known for: $h(%h,knownfor))
  364.     dualcmd $iif($h(%h,bio),Biography: $h(%h,bio))
  365.     dualcmd $iif($h(%h,news),News: $h(%h,news))
  366.   }
  367.   else {
  368.     dualcmd [iMDb] $h(%h,title) $+  $chr(40) 12 $+ $h(%h,url) $+  $chr(41)
  369.     dualcmd $iif($h(%h,rating),Rated: $h(%h,rating)) $iif($h(%h,releasedate),Released: $h(%h,releasedate)) $iif($h(%h,runtime),Runtime: $h(%h,runtime)) $iif($h(%h,genre),Genre: $h(%h,genre))
  370.     dualcmd $iif($h(%h,tagline),Tagline: $h(%h,tagline)) $iif($h(%h,trailer),Trailer:  $+ http:// $+ $h(%h,trailer) $+ )
  371.     dualcmd $iif($h(%h,director),Director: $h(%h,director)) $iif($h(%h,cast),Cast: $replace($h(%h,cast),$chr(187),$chr(44)))
  372.     dualcmd $iif($h(%h,plot),Plot: $h(%h,Plot))
  373.  
  374.     var %r = $h(%h,score)
  375.     if (rate this isin %r) || (%r == n/a) || (!%r) || (%r == none) dualcmd Rating: none
  376.     else dualcmd Rating: $chr(91) $+ $iif(%r > .55,12,) $+ * $+ $iif(%r > 1.55,12,) $+ * $+ $iif(%r > 2.55,12,) $+ * $+ $iif(%r > 3.55,12,) $+ * $+ $iif(%r > 4.55,12,) $+ * $+ $iif(%r > 5.55,12,) $+ * $+ $iif(%r > 6.55,12,) $+ * $+ $iif(%r > 7.55,12,) $+ * $+ $iif(%r > 8.55,12,) $+ * $+ $iif(%r > 9.55,12,) $+ *] %r $+ /10 $paren($h(%h,votes) votes)
  377.   }
  378.   .timerimdb2.gclean 1 60 imdb2.gclean
  379. }
  380.  
  381. alias -l h {
  382.   if ($1 == isnum) return
  383.   if (!$2) { echo -a error: no 2 for hash table | return }
  384.   if (!$hget($1)) hmake $1 10
  385.   if ($isid) return $hget($1,$2)
  386.   else hadd $1 $2-
  387. }
  388. alias -l dualcmd {
  389.   if ($1) {
  390.     if ($me ison $h(imdb2,chan)) msg $h(imdb2,chan) $1-
  391.   }
  392. }
  393. alias -l paren {
  394.   if ($3) return $2 $+ $1 $+ $3
  395.   elseif ($2) return $2 $+ $1 $+ $2
  396.   elseif ($1 != $null) return ( $+ $1- $+ )
  397. }
  398. alias imdb2.gclean {
  399.   ;this removes the hash tables that were used AND closes @imdb2
  400.   if (%imdb2) return
  401.   var %r = 0
  402.   while (%r < $hget(imdb2,results)) {
  403.     inc %r
  404.     if ($hget(imdb2. $+ $hget(imdb2,query) $+ %r)) hfree $ifmatch
  405.   }
  406.   set %r $hget(0)
  407.   while (%r) {
  408.     dec %r
  409.     if (imdb2.* iswm $hget(%r)) hfree $v2
  410.   }
  411.   if ($hget(imdb2)) hfree $ifmatch
  412.   set %r $findfile($mircdir,imdb2*.txt,0,1,.remove $1-)
  413.   set %r $findfile($mircdir,imdb2.download*.vbs,0,1,.remove $1-)
  414.   if ($window(@imdb2)) window -c @imdb2
  415.   unset %imdb2
  416. }
  417.  
  418. on 1:UNLOAD:{
  419.   imdb2.gclean
  420. }
  421.  
  422. ;==================================================================================
  423. ;Author  : fubar
  424. ;Function: $striphtml identifier
  425. ;          This identifier strips html code from a string of text.
  426. ;         Good for using when retrieving webpages within mirc.  
  427. ;==================================================================================
  428. ;
  429. ;This identifier strips html code from a string of text. Good for using when retrieving webpages within mirc.
  430. ;
  431. ;Usage: $striphtml(html code)
  432. alias -l Xchr {
  433.   var %return $regsubex($regsubex($1-,/&#x([A-F0-9]{1,2});/g,$chr($base($regml(\n),16,10))),/&#([0-9]{2});/g,$chr(\1))
  434.   return $replacecs(%return,&ndash;,–,&middot;,·,&raquo;,»,&laquo;,«,&Uuml;,Ü,&uuml;,ü,&Aacute;,Á,&aacute;,á,&Eacute;,$&
  435.     É,&eacute;,é,&Iacute;,Í,&iacute;,í,&Oacute;,Ó,&oacute;,ó,&Ntilde;,Ñ,&ntilde;,ñ,&Uacute;,Ú,&uacute;,ú,&nbsp;,$chr(32),$&
  436.     &aelig;,æ,&quot;,")
  437. }
  438. alias -l striphtml {
  439.   ; making sure there are parameters to work with
  440.   IF ($1) {
  441.     ; Setting my variables. The %opt is set kind of funky
  442.     ; all it does is combine <two><brackets> into 1 <twobrackets>, fewer loops this way
  443.     ; also stripped tab spaces
  444.     VAR %strip,%opt = <> $remove($1-,> <,><,$chr(9)) <>,%n = 2
  445.     ; using $gettok() I checked the text in front of '>' (chr 62)
  446.     ; then the second $gettok checks the text behind '<' (chr 60)
  447.     ; so I'm extracting anything between >text<
  448.     WHILE ($gettok($gettok(%opt,%n,62),1,60)) {
  449.       ; take each peice of text and add it to the same variable
  450.       %strip = %strip $ifmatch
  451.       %strip = $replace(%strip,&quot;,")
  452.       ; increase the variable so the while statement can check the next part
  453.       INC %n
  454.     }
  455.     ; now that the loop has finished we can return the stripped html code
  456.     RETURN $Xchr(%strip)
  457.   }
  458. }
  459.  
  460. ;/download by SReject
  461. ;http://www.hawkee.com/snippet/9318/
  462. alias imdb2.download {
  463.   if ($regex(Args,$1-,^-c (?|(?:"(?=.+")([^"]+)")|(\S+)) (\S+) (?|(?:"(?=.+")([^"]+)")|(\S+)) (\S+)$)) {
  464.     var %callback = $regml(Args,1)
  465.     var %url = $regml(Args,2)
  466.     var %file = $qt($regml(Args,3))
  467.     var %com = $regml(Args,4)
  468.     var %r = $iif($comerr,1,$com(%com).result)
  469.     .remove $qt($scriptdir $+ %com)
  470.     if ($com(%com)) { .comclose %com }
  471.  
  472.     if (%r == -1) { %callback 1 S_OK %url $qt(%file) }
  473.     elseif (%r == 1) { %callback 0 UnKnown_ComErr %url $qt(%file) }
  474.     elseif (%r == 2) { %callback 0 IE6+_Needed %url $qt(%file) }
  475.     elseif (%r == 3) { %callback 0 Connect_Error %url $qt(%file) }
  476.     elseif (%r == 4) { %callback 0 Newer_ActiveX_Needed %url $qt(%file) }
  477.     elseif (%r == 5) { %callback 0 Writefile_Error %url $qt(%file) }
  478.     else { %callback 0 Unknown_Error %url $qt(%file) }
  479.   }
  480.   elseif ($1 != -c) {
  481.     if ($isid) || (!$regex(Args,$1-,^(?|(?:"(?=.+")([^"]+)")|(\S+)) (\S+) (?|(?:"(?=.+")([^"]+)")|(\S+))$)) || ($regml(Args,0) != 3) { return }
  482.  
  483.     var %callback = $regml(Args,1)
  484.     var %url = $qt($regml(Args,2))
  485.     var %file = $qt($iif(: isin $regml(Args,3),$v2,$mircdir $+ $v2))
  486.     var %com = imdb2.download $+ $ticks $+ .vbs
  487.     var %s = $qt($scriptdir $+ %com)
  488.     var %w = write %s
  489.  
  490.     %w on error resume next
  491.     %w Set C = CreateObject("msxml2.xmlhttp.3.0")
  492.     %w if (err.number <> 0) then
  493.     %w   err.clear
  494.     %w   set C = CreateObject("msxml2.xmlhttp")
  495.     %w   if (err.number <> 0) then
  496.     %w     err.clear
  497.     %w     set C = CreateObject("XMLHttpRequest")
  498.     %w     if (err.number <> 0) then wscript.quit(2)
  499.     %w   end if
  500.     %w end if
  501.     %w C.open "GET", %url $+ , false
  502.     %w C.send
  503.     %w if (err.number <> 0) then wscript.quit(3)
  504.     %w set O = createobject("adodb.stream")
  505.     %w if (err.number <> 0) then wscript.quit(4)
  506.     %w O.type=1
  507.     %w O.mode=3
  508.     %w O.open
  509.     %w O.write C.responsebody
  510.     %w O.savetofile %file $+ ,2
  511.     %w if (err.number <> 0) then wscript.quit(5)
  512.     %w O.close
  513.     %w wscript.quit(-1)
  514.  
  515.     .comopen %com WScript.Shell
  516.     if ($comerr || !$comcall(%com,imdb2.download -c $qt(%callback) $noqt(%url) %file,run,1,bstr*,%s,uint,1,bool,true)) { goto error }
  517.     return
  518.   }
  519.   :error
  520.   if ($error) { reseterror }
  521.   if ($isfile(%s)) { .remove %s }
  522.   if ($com(%com)) { .comclose %com }
  523. }
  524. alias -l Xchr {
  525.   var %return $regsubex($regsubex($1-,/&#x([A-F0-9]{1,2});/g,$chr($base($regml(\n),16,10))),/&#([0-9]{2});/g,$chr(\1))
  526.   return $replacecs(%return,&ndash;,–,&middot;,·,&raquo;,»,&laquo;,«,&Uuml;,Ü,&uuml;,ü,&Aacute;,Á,&aacute;,á,&Eacute;,$&
  527.     É,&eacute;,é,&Iacute;,Í,&iacute;,í,&Oacute;,Ó,&oacute;,ó,&Ntilde;,Ñ,&ntilde;,ñ,&Uacute;,Ú,&uacute;,ú,&nbsp;,$chr(32),$&
  528.     &aelig;,æ,&quot;,")
  529. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement