Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Youtube Video Downloader by Ford_Lawnmower irc.Geekshed.net #Script-Help
- menu * {
- Youtube Video Downloader: dialog $iif($dialog(Y_V_D),-v,-md) Y_V_D Y_V_D
- }
- alias -l YoutubeSearch {
- if ($sock(YoutubeSearch)) { sockclose YoutubeSearch }
- sockopen YoutubeSearch www.youtube.com 80
- sockmark YoutubeSearch $+(/results?search_type=videos&aq=f&search_query=,$replace($1-,$chr(32),+))
- }
- On *:sockopen:YoutubeSearch: {
- if (!$sockerr) {
- did -r Y_V_D 3,13,17-20
- sockwrite -nt $sockname GET $sock($sockname).mark HTTP/1.0
- sockwrite -n $sockname Host: www.youtube.com
- sockwrite -n $sockname $crlf
- }
- else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
- }
- On *:sockread:YoutubeSearch: {
- if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
- else {
- var %Youtube | sockread %Youtube
- if (No video results isin %Youtube) {
- did -a Y_V_D 3,13 No results were found for your search!
- hfree $sockname
- sockclose $sockname
- }
- elseif ($regex(%Youtube,/"title="([^"]*)".*href="\/watch\?v=(.*?)"/i)) {
- hadd -m $sockname id $regml(2)
- hadd -m $sockname title $fix($regml(1))
- }
- elseif ($regex(%Youtube,/username-prepend">.*dir="ltr">(.+?)<\/a/i)) {
- hadd -m $sockname user $regml(1)
- var %s $sockname
- GetThumb i3.ytimg.com $+(/vi/,$hget(%s,id),/default.jpg) YouTubeThumbs $+($calc($did(Y_V_D,13).lines + 1),.jpg)
- did -a Y_V_D 3,13 $hget(%s,title)
- did -a Y_V_D 19 $hget(%s,user)
- did -a Y_V_D 17 $hget(%s,views)
- did -a Y_V_D 18 $hget(%s,date)
- did -a Y_V_D 20 $hget(%s,id)
- }
- elseif ($regex(%Youtube,/<span class="date-added">([^<]*)<\/span>/i)) hadd -m $sockname date $regml(1)
- elseif ($regex(%Youtube,/<span class="viewcount">([^<]*) views<\/span>/i)) {
- hadd -m $sockname views $regml(1)
- }
- elseif (</body> isin %youtube) {
- did -c Y_V_D 3,13,17-20 1
- hfree $sockname
- sockclose $sockname
- .timer 1 3 did -g Y_V_D 5 youtubethumbs/1.jpg
- }
- }
- }
- alias -l fix { return $regsubex($remove($replace($1-,&,&,","),amp;),/&#([0-9]{2});/gi,$chr(\t)) }
- dialog Y_V_D {
- title "Youtube Video Downloader"
- size -1 -1 231 238
- option dbu
- edit "", 1, 4 11 173 10, autohs
- button "Search / Get", 2, 181 9 46 12
- combo 3, 2 40 90 9
- text "Results", 4, 100 31 127 8, center
- icon 5, 7 55 79 69
- text "Views:", 9, 4 134 25 8, right
- text "Added:", 10, 4 149 25 8, right
- text "User:", 11, 4 163 25 8, right
- text "Video ID:", 12, 4 177 25 8, right
- list 13, 100 40 126 175
- combo 17, 33 133 60 9
- combo 18, 33 148 60 9
- combo 19, 33 162 60 9
- combo 20, 33 176 60 9
- button "Download", 22, 144 219 39 12
- button "Play", 23, 188 219 39 12
- text "Video Title", 24, 2 31 90 8, center
- }
- On *:dialog:Y_V_D:Sclick:2,13,21-23: {
- if ($did == 2) && ($did($dname,1).text) {
- tokenize 32 $v1
- if ($regex($1,/.*youtube\.com\/watch\?v=[\S]{11}/Si)) { YTGetDownloadLinks $left($gettok($1,2,61),11) $left($gettok($1,2,61),11) }
- else { YoutubeSearch $1- }
- }
- elseif ($did == 13) {
- did -c $dname 3,17-20 $did(Y_V_D,13).sel
- did -g $dname 5 $+(youtubethumbs/,$did(Y_V_D,13).sel,.jpg)
- }
- elseif ($did == 22) && ($did(20)) { YTGetDownloadLinks $v1 $did(3).seltext }
- elseif ($did == 23) { url -an $+(http://www.youtube.com/watch?v=,$did($dname,20).seltext) }
- }
- alias -l GetWget {
- $iif(!$isdir(wget),mkdir wget)
- if (!$exists(wget/wget.exe)) WshVbscriptDownload http://fordlawnmower.googlecode.com/files/wget wget/wget.exe
- if (!$exists(wget/libssl32.dll)) WshVbscriptDownload http://fordlawnmower.googlecode.com/files/libssl32 wget/libssl32.dll
- if (!$exists(wget/libintl3.dll)) WshVbscriptDownload http://fordlawnmower.googlecode.com/files/libintl3 wget/libintl3.dll
- if (!$exists(wget/libiconv2.dll)) WshVbscriptDownload http://fordlawnmower.googlecode.com/files/libiconv2 wget/libiconv2.dll
- if (!$exists(wget/libeay32.dll)) WshVbscriptDownload http://fordlawnmower.googlecode.com/files/libeay32 wget/libeay32.dll
- }
- alias -l GetThumb {
- if ($isfile($qt($+($3,\,$4)))) { .remove $qt($+($3,\,$4)) }
- var %sockname $+(GetThumb,$ticks,$r(1,$ticks))
- if (!$isdir($qt($3))) { mkdir $qt($3) }
- sockopen %sockname $1 80
- sockmark %sockname $1-
- }
- On *:sockopen:GetThumb*:{
- sockwrite -nt $sockname GET $gettok($sock($sockname).mark,2,32) HTTP/1.0
- sockwrite -n $sockname Host: $gettok($sock($sockname).mark,1,32) $+ $crlf $+ $crlf
- }
- On *:sockread:GetThumb*:{
- if (!$gettok($sock($sockname).mark,5,32)) {
- var %GetThumb | sockread %GetThumb
- if (!%GetThumb) { sockmark $sockname $addtok($sock($sockname).mark,1,32) }
- }
- else {
- sockread &GetThumb
- bwrite -s $qt($+($gettok($sock($sockname).mark,3,32),\,$gettok($sock($sockname).mark,4,32))) -1 -1 &GetThumb
- }
- }
- ;Link select and download starts here.
- alias -l YTGetDownloadLinks {
- var %file $+(temp\,$1)
- if (!$isdir(temp)) mkdir temp
- if ($WshVbscriptDownload($+(http://www.youtube.com/watch?v=,$1),%file)) {
- var %dname $+(YTGetDownloadLinks,~,$1)
- dialog $iif($dialog(%dname),-v,-m) %dname YT_Download_Selector
- did -a %dname 18 $2-
- bread %file 1 $file(%file).size &file
- if ($bfind(&file,1,amp;url_encoded_fmt_stream_map).text) {
- var %start $v1
- var %stop $bfind(&file,$v1,u0026amp;).text
- bcopy &match 1 &file %start $calc(%stop - %start)
- bunset &file
- var %count 1
- while ($bintween(&match,url%3D,$+(%,2Citag),%count)) {
- hadd -m %dname %count $replace($decodeuri($decodeuri($v1)),sig=,signature=)
- inc %count
- }
- %count = 1
- while ($hget(%dname,%count)) {
- var %link $v1
- if ($dialog(%dname)) did -eva %dname %count $GetQuality(%link)
- inc %count
- }
- }
- .remove %file
- }
- }
- alias -l GetQuality {
- var %in $1-
- noop $regex(type,%in,/type=video\/(.*?)[&\;]/i)
- noop $regex(quality,%in,/&quality=(.*)/i)
- return $+($regml(quality,1),-,$regml(type,1))
- }
- ;$bintween by Ford_Lawnmower Syntax = $bintween(&binvar,starttext,endtext,matchnum)
- alias -l bintween {
- var %count = 1, %mark = 0, %mark2 = 0
- while (%count <= $4) {
- if ($bfind($1, %mark2, $2).text) {
- %mark = $calc($bfind($1, %mark2, $2).text + $len($2))
- if ($bfind($1, %mark, $3).text) {
- %mark2 = $bfind($1, %mark, $3).text
- }
- else { return 0 }
- }
- else { return 0 }
- inc %count
- }
- return $bvar($1, $iif(%mark > 0,%mark,1), $calc(%mark2 - %mark)).text
- }
- alias -l DecodeUri return $regsubex($1-,/\%([0-9a-f]{2})/gi,$chr($base(\t,16,10)))
- alias -l WshVbscriptDownload {
- var %comname $+(WshVbscriptDownload,$ticks,$r(1,1000))
- .comopen %comname MSScriptControl.ScriptControl
- if ($com(%comname)) {
- var %Success $com(%comname,language,4,string,vbscript)
- inc %Success $Execute(%comname,Set MicrosoftXmlhttp = CreateObject("Microsoft.Xmlhttp"))
- inc %Success $Execute(%comname,$+(MicrosoftXmlhttp.Open "GET",$chr(44),$qt($1),$chr(44),False))
- inc %Success $Execute(%comname,MicrosoftXmlhttp.Send)
- if ($evaluate(%comname,MicrosoftXmlhttp.Status)) {
- inc %Success $Execute(%comname,set AdodbStream = CreateObject("Adodb.Stream"))
- inc %Success $Execute(%comname,AdodbStream.type = 1)
- inc %Success $Execute(%comname,AdodbStream.open)
- inc %Success $Execute(%comname,AdodbStream.write MicrosoftXmlhttp.responseBody)
- ;$iif(!$isid,noop $tip(download,File Download,$qt(Downloading $1 $bytes($evaluate(%comname,AdodbStream.Size)).suf),3,,,,))
- inc %Success $Execute(%comname,AdodbStream.savetofile $+($qt($2),$chr(44),2))
- inc %Success $Execute(%comname,AdodbStream.close)
- if (%Success != 10) echo -st *error* WshVbscriptDownload Download Failed!
- else {
- $iif(!$isid,noop $tip(download,File Download,$qt($1 Complete),3,,,,))
- var %return 1
- }
- }
- .comclose %comname
- return %return
- }
- }
- alias -l Execute return $com($1,executestatement,3,bstr,$2-)
- alias -l Evaluate {
- noop $com($1,eval,3,bstr,$2-)
- return $com($1).result
- }
- On *:start: {
- echo -ga Downloading the needed files for this script, please wait .....
- getwget
- }
- On *:dialog:YTGetDownloadLinks~*:close:*: hfree $dname
- On *:dialog:YTGetDownloadLinks~*:Sclick:1-12: {
- $iif(!$isdir(Youtube),mkdir Youtube)
- $iif(!$isdir(wget),mkdir wget)
- if (!$exists(wget\wget.exe)) {
- echo -gat I am missing some of the files needed to download your video.
- echo -gat Please try your download after I gather the missing files.
- getwget
- }
- else {
- var %fn $mkfn($did(18)), %ext $gettok($did($did),2,45), %id $gettok($dname,2,126), %idext $+(%id,%ext)
- run -n wget\wget.exe -bo $qt($+($mircdir,wget\,%id,%ext)) -O $qt($+($mircdir,Youtube,\,%fn,.,%ext)) $hget($dname,$did)
- ;echo -a run -n wget\wget.exe -bo $qt($+($mircdir,wget\,%id,%ext)) -O $qt($+($mircdir,Youtube,\,%fn,.,%ext)) $hget($dname,$did)
- dialog $iif($dialog(%idext),-v,-md) %idext YTDownloadProgress
- did -a %idext 1 %fn
- YTProgressCheck %idext
- }
- }
- alias -l YTProgressCheck {
- var %file $+(wget\,$1), %dname $1, %data $remove($read(%file,$calc($lines(%file) - 1)),..)
- if ($dialog(%dname)) {
- tokenize 32 %data
- if (!$5) {
- did -a %dname 2 $bytes($calc($remove($1,k) * 1000)).suf
- did -a %dname 3 $2
- did -a %dname 4 $3
- did -a %dname 5 $4
- .timer $+ %dname 1 1 YTProgressCheck %dname
- }
- else {
- did -a %dname 2,3,5 Complete
- did -a %dname 4 $3-4
- .remove %file
- }
- }
- }
- dialog YT_Download_Selector {
- title "Youtube Download Selector"
- size -1 -1 159 70
- option dbu
- button "", 1, 2 4 37 12, hide disable
- button "", 2, 41 4 37 12, hide disable
- button "", 3, 80 4 37 12, hide disable
- button "", 4, 119 4 37 12, hide disable
- button "", 5, 2 17 37 12, hide disable
- button "", 6, 41 17 37 12, hide disable
- button "", 7, 80 17 37 12, hide disable
- button "", 8, 119 17 37 12, hide disable
- button "", 9, 2 30 37 12, hide disable
- button "", 10, 41 30 37 12, hide disable
- button "", 11, 80 30 37 12, hide disable
- button "", 12, 119 30 37 12, hide disable
- text "", 18, 2 59 154 8, center
- button "", 13, 2 44 37 12, hide disable
- button "", 14, 41 44 37 12, hide disable
- button "", 15, 80 44 37 12, hide disable
- button "", 16, 119 44 37 12, hide disable
- }
- dialog YTDownloadProgress {
- title "Youtube Downloads"
- size -1 -1 98 54
- option dbu
- text "", 1, 1 2 96 8, center
- text "", 2, 37 15 58 8
- text "", 3, 37 24 59 8
- text "", 4, 37 33 59 8
- text "", 5, 37 42 59 8
- text "Size:", 6, 2 15 32 8, right
- text "Complete:", 7, 2 24 32 8, right
- text "Speed:", 8, 2 33 32 8, right
- text "Remaining:", 9, 2 42 32 8, right
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement