多线程系统代理下载tube1080p视频

许多实用脚本和封装函数, 可以让您编写脚本更加便捷高效

Moderators: tmplinshi, arcticir

Post Reply
joshatt
Posts: 151
Joined: 07 Dec 2014, 08:41

多线程系统代理下载tube1080p视频

Post by joshatt » 24 Dec 2020, 22:07

Code: Select all

EnvGet, ovx, WG_STARTPOINT_X
EnvGet, ovy, WG_STARTPOINT_Y
MouseMove,%ovx%,%ovy%
clipboard =                     ; Empty the clipboard
click,right
sleep,100
send,e
ClipWait, 2
if ErrorLevel
{
    return
}
cb := Clipboard

tooltip,% cb
sleep,1000
tooltip
SetWorkingDir, h:\youtube-dlc
if(InStr(cb, "https://")>0 or InStr(cb, "http://")>0)
{
          cb := RegExReplace(cb,"&index=.*$","")                  ;如果是youtube playlist中的视频, 去掉尾部的&index=.....
          cb := RegExReplace(cb,"&list=.*$","")                  ;如果是youtube playlist中的视频, 去掉尾部的&list=.....
          RegRead,v,HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings,ProxyServer
          if(v="")
          {
            MsgBox, please turn on system proxy.
            return
          }
          aria = --external-downloader aria2c --external-downloader-args "-x 16 -k 1M"
          full :="-o h:\%(title)s.%(ext)s -i -f 137+bestaudio[ext=m4a] --merge-output-format mp4 -c --proxy " . v . " " 
          . cb . " " . aria
          Run, cmd.exe,,,vid
          WinWaitActive, ahk_pid %vid%
          ControlSend,  ahk_parent, {text}set http_proxy=http://%v%%A_space%`n, ahk_pid %vid%
          ControlSend,  ahk_parent, {text}set https_proxy=https://%v%%A_space%`n, ahk_pid %vid%
          ControlSend,  ahk_parent, {text}youtube-dlc %full%`n, ahk_pid %vid%
}
return
使用方法: 比如想下载存放在h:盘, 就建一个 h:\youtube-dlc 文件夹, 把youtube-dlc.exe和aria2c.exe放进来, 把本脚本也放进来.
然后设置系统代理.
本脚本会抓取系统代理, 用于下载......这样设计的目的, 不用说了, 梯子经常换来换去的, 就不再因此改脚本了
下载全过程是直观的, 这一点费了很多功夫, 抛弃了暗箱的方法
本脚本设计的目标是: 仅下载1080p的格式(下载1080的视频, 下载最高音频m4a, 自动合成mp4), 如果无此格式, 就不下载, 会看到:
ERROR: requested format not available
有其他格式需求的, 可以留言

1~13行, 也就是空行之前, 是配合wgestures软件, 用鼠标手势, 对某一视频链接划手势, 就触发本脚本(wgestures中填写: 命令行------本脚本的全路径, 用双引号括起来). 如果是用其他方式获得视频网址, 替代这些行, 总之网址赋值给变量cb.

注意: youtube-dl / youtube-dlc 的特点是断点续传, 所以有时候下载失败, 比如报错, 比如停住不动, 那么关闭cmd窗口后, 不要着急地去删视频音频的临时文件, 而应该再次运行, 会续传的.

获取系统代理, 仅在win7测试过, 不知道其他系统的键是否相同

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: 多线程系统代理下载tube1080p视频

Post by garry » 25 Dec 2020, 08:46

another example run DOS in GUI
( this example without proxy )

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
}
;=========================================================================================

Image
Last edited by garry on 26 Dec 2020, 10:33, edited 2 times in total.

joshatt
Posts: 151
Joined: 07 Dec 2014, 08:41

Re: 多线程系统代理下载tube1080p视频

Post by joshatt » 25 Dec 2020, 22:05

@garry
Marvellous! Thanks a lot.

sanmaodo
Posts: 45
Joined: 28 Aug 2020, 01:39

Re: 多线程系统代理下载tube1080p视频

Post by sanmaodo » 05 Mar 2021, 11:51

@garry
很强大!谢谢! :bravo: :bravo: :bravo:


Post Reply

Return to “脚本函数”