;---FUNCTIONS----------------------------------------------------------------------- ; Misc Functions that are called by both the Video and Social Media poster ; -------------------------------Variables------------------------------- ; Declare global variables here so they don't have to be declared in each script global ChromeTabsURLArray global DriverTitleArray global LastWebsitePostURL global ChromeFilepath global CurrentTabURL global URLOfLastErrorPage ; #Include %A_ScriptDir%\ChromeAutomationFunctions.ahk ; #Include %A_ScriptDir%\RunCMD.ahk DevModeMsgBox(Message){ if(!DevMode) return Msgbox, 4096, DevModeMsgBox, %Message% return } ; -------------------------------SaveOrPostProgress------------------------------- ; PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging,DiscordVideos" SaveOrPostProgress(Message:="",PostType:=""){ MessageBU := Message ; Msgbox % "PostType: " PostType ; Msgbox % "CurrentSite: " CurrentSite if(CurrentSite != "") Message := CurrentSite . ": " . Message if(InStr(PostType, "Tooltip")){ TooltipThis(Message) } if(InStr(PostType, "ErrorLoggingTextFile")){ Func_LogErrorsToTextFile(Message) } if(InStr(PostType, "ErrorSummaryVar")){ Func_LogErrorsToVar(Message) } if(InStr(PostType, "DiscordErrorLogging")){ PostToDiscordChannel(Message,DiscordErrorLoggingWebhookBotURL) } if(InStr(PostType, "DevModeMsgBox")){ DevModeMsgBox(Message) } if(InStr(PostType, "DiscordVideos")){ Message := MessageBU PostToDiscordChannel(Message,DiscordVideosWebhookURL) } if(InStr(PostType, "DiscordParler")){ Message := MessageBU PostToDiscordChannel(Message,DiscordParlerWebhookURL) } } ; -------------------------------/SaveOrPostProgress------------------------------- ; -------------------------------TooltipThis------------------------------- TooltipThis(String){ ; Xposition := StrLen(String) StringFirstLine := StrSplit(String, "`n") StringFirstLine := StringFirstLine[1] Xposition := StrLen(StringFirstLine) ; Msgbox % "String: " String Xposition := Xposition * 4 X := (A_ScreenWidth / 2) - Xposition ; Msgbox % "X: " X if(ShowTooltipProgress){ ToolTip, %String%, %X%, 0 } } ; -------------------------------/TooltipThis------------------------------- ;------------------------------------------------ TimedToolTip(Text, x="", y="",RemoveAfterTime:=2000, SetWhichToolTip="") { if(X = ""){ Xposition := StrLen(Text) ; Msgbox % "Xposition: " Xposition Xposition := Xposition * 4 ; Xposition := 0 X := (A_ScreenWidth / 2) - Xposition ; Msgbox % "X: " X } (y = "")?(y:=0):(y:=y) ; Msgbox % "y: " y ToolTip, %Text%, %X%, %Y% SetTimer, RMApp_ToolTipRASub, % - RemoveAfterTime return RMApp_ToolTipRASub: ToolTip,,,, %WhichToolTip% return } ; -------------------------------LogErrorsToTextFile------------------------------- Func_LogErrorsToTextFile(Text){ ; ErrorLoggingFile := Filepath FormatTime, TodayDate , YYYYMMDDHH24MISS, yyyyMMdd_hhmmss text = ( ---------------%TodayDate%--------------- %Text% ) FileAppend, %Text%, %ErrorLoggingFilePath% } ; -------------------------------/LogErrorsToTextFile------------------------------- ; -------------------------------LogErrorsToVar------------------------------- Func_LogErrorsToVar(Text){ ErrorLogVar .= "`n" . Text } ; -------------------------------/LogErrorsToVar------------------------------- ; -------------------------------CheckDirExistAndCreate------------------------------- ; Check if directory exists and if not, create it CheckDirExistAndCreate(Path){ if(!FileExist(Path)){ FileCreateDir, %Path% } } ; -------------------------------/CheckDirExistAndCreate------------------------------- CheckIfUpdateAvailable(Filepath, CurrentVersion){ FileRead, ScriptUpdateContents, %Filepath% FileContents := StrSplit(ScriptUpdateContents, "ScriptVersion") FileContents := FileContents[2] FileContents := StrSplit(FileContents, "`n") UpdateVersion := FileContents[1] ; msgbox % UpdateVersion if(!InStr(UpdateVersion, CurrentVersion)){ ; Update found for file, write to settings.ini for next time script is run Message = Update Available to Download SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") Return True } Return False } CheckSeleniumDriver(){ try Driver := SChrome_Get("", ChromeProfile := "") ; open new tab page with with specified profile catch e { ShowSeleniumErrorMsgbox() ; Message = Failed to Make Connection to Chrome. Check for Any Open Dialogue Boxes or out of date ChromeDriver ; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") Return "Failed" } ; Driver := SChrome_Get("https://www.bitchute.com/", ChromeProfile) ; open new tab page with with specified profile ; driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding catch e { ShowSeleniumErrorMsgbox() ; Message = Failed to send command to Chrome. Check for an Open Dialogue Box. ; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") Return "Failed" } DriverStatus := 1 if(ReuseTabs) CreateArrayOfChromeTabs() } SeleniumConnectToActiveTab(IP_Port := "127.0.0.1:9222"){ Driver := ComObjCreate("Selenium.ChromeDriver") Driver.SetCapability("debuggerAddress", IP_Port) try Driver.Start() catch e { Message = Failed to Connect to Chrome. Showing Error Msgbox SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") ShowSeleniumErrorMsgbox() ; msgbox, failed to connect to Chrome for some reason. ; Message = Failed to Connect to Chrome for some reason. ; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") } return Driver } /* */ CreateArrayOfChromeTabs() { Message = Creating an Array of All Chrome Tabs SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") ; Create an arrays DriverTitleArray := [] ChromeTabsURLArray := [] try TotalTabsFound := Driver.Windows.Count ; Message = TotalTabsFound: %TotalTabsFound% ; DevModeMsgBox(Message) ; DevModeMsgBox(TotalTabsFound) /* ; if only 1 tab exists, grab info, push to array and return if(TotalTabsFound = 1){ try Title := Driver.Title try URL := Driver.URL if(Title != "") DriverTitleArray.Push(Title) if(URL != "") ChromeTabsURLArray.Push(URL) return } */ ; Msgbox % "TotalTabsFound: " TotalTabsFound ; if(DevMode) ; Msgbox % "TotalTabsFound: " TotalTabsFound ; msgbox % "total Tabs:" Driver.Windows.Count ; Message = Creating an Array of Chrome Tabs ; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") ; StartTime := A_TickCount ; Sleep, 1000 StartTime := A_TickCount ; 5 is arbitrary number to do some extra loops to make sure all tabs are gone through ; most likely not necessary because unloaded tabs cannot be activated TotalTabLoops := TotalTabsFound + 5 ; Message = TotalTabLoops: %TotalTabLoops% ; DevModeMsgBox(message) Loop % TotalTabLoops { Message = Creating an Array of All Chrome Tabs`nCurrent Loop: %A_index%/%TotalTabLoops% (Cannot check on unloaded tabs)`nSometimes might get stuck for a short while if there is something loading in active tab TooltipThis(Message) ; exit after looping through 1 tab, if only 1 tab found in count if(TotalTabsFound = 1 AND A_index > TotalTabsFound){ Message = Exiting Early after 1 loop ; DevModeMsgBox(message) break } TabEndTime := A_TickCount - TabFoundStartTime TabEndTimeArray .= TabEndTime . "," ; Message = Time to switch to new tab: %TabEndTime%`nCurrent Loop: %A_index%/%TotalTabsFound% ; SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging") TabFoundStartTime := A_TickCount ; TimeToGrabCurrentTab := A_TickCount - StartTime ; Msgbox % "TimeToGrabCurrentTab: " TimeToGrabCurrentTab ; Stop page refresh if it's happening ; try driver.executeScript("return window.stop") try Title := Driver.Title try URL := Driver.URL ; TimeToGrabCurrentTab := A_TickCount - StartTime ; Msgbox % "TimeToGrabCurrentTab: " TimeToGrabCurrentTab ; VAR := HasVal(ChromeTabsURLArray, STRINGVAR) ; returns position of value in array /* if(HasVal(ChromeTabsURLArray, URL)){ ; returns position of value in array DevModeMsgBox("Skipping rest of loop and continuing") Continue } */ if(Title != "") DriverTitleArray.Push(Title) if(URL != "") ChromeTabsURLArray.Push(URL) try driver.SwitchToNextWindow ;Focuses Selenium on the newly opened/next window. ; DevModeMsgBox("switching to next tab") } ; end of loop ; TimeToLoopThroughAllTabs := A_TickCount - StartTime ; Message = Time to Loop through all tabs: %TimeToLoopThroughAllTabs% ; SaveOrPostProgress(Message:=Message,PostType:="ErrorLoggingTextFile,DiscordErrorLogging") ; DevModeMsgBox(Message) return } /* */ InputFilePathIntoOpenWindow(Filepath){ ; Msgbox % "Filepath: " Filepath Message = Waiting for "Open" window to appear to input filepath into SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") ; Tooltip,Waiting for "Open" window to appear to input filepath into,850,0 ; WinWait, Open WinWait,Open,,5 ; Wait for 10 seconds for window if(ErrorLevel) { ; msgbox, failed to find window. Return "Failed" } WinActivate, Open sleep, 1000 ControlSetText, Edit1, %Filepath%, Open sleep, 1000 ControlSend, Edit1, {Enter}, Open sleep, 1000 ; Do an extra check in case the Open window is still open. OpenWindowExist := WinExist("Open") if(OpenWindowExist) ControlSend, Edit1, {Enter}, Open ToolTip, } /* */ ; -------------------------------FileXPro Get File Attributes------------------------------- ;https://www.autohotkey.com/boards/viewtopic.php?t=59882 Filexpro( sFile := "", Kind := "", P* ) { ; v.90 By SKAN on D1CC @ goo.gl/jyXFo9 Local Static xDetails If ( sFile = "" ) { ; Deinit static variable xDetails := "" Return } fex := {}, _FileExt := "" Loop, Files, % RTrim(sfile,"\*/."), DF { If not FileExist( sFile:=A_LoopFileLongPath ) { Return } SplitPath, sFile, _FileExt, _Dir, _Ext, _File, _Drv If ( p[p.length()] = "xInfo" ) ; Last parameter is xInfo { p.Pop() ; Delete parameter fex.SetCapacity(11) ; Make room for Extra info fex["_Attrib"] := A_LoopFileAttrib fex["_Dir"] := _Dir fex["_Drv"] := _Drv fex["_Ext"] := _Ext fex["_File"] := _File fex["_File.Ext"] := _FileExt fex["_FilePath"] := sFile fex["_FileSize"] := A_LoopFileSize fex["_FileTimeA"] := A_LoopFileTimeAccessed fex["_FileTimeC"] := A_LoopFileTimeCreated fex["_FileTimeM"] := A_LoopFileTimeModified } Break } If Not ( _FileExt ) ; Filepath not resolved { Return } objShl := ComObjCreate("Shell.Application") objDir := objShl.NameSpace(_Dir) objItm := objDir.ParseName(_FileExt) If ( VarSetCapacity(xDetails) = 0 ) ; Init static variable { i:=-1, xDetails:={}, xDetails.SetCapacity(309) While ( i++ < 309 ) { xDetails[ objDir.GetDetailsOf(0,i) ] := i } xDetails.Delete("") } If ( Kind and Kind <> objDir.GetDetailsOf(objItm,11) ) ; File isn't desired kind { Return } i:=0, nParams:=p.Count(), fex.SetCapacity(nParams + 11) While ( i++ < nParams ) { Prop := p[i] If ( (Dot:=InStr(Prop,".")) and (Prop:=(Dot=1 ? "System":"") . Prop) ) { fex[Prop] := objItm.ExtendedProperty(Prop) Continue } If ( PropNum := xDetails[Prop] ) > -1 { fex[Prop] := ObjDir.GetDetailsOf(objItm,PropNum) Continue } } fex.SetCapacity(-1) Return fex } ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; GuiButtonIcon ;------------------------------------------------ GuiButtonIcon(Handle, File, Index := 1, Options := "") { RegExMatch(Options, "i)w\K\d+", W), (W="") ? W := 16 : RegExMatch(Options, "i)h\K\d+", H), (H="") ? H := 16 : RegExMatch(Options, "i)s\K\d+", S), S ? W := H := S : RegExMatch(Options, "i)l\K\d+", L), (L="") ? L := 0 : RegExMatch(Options, "i)t\K\d+", T), (T="") ? T := 0 : RegExMatch(Options, "i)r\K\d+", R), (R="") ? R := 0 : RegExMatch(Options, "i)b\K\d+", B), (B="") ? B := 0 : RegExMatch(Options, "i)a\K\d+", A), (A="") ? A := 4 : Psz := A_PtrSize = "" ? 4 : A_PtrSize, DW := "UInt", Ptr := A_PtrSize = "" ? DW : "Ptr" VarSetCapacity( button_il, 20 + Psz, 0 ) NumPut( normal_il := DllCall( "ImageList_Create", DW, W, DW, H, DW, 0x21, DW, 1, DW, 1 ), button_il, 0, Ptr ) ; Width & Height NumPut( L, button_il, 0 + Psz, DW ) ; Left Margin NumPut( T, button_il, 4 + Psz, DW ) ; Top Margin NumPut( R, button_il, 8 + Psz, DW ) ; Right Margin NumPut( B, button_il, 12 + Psz, DW ) ; Bottom Margin NumPut( A, button_il, 16 + Psz, DW ) ; Alignment SendMessage, BCM_SETIMAGELIST := 5634, 0, &button_il,, AHK_ID %Handle% return IL_Add( normal_il, File, Index ) } ; \GuiButtonIcon ;------------------------------------------------ ToggleTestingMode(){ IniRead, TestingMode, Settings.ini, General, TestingMode, 0 ; Msgbox % "TestingMode: " TestingMode if(TestingMode) IniWrite, 0, Settings.ini, General, TestingMode else, IniWrite, 1, Settings.ini, General, TestingMode } ToggleManualSubmit(){ IniRead, ManualSubmit, Settings.ini, General, ManualSubmit, 0 ; Msgbox % "TestingMode: " TestingMode if(ManualSubmit) IniWrite, 0, Settings.ini, General, ManualSubmit else, IniWrite, 1, Settings.ini, General, ManualSubmit } ToggleDevMode(){ IniRead, DevMode, Settings.ini, General, DevMode, 0 ; Msgbox % "TestingMode: " TestingMode if(DevMode) IniWrite, 0, Settings.ini, General, DevMode else, IniWrite, 1, Settings.ini, General, DevMode } FormatTextToJSText(Var){ ; Replaces AHK newline characters with javascript ones /*\b Backspace \f Form Feed \n New Line - done \r Carriage Return \t Horizontal Tabulator \v Vertical Tabulator \' Single quote - done \" Double quote - done \\ Backslash - done */ SingleQuotationmark = " ; Variable of Escaped Symbols EscapedSingleQuote = \' EscapedDoubleQuote = \" EscapedBackslash = \\ EscapedNewLine = \n ; Replace each character that needs replacing in the text string Var := StrReplace(Var, "\", EscapedBackslash) ; needed otherwise selenium will error out Var := StrReplace(Var, "`n", EscapedNewLine) ; needed otherwise selenium will error out Var := StrReplace(Var, "`r", "") ; needed otherwise selenium will error out Var := StrReplace(Var, SingleQuotationmark, EscapedDoubleQuote) ; needed otherwise selenium will error out Var := StrReplace(Var, "'", EscapedSingleQuote) ; needed otherwise selenium will error out ; Var := StrReplace(Var, "`r", "") ; needed otherwise selenium will error out Return Var } ; OnMsgbox Functions ;------------------------------------------------ OnMsgBoxUpdateAvailable() { DetectHiddenWindows, On Process, Exist If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) { ControlSetText Button1, Cancel ControlSetText Button2, Install } } OnMsgBoxChromeDriverFailed() { DetectHiddenWindows, On Process, Exist If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) { WinMove,, 0 ControlSetText Button1, Reload Script ControlSetText Button2, ChromeDriver ControlSetText Button3, Instructions } } SaveCurrentChromeVersionToIniFile(){ ; Msgbox % "ChromeFilepath: " ChromeFilepath GetChromeVersionCommand = powershell (Get-Item '%ChromeFilepath%').VersionInfo.ProductVersion Chromeversion := RunCMD(GetChromeVersionCommand) if(InStr(ChromeVersion, "scripts is disabled on this system")){ ChromeVersion = Not Able to Grab Because: "scripts are disabled in powershell" } ; Msgbox % "Chromeversion: " Chromeversion ; Msgbox % "Chromeversion: " Chromeversion if(ChromeFilepath = "") return ; Chromeversion := StrSplit(Chromeversion, "`n") ; Chromeversion := Chromeversion[4] IniWrite, %ChromeVersion%, Settings.ini, Misc, ChromeVersion } SaveDriverURLOFErrorPage(){ ; save the url of the result page. That way if a tab is not found for a site, we can open up a tab from this tab instead of middle of nowhere. That way we can keep the tabs together try URLOfLastErrorPage := driver.URL }