Code: Select all
;-------- saved at 星期五 十二月 2020-12-25 16:18 UTC --------------
;- Hide command console when using RunWaitOne() example / from user teadrinker
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=84266
;-------------------------------------
;- MODIFIED = 20201225
;- CREATED = 20201211
;- from user= teadrinker
;- HowTo use= Startscript ,minimize script
; copy youtube url > download starts and show GUI
; when download ended > opens video folder \Desktop\M_VIDEO
; or - type a DOS command below and use START-button
;-------------------------------------
;----- youtube-dl.exe ------------------------
transform,s,chr,34
filename1=YOUTUBE-DL.exe TEST
youtubedl:=a_scriptdir . "\youtube-dl.exe" ;<<< youtube-dl.exe in a_scriptdir
fdmp4:=a_desktop . "\M_VIDEO" ;<<< save videos here
ifnotexist,%fdmp4%
filecreatedir,%fdmp4%
ifexist,%youtubedl%
{
loop,%youtubedl%
SP1:=A_loopFileShortPath
;RunWait, %comspec% /k %sp1% -U ;- Update youtube-dl.exe
}
else
{
run,https://youtube-dl.org/latest/youtube-dl.exe
return
}
var=https://www.youtube.com/watch?v=G6_DldYj0uQ ;- URL Li Xiang Lan ( for test )
;--------------------------------
;----- FOR TEST -------------------------
;cmdx:=youtubedl . " -U" ;- update youtube-dl.exe
;cmdx:=sp1 . " " . var . " --verbose --youtube-skip-dash-manifest --write-auto-sub --sub-lang de -o " . s . fdmp4 . "\`%(title)s$`%(uploader)s$`%(id)s.`%(ext)s"
;-----------------------------
;cmdx:="nslookup myip.opendns.com. resolver1.opendns.com"
;cmdx:="ftype AutoHotkeyScript"
;cmdx:="Where user32.dll"
;cmdx:="dir *.* /s", A_AhkPath . "\..\"
;cmdx:="dir"
;cmdx:="ping autohotkey.com -n 4"
cmdx:=""
;------------------------------------------
;============== GUI ===========
#warn
#noenv
name1:="Youtube-dl_TEST"
global name1
CPX:="cp" . DllCall("GetOEMCP", "UInt") ;- get CODEPAGE e.g. CP850
setworkingdir,%a_scriptdir%
clipboard=
Gui,1:default
Gui,1: -DPIScale
Gui,1:Color,Black,Black ; GUI black / EDIT is BLACK
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100
;- maybe change fontsize
;============ GUISIZEx DPIx 4Kx 3840*2160 is 100% ============
if (wa=3840)
Gui,1:Font,s12 cYellow,Lucida Console
;============ GUISIZEx DPIx FHD 1920*1080 is 100% ============
else if (wa=1920)
Gui,1:Font,s10 cYellow,Lucida Console
else
Gui,1:Font,s10 cYellow,Lucida Console
;=============================================================
x:=(wa*1)/xx,y:=(ha*1)/xx,w:=(wa*70)/xx,h:=(ha*3)/xx
Gui, Add, Edit, x%x% y%y% w%w% h%h% vED1 readonly ;- show copied youtube url
;---------
x:=(wa*1)/xx,y:=(ha*5)/xx,w:=(wa*70)/xx,h:=(ha*56)/xx
Gui, Add, Edit, x%x% y%y% w%w% h%h% vED2 ;- here RESULT streaming
;---------
x:=(wa*1)/xx,y:=(ha*63)/xx,w:=(wa*64)/xx,h:=(ha*6)/xx
Gui, Add, Edit, x%x% y%y% w%w% h%h% vED3,%cmdx% ;- add CMDx command above for test
;---------
x:=(wa*66)/xx,y:=(ha*70)/xx,w:=(wa*5)/xx,h:=(ha*2.2)/xx
Gui, Add, Edit, x%x% y%y% w%w% h%h% vED4 center, ;- started / ended
;---------
x:=(wa*66)/xx,y:=(ha*63)/xx,w:=(wa*5)/xx,h:=(ha*2.2)/xx
Gui,add,button, x%x% y%y% w%w% h%h% gCLEAR, <CLEAR
x:=(wa*66)/xx,y:=(ha*66)/xx,w:=(wa*5)/xx,h:=(ha*2.2)/xx
Gui,add,button, x%x% y%y% w%w% h%h% gA0, <START
;--------
x:=(wa*.1)/xx,y:=(ha*4)/xx,w:=(wa*72)/xx,h:=(ha*75)/xx
Gui, Show,x%x% y%y% w%w% h%h%,%name1%
;gosub,a0
return
;-------------------------
Guiclose:
Exitapp
;==============================
A0:
Gui,1:submit,nohide
Guicontrol,1:,ED2,
Guicontrol,1:,ED4,Started...
sleep,300
ED3a:="cmd /c " . ED3
CmdRet(ED3a, Func("AddOutputInGui"),CPX)
;CmdRet(ED3a, Func("AddOutputInGui"), "cp850")
Guicontrol,1:,ED4,ENDED
if ED3 contains youtube
run,%fdmp4%
return
;-------------------------
CLEAR:
Guicontrol,1:,ED1,
Guicontrol,1:,ED3,
Guicontrol,1:,ED4,
GuiControl,1: Focus,ED3
return
;-------------------------
;-------------------------
OnClipboardChange:
{
id:=""
L:=""
If (A_EventInfo=1)
{
;if (winactive("YouTube"))
{
if (instr(clipboard, "https://www.youtube.com") or (instr(clipboard,"https://invidio.us") ) )
{
Loop,parse,clipboard, `n, `r
{
x= %a_loopfield%
if x=
continue
Loop, Parse,x,`/`=`&`?%a_space%`#`:
{
id:= A_LoopField
stringlen,L,id
if (L=11)
break
}
}
}
}
}
if (L=11)
{
Gui,1:show
url=https://www.youtube.com/watch?v=%id%
sleep,300
Guicontrol,1:,ED1,%clipboard%
cmdxx:=sp1 . " " . url . " --verbose --youtube-skip-dash-manifest --write-auto-sub --sub-lang en -o " . s . fdmp4 . "\`%(title)s$`%(uploader)s$`%(id)s.`%(ext)s"
Guicontrol,1:,ED3,%cmdxx%
GuiControl,1: Focus,ED3
gosub,A0
}
clipboard=
return
}
return
;-------------------------------
;=========================================================
AddOutputInGui(output) {
Control, EditPaste, %output%`r`n, Edit2,%name1% ;- display output in 2nd EDIT
}
;=========================================================
CmdRet(sCmd, callBackFuncObj := "", encoding := "CP0")
{
static HANDLE_FLAG_INHERIT := 0x00000001, flags := HANDLE_FLAG_INHERIT
, STARTF_USESTDHANDLES := 0x100, CREATE_NO_WINDOW := 0x08000000
hPipeRead:=""
hPipeWrite:=""
sOutput:=""
;CPX:="cp" . DllCall("GetOEMCP", "UInt")
DllCall("CreatePipe", "PtrP", hPipeRead, "PtrP", hPipeWrite, "Ptr", 0, "UInt", 0)
DllCall("SetHandleInformation", "Ptr", hPipeWrite, "UInt", flags, "UInt", HANDLE_FLAG_INHERIT)
VarSetCapacity(STARTUPINFO , siSize := A_PtrSize*4 + 4*8 + A_PtrSize*5, 0)
NumPut(siSize , STARTUPINFO)
NumPut(STARTF_USESTDHANDLES, STARTUPINFO, A_PtrSize*4 + 4*7)
NumPut(hPipeWrite , STARTUPINFO, A_PtrSize*4 + 4*8 + A_PtrSize*3)
NumPut(hPipeWrite , STARTUPINFO, A_PtrSize*4 + 4*8 + A_PtrSize*4)
VarSetCapacity(PROCESS_INFORMATION, A_PtrSize*2 + 4*2, 0)
if !DllCall("CreateProcess", "Ptr", 0, "Str", sCmd, "Ptr", 0, "Ptr", 0, "UInt", true, "UInt", CREATE_NO_WINDOW
, "Ptr", 0, "Ptr", 0, "Ptr", &STARTUPINFO, "Ptr", &PROCESS_INFORMATION)
{
DllCall("CloseHandle", "Ptr", hPipeRead)
DllCall("CloseHandle", "Ptr", hPipeWrite)
throw Exception("CreateProcess is failed")
}
DllCall("CloseHandle", "Ptr", hPipeWrite)
VarSetCapacity(sTemp, 4096), nSize := 0
while DllCall("ReadFile", "Ptr", hPipeRead, "Ptr", &sTemp, "UInt", 4096, "UIntP", nSize, "UInt", 0) {
sOutput .= stdOut := StrGet(&sTemp, nSize, encoding)
;sOutput .= stdOut := StrGet(&sTemp, nSize)
;sOutput .= stdOut := StrGet(&sTemp, nSize, CPX)
( callBackFuncObj && callBackFuncObj.Call(stdOut) )
}
DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION))
DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION, A_PtrSize))
DllCall("CloseHandle", "Ptr", hPipeRead)
Return sOutput
}
;=========================================================================================