Advertisement
Ford

Simple Youtube video downloader for mIRC | With mp3 save

Sep 30th, 2012
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 12.90 KB | None | 0 0
  1. ;Youtube Simple Downloader by Ford_Lawnmower irc.abjects.net #mIRC
  2. menu channel,status,menubar {
  3.   Youtube Simple Downloader: dialog $iif(!$dialog(YTSimpleDownloader),-m YTSimpleDownloader,-v) YTSimpleDownloader
  4. }
  5. alias -l DSleep {
  6.   return $WshRunitSilent(choice /c "10" /n /d "1" /t $1)
  7. }
  8. alias -l WshRunitSilent {
  9.   var %comname $+(WshRunSilent,$ticks)
  10.   .comopen %comname WScript.Shell
  11.   if ($com(%comname)) {
  12.     if (!$com(%comname,run,3,bstr,$1-,uint,0,string,true)) {
  13.       echo -st *error* WshRunSilent $com(%comname).error
  14.       var %return 0
  15.     }
  16.     else var %return 1
  17.     .comclose %comname
  18.     return %return
  19.   }
  20. }
  21. ;VideoToAudio ffmpeg.exeDirectory;infile;outfile;cleanup command here
  22. alias -l VideoToAudio {
  23.   tokenize 59 $1-
  24.   var %start $ctime, %dname $replace($+(YTVideoToAudio,$mkfn($3)),$chr(32),_), %cleanup $4, %temp $+($wshgetvar(temp),\,$nopath($3))
  25.   var %quality $input(Please select an audio quality,omr,Quality Settings Needed,160,64,128,160,192,224,256,320)
  26.   if (%quality) {
  27.     dialog $iif($dialog(%dname),-v,-md) %dname YTVideoToAudio
  28.     dcheck did -a %dname 8 $nopath($2)
  29.     dcheck did -a %dname 9 $nopath($3)
  30.     dcheck did -a %dname 11 Conversion in progress......
  31.     ShowProgress %dname
  32.     .timer $+ %dname 0 1 ShowProgress %dname    
  33.     if ($exists($qt($3))) .remove $qt($3)
  34.     if ($WshRunitSilent($1 -i $qt($2) -vn -ar 44100 -ac 2 -ab $+(%quality,k) -f mp3 $qt(%temp))) {
  35.       dcheck did -a %dname 11 Conversion Complete in $duration($calc($ctime - %start))
  36.       .timer $+ %dname off
  37.       .copy $qt(%temp) $qt($3)
  38.       .remove $qt(%temp)
  39.       %cleanup
  40.     }
  41.     else dcheck did -a %dname Conversion Failed!
  42.   }
  43. }
  44. alias -l ShowProgress {
  45.   var %count $iif($calc($gettok($nopath($did($1,1)),1,46) + 1) > 8,1,$calc($gettok($nopath($did($1,1)),1,46) + 1))
  46.   dcheck did -g $1 1-7 $+(FFmpeg\,%count,.ico)
  47.   return
  48. }
  49. alias -l dcheck {
  50.   if ($dialog($3)) $1-
  51. }
  52. dialog -l YTVideoToAudio {
  53.   title "Video to Audio Conversion"
  54.   size -1 -1 132 56
  55.   option dbu
  56.   icon 1, 2 24 17 19
  57.   icon 2, 20 24 17 19
  58.   icon 3, 38 24 17 19
  59.   icon 4, 56 24 17 19
  60.   icon 5, 74 24 17 19
  61.   icon 6, 92 24 17 19
  62.   icon 7, 110 24 17 19
  63.   text "", 8, 0 1 132 8, center
  64.   text "", 9, -2 16 134 8, center
  65.   text "TO", 10, 51 8 25 8, center
  66.   text "", 11, 0 46 132 8, center
  67.   text "", 12, 0 0 0 0
  68. }
  69. dialog -l YTSimpleDownloader {
  70.   title "Youtube Downloader"
  71.   size -1 -1 202 51
  72.   option dbu
  73.   text "Link:", 1, 0 4 25 8, right
  74.   text "Save to:", 2, 0 15 25 8, right
  75.   edit "", 3, 26 3 175 10
  76.   edit "", 4, 26 14 151 10
  77.   button "Browse", 5, 179 14 22 10
  78.   radio "Audio Only", 6, 8 38 42 10
  79.   radio "Video Only", 7, 54 38 38 10
  80.   button "Download", 8, 163 37 37 12
  81.   text "", 9, 0 27 201 8
  82.   radio "Both", 10, 97 38 31 10
  83. }
  84. on *:dialog:YTSimpleDownloader:Sclick:5,8: {
  85.   getwget
  86.   if ($did == 5) did -ra $dname 4 $sdir($mircdir,Select a Directory)
  87.   else {
  88.     tokenize 32 $did(3) $did(4) $iif($did(6).state,Audio,$iif($did(8).state,Both,Video)) $did(4)
  89.     if ($regex($1,/.*youtube\.com\/watch\?v=[\S]{11}/Si)) {
  90.       YTGetDownloadLinks $left($gettok($1,2,61),11) $left($gettok($1,2,61),11)
  91.     }
  92.   }
  93. }
  94. ;Link select and download starts here.
  95. alias -l YTGetDownloadLinks {
  96.   var %file $+($wshgetvar(temp),\,$1)
  97.   if ($WshVbscriptDownload($+(http://www.youtube.com/watch?v=,$1),%file)) {
  98.     var %dname $+(YT_GetDownloadLinks,~,$1)
  99.     dialog $iif($dialog(%dname),-v,-m) %dname YT_Download_Selector
  100.     did -a %dname 18 $2-
  101.     did -a %dname 19 $iif($isdir($did(YTSimpleDownloader,4)),$did(YTSimpleDownloader,4),$mircdirYoutube\)
  102.     did -a %dname 20 $iif($did(YTSimpleDownloader,6).state,Audio,$iif($did(YTSimpleDownloader,10).state,Both,Video))
  103.     dialog -x YTSimpleDownloader
  104.     bread %file 1 $file(%file).size &file
  105.     if ($bintween(&file,<meta name="title" content=",">,1)) did -a %dname 18 $fix&#($v1)          
  106.     if ($bfind(&file,1,amp;url_encoded_fmt_stream_map).text) {
  107.       var %start $v1
  108.       var %stop $bfind(&file,$v1,u0026amp;).text
  109.       bcopy &match 1 &file %start $calc(%stop - %start)
  110.       bunset &file
  111.       var %count 1
  112.       while ($bintween(&match,url%3D,$+(%,2Citag),%count)) {
  113.         hadd -m %dname %count $replace($decodeuri($decodeuri($v1)),sig,signature)
  114.         inc %count
  115.       }
  116.       %count = 1
  117.       while ($hget(%dname,%count)) {
  118.         var %link $v1
  119.         if ($dialog(%dname)) did -eva %dname %count $GetQuality(%link)
  120.         inc %count
  121.       }
  122.     }
  123.     .timer 1 2 .remove %file
  124.   }
  125. }
  126. alias -l GetQuality {
  127.   var %in $1-
  128.   noop $regex(type,%in,/type=video\/(.*?)[&\;]/i)
  129.   noop $regex(quality,%in,/&quality=(.*)/i)
  130.   return $+($iif($regml(quality,1),$regml(quality,1),Small),-,$regml(type,1))
  131. }
  132. ;$bintween by Ford_Lawnmower Syntax = $bintween(&binvar,starttext,endtext,matchnum)
  133. alias -l bintween {
  134.   var %count = 1, %mark = 0, %mark2 = 0
  135.   while (%count <= $4) {
  136.     if ($bfind($1, %mark2, $2).text) {
  137.       %mark = $calc($bfind($1, %mark2, $2).text + $len($2))
  138.       if ($bfind($1, %mark, $3).text) {
  139.         %mark2 = $bfind($1, %mark, $3).text
  140.       }
  141.       else { return 0 }
  142.     }
  143.     else { return 0 }
  144.     inc %count
  145.   }
  146.   return $bvar($1, $iif(%mark > 0,%mark,1), $calc(%mark2 - %mark)).text
  147. }
  148. alias -l DecodeUri return $regsubex($1-,/\%([0-9a-f]{2})/gi,$chr($base(\t,16,10)))
  149. alias -l WshVbscriptDownload {
  150.   var %comname $+(WshVbscriptDownload,$ticks,$r(1,1000))
  151.   .comopen %comname MSScriptControl.ScriptControl
  152.   if ($com(%comname)) {
  153.     var %Success $com(%comname,language,4,string,vbscript)
  154.     inc %Success $Execute(%comname,Set MicrosoftXmlhttp = CreateObject("Microsoft.Xmlhttp"))
  155.     inc %Success $Execute(%comname,$+(MicrosoftXmlhttp.Open "GET",$chr(44),$qt($1),$chr(44),False))
  156.     inc %Success $Execute(%comname,MicrosoftXmlhttp.Send)
  157.     if ($evaluate(%comname,MicrosoftXmlhttp.Status)) {
  158.       inc %Success $Execute(%comname,set AdodbStream = CreateObject("Adodb.Stream"))
  159.       inc %Success $Execute(%comname,AdodbStream.type = 1)
  160.       inc %Success $Execute(%comname,AdodbStream.open)
  161.       inc %Success $Execute(%comname,AdodbStream.write MicrosoftXmlhttp.responseBody)
  162.       ;$iif(!$isid,echo 04 -sat Downloading $1 $bytes($evaluate(%comname,AdodbStream.Size)).suf)
  163.       inc %Success $Execute(%comname,AdodbStream.savetofile $+($qt($2),$chr(44),2))
  164.       inc %Success $Execute(%comname,AdodbStream.close)
  165.       if (%Success != 10) echo -st *error* WshVbscriptDownload Download Failed!
  166.       else {
  167.         $iif(!$isid,echo 09 -sat Download $1 Complete)
  168.         var %return 1
  169.       }
  170.     }
  171.     .comclose %comname
  172.     return %return
  173.   }
  174. }
  175. alias -l Execute return $com($1,executestatement,3,bstr,$2-)
  176. alias -l Evaluate {
  177.   noop $com($1,eval,3,bstr,$2-)
  178.   return $com($1).result
  179. }
  180. On *:start: {
  181.   if (!$exists(wget\wget.exe)) getwget
  182. }
  183. On *:dialog:YT_GetDownloadLinks~*:close:*: if ($hget($dname)) hfree $dname
  184. On *:dialog:YT_GetDownloadLinks~*:Sclick:1-12: {
  185.   $iif(!$isdir(Youtube),mkdir Youtube)
  186.   $iif(!$isdir(wget),mkdir wget)
  187.   if ((!$exists(wget\wget.exe)) || (!$exists($ffmpeg)))  {
  188.     echo -gat I am missing some of the files needed to download your video.
  189.     echo -gat Please try your download after I gather the missing files.
  190.     getwget
  191.   }
  192.   else {
  193.     var %fn $mkfn($did(18)), %ext $gettok($did($did),2,45), %id $gettok($dname,2,126), %idext $+(%id,%ext)
  194.     var %dir $did(19)
  195.     var %selection $did(20)
  196.     run -n wget\wget.exe -bo $qt($+($wshgetvar(temp),\,%id,%ext)) -O $qt($+(%dir,%fn,.,%ext)) $hget($dname,$did)
  197.     dialog $iif($dialog(%idext),-v,-md) %idext YTDownloadProgress
  198.     did -a %idext 1 %fn
  199.     did -a %idext 10 %selection
  200.     did -a %idext 11 %dir
  201.     did -a %idext 12 %ext
  202.     .timer 1 2 YTProgressCheck %idext
  203.     dialog -x $dname
  204.   }
  205. }
  206. alias -l YTProgressCheck {
  207.   var %file $+($wshgetvar(temp),\,$1), %dname $1, %data $remove($read(%file,$calc($lines(%file) - 1)),..)
  208.   if ($dialog(%dname)) {
  209.     tokenize 32 %data
  210.     if (!$5) {
  211.       did -a %dname 2 $bytes($calc($remove($1,k) * 1000)).suf
  212.       did -a %dname 3 $2
  213.       did -a %dname 4 $3
  214.       did -a %dname 5 $4
  215.       .timer $+ %dname 1 1 YTProgressCheck %dname
  216.     }
  217.     else {
  218.       did -a %dname 2,3,5 Complete
  219.       did -a %dname 4 $3-4
  220.       .remove $qt(%file)
  221.       if ($did(%dname,10) != Video) {
  222.         var %sel $did(%dname,10), %dir $did(%dname,11), %ext $did(%dname,12), %fn $did(%dname,1)
  223.         var %command $iif($did(%dname,10) == Audio,.remove $qt($+(%dir,%fn,.,%ext)))
  224.         var %fn2 $iif($exists($qt($+(%dir,$did(%dname,1),.mp3))), $input($did(%dname,1) already exists.$&
  225.           $crlf Please enter a new file name.,eoq,FileName Conflict,$did(%dname,1),),$did(%dname,1))
  226.         if (%fn) VideoToAudio $+($qt($ffmpeg),;,$qt($+(%dir,%fn,.,%ext)),;,$qt($+(%dir,%fn2,.,mp3)),;,%command)
  227.       }
  228.       dialog -x %dname
  229.     }
  230.   }
  231. }
  232. alias -l GetWget {
  233.   if (!$isdir(wget)) {
  234.     if ($input(You must download some files to continue. $crlf Dowload them now ?,yq,Youtube Simple DownloaderMissing Files,,)) {
  235.       mkdir wget
  236.     }
  237.     else halt
  238.   }
  239.   if (!$exists(wget/wget.exe)) DownloadTransfer http://fordlawnmower.googlecode.com/files/wget wget.exe wget
  240.   if (!$exists(wget/libssl32.dll)) DownloadTransfer http://fordlawnmower.googlecode.com/files/libssl32 libssl32.dll wget
  241.   if (!$exists(wget/libintl3.dll)) DownloadTransfer http://fordlawnmower.googlecode.com/files/libintl3 libintl3.dll wget
  242.   if (!$exists(wget/libiconv2.dll)) DownloadTransfer http://fordlawnmower.googlecode.com/files/libiconv2 libiconv2.dll wget
  243.   if (!$exists(wget/libeay32.dll)) DownloadTransfer http://fordlawnmower.googlecode.com/files/libeay32 libeay32.dll wget
  244.   GetFFmpeg
  245. }
  246. alias -l DownloadTransfer {
  247.   var %tempfile $+($wshgetvar(temp),/,$2), %destfile $+($3,/,$2)
  248.   if (!$isdir($3)) mkdir $3
  249.   if ($WshVbscriptDownload($1, %tempfile)) {
  250.     .copy %tempfile %destfile
  251.     .remove %tempfile
  252.     echo 04 -ga Transfer of %destfile complete.
  253.   }
  254. }
  255. alias -l GetFFmpeg {
  256.   $iif(!$isdir(FFmpeg),mkdir FFmpeg)
  257.   if (!$exists($ffmpeg)) DownloadTransfer http://fordlawnmower.googlecode.com/files/ffmpeg ffmpeg.exe ffmpeg
  258.   var %count 1
  259.   while (%count <= 8) {
  260.     if (!$exists($+(ffmpeg/,%count,.ico))) DownloadTransfer $+(http://fordlawnmower.googlecode.com/files/,%count,.ico) $+(%count,.ico) ffmpeg
  261.     inc %count
  262.   }
  263. }
  264. alias -l FFmpeg return $mircdirFFmpeg\ffmpeg.exe
  265. alias -l WshGetVar {
  266.   var %comname $+(WinGetVar,$ticks)
  267.   .comopen %comname Wscript.Shell
  268.   if ($com(%comname)) {
  269.     if (!$com(%comname,ExpandEnvironmentStrings,3,bstr,$+(%,$1,%))) {
  270.       echo -st *error* WinGetVar $com(%comname).error
  271.     }
  272.     var %return $com(%comname).result
  273.     .comclose %comname
  274.     return %return
  275.   }
  276. }
  277. alias -l fix&# {
  278.   return $regsubex($replace($regsubex($1-,/\&\#([0-9]{1,});/g,$utf8(\t)),&quot;,",&amp;,&,&gt;,>,&lt;,<,&#39;,',$chr(9),$chr(32)),$&
  279.     /([$\|%\[\]\}\{][^\s]*)/g,$+($chr(2),$chr(2),\t))
  280. }
  281. alias -l UTF8 {
  282.   if ($version >= 7) return $chr($1)
  283.   elseif ($1 < 255) { return $chr($1) }
  284.   elseif ($1 >= 256) && ($1 < 2048) { return $+($chr($calc(192 + $div($1,64))),$chr($calc(128 + $mod($1,64)))) }
  285.   elseif ($1 >= 2048) && ($1 < 65536) { return $+($chr($calc(224 + $div($1,4096))),$chr($calc(128 + $mod($div($1,64),64))),$chr($calc(128 + $mod($1,64)))) }
  286.   elseif ($1 >= 65536) && ($1 < 2097152) {
  287.     return $+($chr($calc(240 + $div($1,262144))),$chr($calc(128 + $mod($div($1,4096),64))),$chr($calc(128 + $mod($div($1,64),64))),$&
  288.       $chr($calc(128 + $mod($1,64))))
  289.   }
  290. }
  291. alias -l div { return $int($calc($1 / $2)) }
  292. alias -l mod {
  293.   var %int $int($calc($1 / $2))
  294.   return $calc($1 - (%int * $2))
  295. }
  296. alias -l H2U { return $utf8($base($1,16,10)) }
  297. dialog YT_Download_Selector {
  298.   title "Youtube Download Selector"
  299.   size -1 -1 159 70
  300.   option dbu
  301.   button "", 1, 2 4 37 12, hide disable
  302.   button "", 2, 41 4 37 12, hide disable
  303.   button "", 3, 80 4 37 12, hide disable
  304.   button "", 4, 119 4 37 12, hide disable
  305.   button "", 5, 2 17 37 12, hide disable
  306.   button "", 6, 41 17 37 12, hide disable
  307.   button "", 7, 80 17 37 12, hide disable
  308.   button "", 8, 119 17 37 12, hide disable
  309.   button "", 9, 2 30 37 12, hide disable
  310.   button "", 10, 41 30 37 12, hide disable
  311.   button "", 11, 80 30 37 12, hide disable
  312.   button "", 12, 119 30 37 12, hide disable
  313.   text "", 18, 2 59 154 8, center
  314.   button "", 13, 2 44 37 12, hide disable
  315.   button "", 14, 41 44 37 12, hide disable
  316.   button "", 15, 80 44 37 12, hide disable
  317.   button "", 16, 119 44 37 12, hide disable
  318.   text "", 19, 0 0 0 0
  319.   text "", 20, 0 0 0 0
  320. }
  321. dialog -l YTDownloadProgress {
  322.   title "Youtube Downloads"
  323.   size -1 -1 98 54
  324.   option dbu
  325.   text "", 1, 1 2 96 8, center
  326.   text "", 2, 37 15 58 8
  327.   text "", 3, 37 24 59 8
  328.   text "", 4, 37 33 59 8
  329.   text "", 5, 37 42 59 8
  330.   text "Size:", 6, 2 15 32 8, right
  331.   text "Complete:", 7, 2 24 32 8, right
  332.   text "Speed:", 8, 2 33 32 8, right
  333.   text "Remaining:", 9, 2 42 32 8, right
  334.   text "", 10, 1 10 0 6, center
  335.   text "", 11, 1 10 0 6, center
  336.   text "", 12, 1 10 0 6, center
  337. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement