Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alias youtube {
- var %sock = youtube_ $+ $md5($ticks $+ $r(1,999999)), %link = $1-
- if (!%link) { var %link = $input(Enter Link,oe,Youtube Downloader) }
- if (%link) && ($urlparse(%link).host == www.youtube.com) && (/watch?v=* iswm $urlparse(%link).path) {
- sockclose %sock
- hadd -m %sock mark $1-
- sockopen %sock youtube.com 80
- }
- else { echo -a Youtube Downloader: Invalid Link, Syntax: /youtube http://www.youtube.com/watch?v=Code }
- }
- on *:sockopen:youtube_*:{
- var %sw = sockwrite -n $sockname, %mark = $hget($sockname,mark)
- if (!$regex(%mark,/v=(.+)$/) || $sockerr) { echo -a Youtube Downloader: Connection Failed }
- var %code = $regml(1)
- %sw GET $urlparse(%mark).path HTTP/1.1
- %sw Host: www.youtube.com
- %sw Connection: Close
- %sw
- hadd -m $sockname file %code $+ .tmp
- }
- on *:sockread:youtube_*:{
- sockread -f &d
- bwrite $hget($sockname,file) -1 -1 &d
- }
- on *:sockclose:youtube_*:{
- bread $hget($sockname,file) 1 $file($hget($sockname,file)).size &d
- var %1 = $bfind(&d,1,fmt_url_map=), %2 = $bfind(&d,%1,&)
- var %url = $bvar(&d,%1 - %2).text
- var %url = $urldecode(%url)
- var %url = $gettok($gettok(%url,2,124),1,44)
- .remove $hget($sockname,file)
- youtube2 %url $hget($sockname,file)
- .hfree -sw $sockname
- }
- alias youtube2 {
- if ($regex($1-,/http://(.+)/(.+)/)) { var %host = $regml(1) }
- var %sock = youtube2_ $+ $md5($ticks $+ $r(1,9999999))
- var %file = $2
- if ($regex($1-,/id=([a-z0-9]+)/$)) {
- sockclose %sock
- .remove %file
- hadd -m %sock mark $1
- hadd -m %sock file %file
- sockopen %sock %host 80
- }
- }
- on *:sockopen:youtube2_*:{
- var %sw = sockwrite -n $sockname, %mark = $hget($sockname,mark)
- if ($regex(%mark,/http://(.+)/(.+)/)) {
- %sw GET / $+ $regml(2) HTTP/1.1
- %sw Host: $regml(1)
- %sw Connection: Close
- %sw
- }
- .timer_progress_ $+ $sockname 0 1 _progress $sockname
- }
- on *:sockread:youtube2_*:{
- sockread -f &1
- if ($bfind(&1,1,Content-Length:)) {
- var %s = $v1, %e = $bfind(&1,$v1,$lf)
- var %head = $bvar(&1,%s,$calc(%e - %s)).text
- if ($regex(%head,/Content-Length: (\d+)/i)) {
- hadd -m $sockname length $regml(1)
- if ($regml(1) > 0) { dialog -m $sockname Youtube_Download }
- }
- }
- if (!$hget($sockname,count)) { hadd -m $sockname count 1 }
- if (!$sockbr) { return }
- hinc $sockname count $bvar(&1,0)
- bwrite $hget($sockname,file) -1 -1 &1
- }
- alias _progress {
- var %sock = $1
- if (!$hget(%sock,ticks)) { hadd -m %sock ticks $ticks }
- var %ticks = $hget(%sock,ticks)
- var %speed = $int($calc(($file($hget(%sock,file)).size / (($ticks - %ticks) / 1000)) / 1024)) kb/s
- did -ra %sock 1 Downloading: $strip($tpbar($hget(%sock,count),$hget(%sock,length),20,[,],|,·,15,4,5,2).p,c) %speed
- }
- on *:sockclose:youtube2_*:{
- deheader $hget($sockname,file) $remove($hget($sockname,file),.tmp) $+ .flv
- did -h $sockname 1
- did -v $sockname 2
- did -e $sockname 3
- did -b $sockname 4
- .timer_progress_ $+ $sockname off
- .hfree -sw $sockname
- }
- alias deheader {
- var %in = $1, %out = $2
- bread %in 0 $file(%in).size &in
- var %find = $bfind(&in,1,$crlf $+ $crlf)
- bcopy &out 1 &in $calc(%find + 4) -1
- bwrite %out 0 -1 &out
- if ($exists(%in)) { .remove %in }
- }
- alias urlencode return $regsubex($1-,/G(.)/g,$iif(($prop && 1 !isalnum) || !$prop,$chr(37) $+ $base($asc(1),10,16),1))
- alias urldecode return $regsubex($replace($1-,+,$chr(32),% $+ 20,$chr(32)),/%([0-9A-Fa-f]{2})/g,$chr($base(\1,16,10)))
- alias tpbar return $+(,$8,$4,,$9,$str($6,$calc(($1 /$2)*$3)),,$10,$str($7,$calc($3 -($1 /$2)*$3)),,$8,$5) $iif($prop == p,$+(,$8,$4,,$base($11,10,10,2),$int($calc($1 /$2 *100)),%,,$8,$5)) $+
- alias pbar return $+(,$8,$4,,$9,$str($6,$calc(($1 /$2)*$3)),,$10,$str($7,$calc($3 -($1 /$2)*$3)),,$8,$5) $iif($prop == p,$+(,$8,$4,,$base($11,10,10,2),$int($calc($1 /$2 *100)),%,,$8,$5)) $+
- dialog Youtube_Download {
- title "Download"
- size -1 -1 164 53
- option dbu
- text "Downloading:", 1, 23 14 146 11
- text "Download Complete.", 2, 60 14 146 11, hide
- button "OK", 3, 43 31 37 12, default disable
- button "Cancel", 4, 95 31 37 12
- }
- on *:dialog:Youtube2_*:sclick:3:{ dialog -x $dname }
- on *:dialog:Youtube2_*:sclick:4:{
- if ($exists($hget($dname,file))) { .remove $hget($dname,file) }
- .hfree -sw $dname
- .timer_progress_ $+ $dname off
- .sockclose $dname
- dialog -x $dname
- }
- alias urlparse {
- if ($regex($1-,/^(?:([a-z.+-]+)://|())(?:([^@:]+)(?::(.*?)|())@|()())([a-z0-9.-]+)(?::(d+)|())(/.*)?$/i)) {
- if ($prop == proto) return $iif($regml(1) != $null,$ifmatch,http)
- elseif ($prop == user) return $regml(2)
- elseif ($prop == pass) return $regml(3)
- elseif ($prop == host) return $regml(4)
- elseif ($prop == port) return $iif($regml(5) != $null,$ifmatch,$urlport($iif($regml(1) != $null,$ifmatch,http)))
- elseif ($prop == path) return $iif($regml(6) != $null,$ifmatch,/)
- else return $true
- }
- else return $iif(!$prop,$false)
- }
- alias urlport {
- return $iif($findtok(http ftp telnet nntp https gopher,$1,32),$gettok(80 21 23 119 443 70,$ifmatch,32),0)
- }
- alias urlencode {
- var %t = $1-, %r = "", %c
- while ($len(%t)) {
- %c = $asc($left(%t,1))
- %r = %r $+ $iif((%c <= 32) || (%c >= 127),% $+ $base($ifmatch,10,16,2),$chr(%c))
- %t = $right(%t,-1)
- }
- return %r
- }
- alias urlpath {
- var %t = $iif($right($1-,1) == /,/), %r = "", %i = 0
- while (%i < $numtok($1-,47)) {
- inc %i
- if ($gettok($1-,%i,47) == .) %r = %r $+ $iif($right(%r,1) != /,/)
- elseif ($gettok($1-,%i,47) != ..) %r = $instok(%r,$ifmatch,0,47)
- else {
- if (!$numtok(%r,47)) return $null
- %r = $deltok(%r,-1,47) $+ /
- }
- }
- return $iif(%r != /,/) $+ %r $+ $iif((%r != $null) && ($right(%r,1) != /),%t)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement