Advertisement
Ford

Youtube search and download for mIRC

Sep 30th, 2012
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 10.71 KB | None | 0 0
  1. ;Youtube Video Downloader by Ford_Lawnmower irc.Geekshed.net #Script-Help
  2. menu * {
  3.   Youtube Video Downloader: dialog $iif($dialog(Y_V_D),-v,-md) Y_V_D Y_V_D
  4. }
  5. alias -l YoutubeSearch {
  6.   if ($sock(YoutubeSearch)) { sockclose YoutubeSearch }
  7.   sockopen YoutubeSearch www.youtube.com 80
  8.   sockmark YoutubeSearch $+(/results?search_type=videos&aq=f&search_query=,$replace($1-,$chr(32),+))
  9. }
  10. On *:sockopen:YoutubeSearch: {
  11.   if (!$sockerr) {
  12.     did -r Y_V_D 3,13,17-20
  13.     sockwrite -nt $sockname GET $sock($sockname).mark HTTP/1.0
  14.     sockwrite -n $sockname Host: www.youtube.com
  15.     sockwrite -n $sockname $crlf
  16.   }
  17.   else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  18. }
  19. On *:sockread:YoutubeSearch: {
  20.   if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  21.   else {
  22.     var %Youtube | sockread %Youtube
  23.     if (No video results isin %Youtube) {
  24.       did -a Y_V_D 3,13 No results were found for your search!
  25.       hfree $sockname
  26.       sockclose $sockname
  27.     }
  28.     elseif ($regex(%Youtube,/"title="([^"]*)".*href="\/watch\?v=(.*?)"/i)) {
  29.       hadd -m $sockname id $regml(2)      
  30.       hadd -m $sockname title $fix($regml(1))
  31.     }  
  32.     elseif ($regex(%Youtube,/username-prepend">.*dir="ltr">(.+?)<\/a/i)) {
  33.       hadd -m $sockname user $regml(1)
  34.       var %s $sockname      
  35.       GetThumb i3.ytimg.com $+(/vi/,$hget(%s,id),/default.jpg) YouTubeThumbs $+($calc($did(Y_V_D,13).lines + 1),.jpg)
  36.       did -a Y_V_D 3,13 $hget(%s,title)
  37.       did -a Y_V_D 19 $hget(%s,user)
  38.       did -a Y_V_D 17 $hget(%s,views)
  39.       did -a Y_V_D 18 $hget(%s,date)
  40.       did -a Y_V_D 20 $hget(%s,id)      
  41.     }
  42.     elseif ($regex(%Youtube,/<span class="date-added">([^<]*)<\/span>/i)) hadd -m $sockname date $regml(1)
  43.     elseif ($regex(%Youtube,/<span class="viewcount">([^<]*) views<\/span>/i)) {
  44.       hadd -m $sockname views $regml(1)
  45.     }
  46.     elseif (</body> isin %youtube) {
  47.       did -c Y_V_D 3,13,17-20 1
  48.       hfree $sockname
  49.       sockclose $sockname
  50.       .timer 1 3 did -g Y_V_D 5 youtubethumbs/1.jpg
  51.     }
  52.   }
  53. }
  54. alias -l fix { return $regsubex($remove($replace($1-,&amp;,&,&quot;,"),amp;),/&#([0-9]{2});/gi,$chr(\t)) }
  55. dialog Y_V_D {
  56.   title "Youtube Video Downloader"
  57.   size -1 -1 231 238
  58.   option dbu
  59.   edit "", 1, 4 11 173 10, autohs
  60.   button "Search / Get", 2, 181 9 46 12
  61.   combo 3, 2 40 90 9
  62.   text "Results", 4, 100 31 127 8, center
  63.   icon 5, 7 55 79 69
  64.   text "Views:", 9, 4 134 25 8, right
  65.   text "Added:", 10, 4 149 25 8, right
  66.   text "User:", 11, 4 163 25 8, right
  67.   text "Video ID:", 12, 4 177 25 8, right
  68.   list 13, 100 40 126 175
  69.   combo 17, 33 133 60 9
  70.   combo 18, 33 148 60 9
  71.   combo 19, 33 162 60 9
  72.   combo 20, 33 176 60 9
  73.   button "Download", 22, 144 219 39 12
  74.   button "Play", 23, 188 219 39 12
  75.   text "Video Title", 24, 2 31 90 8, center
  76. }
  77. On *:dialog:Y_V_D:Sclick:2,13,21-23: {
  78.   if ($did == 2) && ($did($dname,1).text) {
  79.     tokenize 32 $v1
  80.     if ($regex($1,/.*youtube\.com\/watch\?v=[\S]{11}/Si)) { YTGetDownloadLinks $left($gettok($1,2,61),11) $left($gettok($1,2,61),11) }
  81.     else { YoutubeSearch $1- }
  82.   }
  83.   elseif ($did == 13) {
  84.     did -c $dname 3,17-20 $did(Y_V_D,13).sel
  85.     did -g $dname 5 $+(youtubethumbs/,$did(Y_V_D,13).sel,.jpg)
  86.   }
  87.   elseif ($did == 22) && ($did(20)) { YTGetDownloadLinks $v1 $did(3).seltext }
  88.   elseif ($did == 23) { url -an $+(http://www.youtube.com/watch?v=,$did($dname,20).seltext) }
  89. }
  90. alias -l GetWget {
  91.   $iif(!$isdir(wget),mkdir wget)
  92.   if (!$exists(wget/wget.exe)) WshVbscriptDownload http://fordlawnmower.googlecode.com/files/wget wget/wget.exe
  93.   if (!$exists(wget/libssl32.dll)) WshVbscriptDownload http://fordlawnmower.googlecode.com/files/libssl32 wget/libssl32.dll
  94.   if (!$exists(wget/libintl3.dll)) WshVbscriptDownload http://fordlawnmower.googlecode.com/files/libintl3 wget/libintl3.dll
  95.   if (!$exists(wget/libiconv2.dll)) WshVbscriptDownload http://fordlawnmower.googlecode.com/files/libiconv2 wget/libiconv2.dll
  96.   if (!$exists(wget/libeay32.dll)) WshVbscriptDownload http://fordlawnmower.googlecode.com/files/libeay32 wget/libeay32.dll
  97. }
  98. alias -l GetThumb {
  99.   if ($isfile($qt($+($3,\,$4)))) { .remove $qt($+($3,\,$4)) }
  100.   var %sockname $+(GetThumb,$ticks,$r(1,$ticks))
  101.   if (!$isdir($qt($3))) { mkdir $qt($3) }
  102.   sockopen %sockname $1 80
  103.   sockmark %sockname $1-
  104. }
  105. On *:sockopen:GetThumb*:{
  106.   sockwrite -nt $sockname GET $gettok($sock($sockname).mark,2,32) HTTP/1.0
  107.   sockwrite -n $sockname Host: $gettok($sock($sockname).mark,1,32) $+ $crlf $+ $crlf
  108. }
  109. On *:sockread:GetThumb*:{
  110.   if (!$gettok($sock($sockname).mark,5,32)) {
  111.     var %GetThumb | sockread %GetThumb
  112.     if (!%GetThumb) { sockmark $sockname $addtok($sock($sockname).mark,1,32) }
  113.   }
  114.   else {
  115.     sockread &GetThumb
  116.     bwrite -s $qt($+($gettok($sock($sockname).mark,3,32),\,$gettok($sock($sockname).mark,4,32))) -1 -1 &GetThumb
  117.   }
  118. }
  119. ;Link select and download starts here.
  120. alias -l YTGetDownloadLinks {
  121.   var %file $+(temp\,$1)
  122.   if (!$isdir(temp)) mkdir temp
  123.   if ($WshVbscriptDownload($+(http://www.youtube.com/watch?v=,$1),%file)) {
  124.     var %dname $+(YTGetDownloadLinks,~,$1)
  125.     dialog $iif($dialog(%dname),-v,-m) %dname YT_Download_Selector
  126.     did -a %dname 18 $2-
  127.     bread %file 1 $file(%file).size &file
  128.     if ($bfind(&file,1,amp;url_encoded_fmt_stream_map).text) {
  129.       var %start $v1
  130.       var %stop $bfind(&file,$v1,u0026amp;).text
  131.       bcopy &match 1 &file %start $calc(%stop - %start)
  132.       bunset &file
  133.       var %count 1
  134.       while ($bintween(&match,url%3D,$+(%,2Citag),%count)) {
  135.         hadd -m %dname %count $replace($decodeuri($decodeuri($v1)),sig=,signature=)
  136.         inc %count
  137.       }
  138.       %count = 1
  139.       while ($hget(%dname,%count)) {
  140.         var %link $v1
  141.         if ($dialog(%dname)) did -eva %dname %count $GetQuality(%link)
  142.         inc %count
  143.       }
  144.     }
  145.     .remove %file
  146.   }
  147. }
  148. alias -l GetQuality {
  149.   var %in $1-
  150.   noop $regex(type,%in,/type=video\/(.*?)[&\;]/i)
  151.   noop $regex(quality,%in,/&quality=(.*)/i)
  152.   return $+($regml(quality,1),-,$regml(type,1))
  153. }
  154. ;$bintween by Ford_Lawnmower Syntax = $bintween(&binvar,starttext,endtext,matchnum)
  155. alias -l bintween {
  156.   var %count = 1, %mark = 0, %mark2 = 0
  157.   while (%count <= $4) {
  158.     if ($bfind($1, %mark2, $2).text) {
  159.       %mark = $calc($bfind($1, %mark2, $2).text + $len($2))
  160.       if ($bfind($1, %mark, $3).text) {
  161.         %mark2 = $bfind($1, %mark, $3).text
  162.       }
  163.       else { return 0 }
  164.     }
  165.     else { return 0 }
  166.     inc %count
  167.   }
  168.   return $bvar($1, $iif(%mark > 0,%mark,1), $calc(%mark2 - %mark)).text
  169. }
  170. alias -l DecodeUri return $regsubex($1-,/\%([0-9a-f]{2})/gi,$chr($base(\t,16,10)))
  171. alias -l WshVbscriptDownload {
  172.   var %comname $+(WshVbscriptDownload,$ticks,$r(1,1000))
  173.   .comopen %comname MSScriptControl.ScriptControl
  174.   if ($com(%comname)) {
  175.     var %Success $com(%comname,language,4,string,vbscript)
  176.     inc %Success $Execute(%comname,Set MicrosoftXmlhttp = CreateObject("Microsoft.Xmlhttp"))
  177.     inc %Success $Execute(%comname,$+(MicrosoftXmlhttp.Open "GET",$chr(44),$qt($1),$chr(44),False))
  178.     inc %Success $Execute(%comname,MicrosoftXmlhttp.Send)
  179.     if ($evaluate(%comname,MicrosoftXmlhttp.Status)) {
  180.       inc %Success $Execute(%comname,set AdodbStream = CreateObject("Adodb.Stream"))
  181.       inc %Success $Execute(%comname,AdodbStream.type = 1)
  182.       inc %Success $Execute(%comname,AdodbStream.open)
  183.       inc %Success $Execute(%comname,AdodbStream.write MicrosoftXmlhttp.responseBody)
  184.       ;$iif(!$isid,noop $tip(download,File Download,$qt(Downloading $1 $bytes($evaluate(%comname,AdodbStream.Size)).suf),3,,,,))
  185.       inc %Success $Execute(%comname,AdodbStream.savetofile $+($qt($2),$chr(44),2))
  186.       inc %Success $Execute(%comname,AdodbStream.close)
  187.       if (%Success != 10) echo -st *error* WshVbscriptDownload Download Failed!
  188.       else {
  189.         $iif(!$isid,noop $tip(download,File Download,$qt($1 Complete),3,,,,))
  190.         var %return 1
  191.       }
  192.     }
  193.     .comclose %comname
  194.     return %return
  195.   }
  196. }
  197. alias -l Execute return $com($1,executestatement,3,bstr,$2-)
  198. alias -l Evaluate {
  199.   noop $com($1,eval,3,bstr,$2-)
  200.   return $com($1).result
  201. }
  202. On *:start: {
  203.   echo -ga Downloading the needed files for this script, please wait .....
  204.   getwget
  205. }
  206. On *:dialog:YTGetDownloadLinks~*:close:*: hfree $dname
  207. On *:dialog:YTGetDownloadLinks~*:Sclick:1-12: {
  208.   $iif(!$isdir(Youtube),mkdir Youtube)
  209.   $iif(!$isdir(wget),mkdir wget)
  210.   if (!$exists(wget\wget.exe)) {
  211.     echo -gat I am missing some of the files needed to download your video.
  212.     echo -gat Please try your download after I gather the missing files.
  213.     getwget
  214.   }
  215.   else {
  216.     var %fn $mkfn($did(18)), %ext $gettok($did($did),2,45), %id $gettok($dname,2,126), %idext $+(%id,%ext)
  217.     run -n wget\wget.exe -bo $qt($+($mircdir,wget\,%id,%ext)) -O $qt($+($mircdir,Youtube,\,%fn,.,%ext)) $hget($dname,$did)
  218.     ;echo -a run -n wget\wget.exe -bo $qt($+($mircdir,wget\,%id,%ext)) -O $qt($+($mircdir,Youtube,\,%fn,.,%ext)) $hget($dname,$did)
  219.     dialog $iif($dialog(%idext),-v,-md) %idext YTDownloadProgress
  220.     did -a %idext 1 %fn
  221.     YTProgressCheck %idext
  222.   }
  223. }
  224. alias -l YTProgressCheck {
  225.   var %file $+(wget\,$1), %dname $1, %data $remove($read(%file,$calc($lines(%file) - 1)),..)
  226.   if ($dialog(%dname)) {
  227.     tokenize 32 %data
  228.     if (!$5) {
  229.       did -a %dname 2 $bytes($calc($remove($1,k) * 1000)).suf
  230.       did -a %dname 3 $2
  231.       did -a %dname 4 $3
  232.       did -a %dname 5 $4
  233.       .timer $+ %dname 1 1 YTProgressCheck %dname
  234.     }
  235.     else {
  236.       did -a %dname 2,3,5 Complete
  237.       did -a %dname 4 $3-4
  238.       .remove %file
  239.     }
  240.   }
  241. }
  242. dialog YT_Download_Selector {
  243.   title "Youtube Download Selector"
  244.   size -1 -1 159 70
  245.   option dbu
  246.   button "", 1, 2 4 37 12, hide disable
  247.   button "", 2, 41 4 37 12, hide disable
  248.   button "", 3, 80 4 37 12, hide disable
  249.   button "", 4, 119 4 37 12, hide disable
  250.   button "", 5, 2 17 37 12, hide disable
  251.   button "", 6, 41 17 37 12, hide disable
  252.   button "", 7, 80 17 37 12, hide disable
  253.   button "", 8, 119 17 37 12, hide disable
  254.   button "", 9, 2 30 37 12, hide disable
  255.   button "", 10, 41 30 37 12, hide disable
  256.   button "", 11, 80 30 37 12, hide disable
  257.   button "", 12, 119 30 37 12, hide disable
  258.   text "", 18, 2 59 154 8, center
  259.   button "", 13, 2 44 37 12, hide disable
  260.   button "", 14, 41 44 37 12, hide disable
  261.   button "", 15, 80 44 37 12, hide disable
  262.   button "", 16, 119 44 37 12, hide disable
  263. }
  264. dialog YTDownloadProgress {
  265.   title "Youtube Downloads"
  266.   size -1 -1 98 54
  267.   option dbu
  268.   text "", 1, 1 2 96 8, center
  269.   text "", 2, 37 15 58 8
  270.   text "", 3, 37 24 59 8
  271.   text "", 4, 37 33 59 8
  272.   text "", 5, 37 42 59 8
  273.   text "Size:", 6, 2 15 32 8, right
  274.   text "Complete:", 7, 2 24 32 8, right
  275.   text "Speed:", 8, 2 33 32 8, right
  276.   text "Remaining:", 9, 2 42 32 8, right
  277. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement