Created
March 31, 2014 16:02
-
-
Save maestrith/9895681 to your computer and use it in GitHub Desktop.
Posted using AHK Studio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#SingleInstance,Force | |
html:=ComObjCreate("htmlfile") | |
url:="https://www.youtube.com/watch?v=VZZ0PnDZdZk" | |
html.write(URLDownloadToVar(url)) | |
title:=html.getElementsByName("title").item[0].getattribute("content") | |
title1:=title | |
title:=uriencode(title) | |
scripts:=html.getElementsBytagname("script") ;.length ;.innerhtml ;.getattribute("flashvars") | |
while,ss:=scripts.item[A_Index-1]{ | |
if InStr(ss.innerhtml,"bitrate"){ | |
for a,b in StrSplit(ss.innerhtml,",") | |
if InStr(b,"bitrate"){ | |
url:="" | |
RegExMatch(uridecode(b),"(http.*)",found) | |
for a,b in StrSplit(found,"&"){ | |
if InStr(b,"\u") | |
url.=RegExReplace(b,"U)\\u\d\d\d\d","&") "" | |
else | |
url.=b "&" | |
} | |
url1:="" | |
for a,b in StrSplit(url,"&"){ | |
if b not contains fallback_host,type,quality | |
url1.=b "&" | |
} | |
download: | |
URLDownloadToFile,% url1,%title1%.mp4 | |
FileGetSize,size,%title1%.mp4 | |
if (size<100){ | |
m("Did not download, trying again") | |
goto download | |
} | |
Else | |
break | |
} | |
m("done",info,url,ss.innerhtml) | |
break | |
} | |
} | |
return | |
UriEncode(Uri){ | |
Len:=StrPut(uri,"utf-8"),VarSetCapacity(Var,Len,0),StrPut(uri, &Var, Enc),f:=A_FormatInteger | |
SetFormat, IntegerFast, H | |
Loop | |
{ | |
Code := NumGet(Var,A_Index-1,"UChar") | |
If (!Code) | |
Break | |
If (Code>=0x30&&Code<=0x39||Code>=0x41&&Code<=0x5A||Code>=0x61&&Code<=0x7A) | |
Res.=Chr(Code) | |
Else | |
Res .= "%" SubStr(Code + 0x100, -1) | |
} | |
SetFormat,IntegerFast,%f% | |
Return,Res | |
} | |
m(x*){ | |
for a,b in x | |
list.=b "`n" | |
msgbox %list% | |
} | |
uriDecode(str) { | |
Loop | |
If RegExMatch(str, "i)(?<=%)[\da-f]{1,2}", hex) | |
StringReplace, str, str, `%%hex%, % Chr("0x" . hex), All | |
Else Break | |
Return, str | |
} | |
URLDownloadToVar( url ) | |
{ | |
hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1") | |
hObject.Open("GET", url) | |
hObject.Send() | |
return hObject.ResponseText | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment