#SingleInstance OFF #NoTrayIcon ;#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. StringReplace, url, 1, ",, All StringReplace, save, 2, ",, All StringReplace, pospar, 3, ",, All StringReplace, showWin, 4, ",, All StringReplace, proxy, 5, ",, All ;StringReplace, showWin, 6, ",, All ;get_highest_YT_quality(v1,t1,l1,"get_highest_YT_quality") IfEqual,showWin,get_highest_YT_quality { YTq := get_highest_YT_quality(url,save,pospar,proxy) Gui, +lastfound -caption +Border +ToolWindow ;+owner wn := WinExist() Gui, Add, Text, vYoutube_q, %YTq% Gui, Show, Hide x10 y10 w300 h30, VidRipper_Dnl_YTq Sleep, 3000 ExitApp } if not url { url = http://www.bbdo.hu/mytest/magyar/works/007_work1.wmv MsgBox,4, SR_Download, Do you want to show download windows? IfMsgBox Yes showWin = 1 else showWin = sleep, 1000 } if not save save = %A_ScriptDir%\temp.wmv if not pospar pospar = 1 SplitPath,save,file rfile := SubStr(file,InStr(file,"_")+1) urlfile := file If rfile urlfile := rfile ;message = 0x11100 ;OnMessage(message, "SetCounter") Loop, 20 ;setting win positions { pos%A_Index% := ((A_Index-1) * 31)+100 } posy := pos%pospar% Gui, +lastfound -caption +Border +ToolWindow ;+owner wn := WinExist() Gui, Add, Progress, Section x55 vProgressBar w100 +Smooth cBDDCEF Gui, Add, Text, Middle x+3 ys-5 h28 w140 vDnlFile, %urlfile% Gui, Font, bold Gui, Add, Text, vProgressN BackgroundTrans w200 x70 ys+2, connecting... Gui, Font Gui, Add, Text, vKB x95 ys+2 w200 BackgroundTrans, Gui, Add, Button, ys x5 w48 h20 gExit, Close If showWin Gui, Show, NoActivate x10 y%posy% w300 h30, VidRipper_Dnl_%pospar% else Gui, Show, Hide x10 y%posy% w300 h30, VidRipper_Dnl_%pospar% total := HttpQueryInfo(url, 5, proxy) If not total ExitApp ;GuiControl, , KB, % "of " round(total/1024/1024,1) " MB" FileDelete, %save% save_dir := SubStr(save,1,InStr(save,"\",false,0)-1) postdata = chr() %urlfile%|%total% ;PostMessage, 8191, %total%, %pospar%, , VidRipperWin Dnlder_Name = VidRipper_Dnl runIDx = runID%pospar% runID := DllCall("GetCurrentProcessId") tsize := round(total/1024,1) IniWrite, %runID%|%url%|%save%|%tsize%, %A_ScriptDir%\%Dnlder_Name%.ini, Running, %runIDx% res:=Download(url, save, message, 1000) ;PostMessage, 8193, 0, %pospar%, , VidRipperWin ExitApp Return Exit: GuiEscape: GuiClose: ExitApp Download(url, save, msg = 0x11100, sleep = 1000) { Global total, save_dir, wid, op_win, pospar, runID, tsize, Dnlder_Name, runIDx SetTimer, _dlprocess, %sleep% UrlDownloadToFile, %url%, %save% SetTimer, _dlprocess, Off Return, ErrorLevel _dlprocess: FileGetSize, current, %save%, K ;Process, Exist ;PostMessage, msg, current * 1024, total, , ahk_pid %ErrorLevel% ;PostMessage, 8192, % current * 1024, %pospar%, , VidRipperWin tprog := Round(current*1024/total*100) IniWrite, %runID%|%url%|%save%|%tsize%|%tprog%, %A_ScriptDir%\%Dnlder_Name%.ini, Running, %runIDx% SetCounter(current * 1024, total) Exit } SetCounter(wParam, lParam) { progress := Round(wParam / lParam * 100) GuiControl, , ProgressBar, %progress% GuiControl, , ProgressN, % progress "%" GuiControl, , KB, % "" round(lParam/1024,1) " KB" } get_highest_YT_quality(v1,t1,l1,proxy) { ; // fmt=0 -> flv: 320x240 (flv1) / mp3 1.0 22KHz (same as fmt=5) ; // fmt=5 -> flv: 320x240 (flv1) / mp3 1.0 22KHz ; // fmt=6 -> flv: 480x360 (flv1) / mp3 1.0 44KHz (No more...) ; // fmt=13 -> 3gp: 176x144 (mpg4) / ??? 2.0 8KHz ; // fmt=17 -> 3gp: 176x144 (mpg4) / ??? 1.0 22KHz ; // fmt=18 -> mp4: 480x360 (H264) / AAC 2.0 44KHz ; // fmt=22 -> mp4: 1280x720 (H264) / AAC 2.0 44KHz ; // fmt=34 -> flv: 320x240 (flv?) / ??? 2.0 44KHz (default now) ; // fmt=35 -> flv: 640x380 (flv?) / ??? 2.0 44KHz fmts = 22|35|18|6 loop, parse, fmts, | { HQtag = &fmt=%A_LoopField% url = http://www.youtube.com/get_video?video_id=%v1%&l=%l1%&t=%t1%%HQtag% info2 := HttpQueryInfo(url,1,proxy) ;MsgBox, info2 = %info2% If info2 not contains timeout,text Return, %A_LoopField% } Return, 5 } ;----------HttpQueryInfo--------------- /* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; HttpQueryInfo ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; QueryInfoFlag HTTP_QUERY_RAW_HEADERS = 21 Receives all the headers returned by the server. Each header is terminated by "\0". An additional "\0" terminates the list of headers. HTTP_QUERY_CONTENT_LENGTH = 5 Retrieves the size of the resource, in bytes. HTTP_QUERY_CONTENT_TYPE = 1 Receives the content type of the resource (such as text/html). Find more at: http://msdn.microsoft.com/library/en-us/wininet/wininet/query_info_flags.asp Proxy Settings: INTERNET_OPEN_TYPE_PRECONFIG 0 // use registry configuration INTERNET_OPEN_TYPE_DIRECT 1 // direct to net INTERNET_OPEN_TYPE_PROXY 3 // via named proxy INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY 4 // prevent using java/script/INS */ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; HttpQueryInfo(URL, QueryInfoFlag=21, Proxy="", ProxyBypass="") { hModule := DllCall("LoadLibrary", "str", "wininet.dll") If (Proxy != "") AccessType=3 Else AccessType=1 io_hInternet := DllCall("wininet\InternetOpenA" , "str", "" ;lpszAgent , "uint", AccessType , "str", Proxy , "str", ProxyBypass , "uint", 0) ;dwFlags If (ErrorLevel != 0 or io_hInternet = 0) { DllCall("FreeLibrary", "uint", hModule) return, -1 } iou_hInternet := DllCall("wininet\InternetOpenUrlA" , "uint", io_hInternet , "str", url , "str", "" ;lpszHeaders , "uint", 0 ;dwHeadersLength , "uint", 0x80000000 ;dwFlags: INTERNET_FLAG_RELOAD = 0x80000000 // retrieve the original item , "uint", 0) ;dwContext If (ErrorLevel != 0 or iou_hInternet = 0) { DllCall("FreeLibrary", "uint", hModule) return, -1 } VarSetCapacity(buffer, 1024, 0) VarSetCapacity(buffer_len, 4, 0) Loop, 5 { hqi := DllCall("wininet\HttpQueryInfoA" , "uint", iou_hInternet , "uint", QueryInfoFlag ;dwInfoLevel , "uint", &buffer , "uint", &buffer_len , "uint", 0) ;lpdwIndex If (hqi = 1) { hqi=success break } } IfNotEqual, hqi, success, SetEnv, res, timeout If (hqi = "success") { p := &buffer Loop { l := DllCall("lstrlen", "UInt", p) VarSetCapacity(tmp_var, l+1, 0) DllCall("lstrcpy", "Str", tmp_var, "UInt", p) p += l + 1 res := res . "`n" . tmp_var If (*p = 0) Break } StringTrimLeft, res, res, 1 } DllCall("wininet\InternetCloseHandle", "uint", iou_hInternet) DllCall("wininet\InternetCloseHandle", "uint", io_hInternet) DllCall("FreeLibrary", "uint", hModule) return, res } ;----------end HttpQueryInfo--------------- ;----------URLDownloadToVar--------------- UrlDownloadToVar(xurl, Proxy="", ProxyBypass="") { AutoTrim, Off hModule := DllCall("LoadLibrary", "str", "wininet.dll") If (Proxy != "") AccessType=3 Else AccessType=1 ;INTERNET_OPEN_TYPE_PRECONFIG 0 // use registry configuration ;INTERNET_OPEN_TYPE_DIRECT 1 // direct to net ;INTERNET_OPEN_TYPE_PROXY 3 // via named proxy ;INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY 4 // prevent using java/script/INS io_hInternet := DllCall("wininet\InternetOpenA" , "str", "" ;lpszAgent , "uint", AccessType , "str", Proxy , "str", ProxyBypass , "uint", 0) ;dwFlags iou := DllCall("wininet\InternetOpenUrlA" , "uint", io_hInternet , "str", xurl , "str", "" ;lpszHeaders , "uint", 0 ;dwHeadersLength , "uint", 0x80000000 ;dwFlags: INTERNET_FLAG_RELOAD = 0x80000000 // retrieve the original item , "uint", 0) ;dwContext If (ErrorLevel != 0 or iou = 0) { DllCall("FreeLibrary", "uint", hModule) AutoTrim, on return 0 } VarSetCapacity(buffer, 512, 0) VarSetCapacity(NumberOfBytesRead, 4, 0) Loop { irf := DllCall("wininet\InternetReadFile", "uint", iou, "uint", &buffer, "uint", 512, "uint", &NumberOfBytesRead) NOBR = 0 Loop 4 ; Build the integer by adding up its bytes. - ExtractInteger NOBR += *(&NumberOfBytesRead + A_Index-1) << 8*(A_Index-1) IfEqual, NOBR, 0, break ;BytesReadTotal += NOBR DllCall("lstrcpy", "str", buffer, "uint", &buffer) res = %res%%buffer% } StringTrimRight, res, res, 2 DllCall("wininet\InternetCloseHandle", "uint", iou) DllCall("wininet\InternetCloseHandle", "uint", io_hInternet) DllCall("FreeLibrary", "uint", hModule) AutoTrim, on return, res } ;----------end URLDownloadToVar---------------