reworked Dailymotion login check, video title input, description input, tags input, and category selection. added extra errorlogging and added check for chrome alerts and dismissing if any

pull/2/head
Yuriy 2 years ago
parent 1f9ce32649
commit 8cd2374736

@ -1111,7 +1111,7 @@ IniWrite, %PodcastNumber%, %VideoLinksIniFile%, Misc, PodcastNumber
; Log Basic info to the errorlogging file ; Log Basic info to the errorlogging file
Message = Starting Upload For: **%VideoTitle%**`nTo: %PostedWebsites%`nWith %ScriptVersion% Message = %ScriptName% v%ScriptVersion%: Starting Upload `nFor: **%VideoTitle%**`nTo: %PostedWebsites%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Message := "VideoTitle: " VideoTitle Message := "VideoTitle: " VideoTitle
@ -3682,6 +3682,62 @@ SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
try 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
sleep, 1500 sleep, 1500
Message = Checking Log In Status
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
LoggedOutStatus := CheckURLForSubstring("/sign-in")
if(LoggedOutStatus){
if(AutoLogin){
Message = Trying to Log Back in Automatically
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
; have to click into username and password field for page to register that there's input
; clicking with JS doesn't make it register, but with xpath selenium it does
Xpath = //input[@placeholder='Email address']
try driver.FindElementByXPath(Xpath).click()
Xpath = //input[@placeholder='Enter password']
driver.FindElementByXPath(Xpath).click()
js = document.querySelector("button[type='submit']").click();
driver.executeScript(js)
driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
sleep, 1000
; Do a double check to make sure that login worked
Message = Checking Login Status
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
LoggedOutStatus := CheckURLForSubstring("/sign-in")
if(LoggedOutStatus){
Message = Failed to log back in. Please Log Back In Manually
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
}
}
else, { ; notify user and return
Message = Login Expired. Please Log Back in
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
}
Message = Waiting 5 seconds for page to fully load
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
sleep, 5000
}
status := CheckForAlerts()
if(Status){
Message = Waiting for page to fully load
try, driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
sleep, 2000
}
Message = Uploading Video Message = Uploading Video
@ -3690,50 +3746,29 @@ SaveOrPostProgress(Message:=Message,PostType:="Tooltip")
Xpath = //input[@type='file'] Xpath = //input[@type='file']
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=1,SleepLength:=2000,StringTextContent:=VideoFilepath) Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=1,SleepLength:=2000,StringTextContent:=VideoFilepath)
if(Status){ if(Status){
; DevModeMsgBox(Status)
Message = Trying to Log Back In
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Xpath = //button[normalize-space()='Log in']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
sleep, 5000
; Upload file again
Xpath = //input[@type='file']
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=1,SleepLength:=2000,StringTextContent:=VideoFilepath)
}
; DevModeMsgBox("test")
sleep, 2000
; Click on Upload Thumbnail Button
TooltipThis("Uploading Thumbnail")
Xpath = //input[@type='file'] Message = Failed to Upload Video. Please Check Login Status
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=VideoThumbFilepath)
if(Status){
Message = Failed to Upload Thumbnail: Check Login Status
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
} }
sleep, 2000
Message = Inputting Video Details
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
Message = Uploading Thumbnail
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; @todo: uncomment this and replace the selenium funciton Xpath = //input[@type='file']
; Clear video title that is input automatically and input the real title Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=VideoThumbFilepath)
/*Msgbox % "JSVideoTitle: " JSVideoTitle
js_SendAndCheckWithNAME(Element:="title",ClassIndexNum:=0,ValueToCheck:="value",SleepLength:=1000,JSStringText:=JSVideoTitle)
Msgbox % "Status: " Status
if(Status){ if(Status){
Message = Failed to input Video Title Message = Failed to Upload Thumbnail: Check Login Status
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
} }
*/ ;
; Message = Inputting Video Details
; Clear out the pre-input title ; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
; js = return document.getElementsByName('title')[0].value = ""; ; Send content through javascript (Great for getting around emoji chrome limitaitons)
; try driver.executeScript(js) ;Executes a Javascript on the webpage, mostly used for buttons.
; try driver.findElementsByName("title").item[1].clear()
Message = Inputting Title Message = Inputting Title
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
@ -3791,6 +3826,71 @@ if(CurrentTitle != VideoTitle){
else, else,
Break Break
}
Message = Inputting Video Description
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
if(strLen(VideoDescription) > 2900){
DailyMotionDescription := SubStr(VideoDescription, 1, 2900) . "..."
}
else,
DailyMotionDescription := VideoDescription
DailyMotionJSDescription := FormatTextToJSText(DailyMotionDescription)
Message = DailyMotionJSDescription String Length := StrLen(DailyMotionJSDescription)
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
Message = Inputting Video Description
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
Loop, 5 { ; make a couple attempts to input description
if(A_index = 5){
Message = Failed to input Description after %A_index% attempts.
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
}
; click into element
Xpath = //textarea[@placeholder='Enter a description']
try driver.FindElementByXPath(Xpath).click()
; send a space and then backspace so element registers the input
Xpath = //textarea[@placeholder='Enter a description']
try driver.FindElementByXPath(Xpath).SendKeys(driver.Keys.SPACE)
try driver.FindElementByXPath(Xpath).SendKeys(driver.Keys.BackSpace)
; inut description with javascript
js = document.querySelector("textarea[placeholder='Enter a description']").value = "%JSVideoDescription%";
try driver.executeScript(js)
; send a space and then backspace so element registers the input
Xpath = //textarea[@placeholder='Enter a description']
try driver.FindElementByXPath(Xpath).SendKeys(driver.Keys.SPACE)
try driver.FindElementByXPath(Xpath).SendKeys(driver.Keys.BackSpace)
sleep, 1000
js = return document.querySelector("textarea[placeholder='Enter a description']").textContent;
try, InputDescription := driver.executeScript(js)
message = InputDescription: %InputDescription%
DevModeMsgBox(InputDescription)
; if input description is less than 15 chars, try again
if(StrLen(InputDescription) < 15)
Continue
else,
Break
} }
@ -3799,25 +3899,49 @@ Break
; Make a couple attempts to Click on Drop down menu and select the "Education" Category ; Make a couple attempts to Click on Drop down menu and select the "Education" Category
TooltipThis("Selecting Education Category") TooltipThis("Selecting Education Category")
Xpath = //div[@name='channel'] Loop, 3 {
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000) if(A_index = 3){
if(Status){ Message = Failed to Select Education Category after %A_index% attempts
SaveOrPostProgress(Message:="Failed to click the Category dropdown button",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage() Return
Return }
}
Xpath = //div[@name='channel']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
js = document.querySelector("div[title='Education'] div[class='ant-select-item-option-content']").click()
try status := driver.executeScript(js)
js = return document.querySelector("div[name='channel']").textContent;
try, status := driver.executeScript(js)
if(instr(status, "Education"))
break
js = document.querySelector("div[title='Education'] div[class='ant-select-item-option-content']").click()
try status := driver.executeScript(js)
catch e {
SaveOrPostProgress(Message:="Failed to select Education category",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
} }
Message = Inputting Tags
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; Msgbox % "VideoTags: " VideoTags
DailyMotionVideoTags := VideoTags . ",,"
Message = DailyMotion Video Tags: %DailyMotionVideoTags%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; DevModeMsgBox(DailyMotionVideoTags)
Xpath = //div[@class='ant-select-selection-search']//input[@role='combobox']
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=DailyMotionVideoTags)
; Msgbox % "Status: " Status
js = return document.querySelector("div[name='tags']").textContent;
try, inputTags := driver.executeScript(js)
Message = Tags that got input: %inputTags% (Will be doubled b/c of js)
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
; DevModeMsgBox(message)
/*sleep, 2000 ; sleep 2 seconds for everything to catch up GUI wise /*sleep, 2000 ; sleep 2 seconds for everything to catch up GUI wise
loop, 5 { loop, 5 {
@ -3912,42 +4036,6 @@ js = document.getElementsByName('basic')[0].click();
try driver.executeScript(js) try driver.executeScript(js)
/*Xpath = //button[normalize-space()='Basic']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
*/
sleep, 1000
/*
TooltipThis("Inputting Tags")
; Input Each tag one by one
Loop % KeywordsArray.Length()
{
Tag := KeywordsArray[A_Index]
xpath = (//input[@class='ant-select-search__field'])[1]
try driver.FindElementByXPath(Xpath).SendKeys(Tag)
catch e {
Message = Failed to input tag: %tag%
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
}
try driver.FindElementByXPath(Xpath).SendKeys(driver.Keys.Tab)
sleep, 250
; OLD Method
; xpath = (//input[@class='ant-select-search__field'])[1]
; driver.FindElementByXPath(Xpath).SendKeys(Tag)
; Tag := KeywordsArray[A_Index]
; try driver.findElementsByName("tags").item[1].SendKeys(Tag)
; sleep, 100
; try driver.findElementsByName("tags").item[1].SendKeys(driver.Keys.Enter)
; sleep, 100
}
*/
; DevModeMsgBox("tags input?")
; Grab the Share URL and pull out the Video Link from it and save it to the Video Linsk ini file, so double uploads are not tried if fialure occurs ; Grab the Share URL and pull out the Video Link from it and save it to the Video Linsk ini file, so double uploads are not tried if fialure occurs
Message = Grabbing Share URL Message = Grabbing Share URL
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile") SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
@ -3962,107 +4050,6 @@ DailyMotionURL := StrReplace(ShareLink, "Share link: ","") ; remove the share li
IniWrite, %DailyMotionURL%, %VideoLinksIniFile%, URLs, DailyMotionURL ; save URL IniWrite, %DailyMotionURL%, %VideoLinksIniFile%, URLs, DailyMotionURL ; save URL
Message = Inputting Video Description
DailyMotionJSDescription := FormatTextToJSText(VideoDescription)
if(StrLen(DailyMotionJSDescription) > 3000){
DailyMotionJSDescription := SubStr(VideoDescription, 1, 2990)
DailyMotionJSDescription := FormatTextToJSText(DailyMotionDescription)
DailyMotionJSDescription .= "....."
}
; Input Video Description
Message = Inputting Video Description
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")
Loop, 5 { ; make a couple attempts to input description
if(A_index = 5){
Message = Failed to input Description after %A_index% attempts.
; SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
; Return
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
SaveDriverURLOFErrorPage()
Return
}
; click into element
Xpath = //textarea[@placeholder='Enter a description']
driver.FindElementByXPath(Xpath).click()
; inut description with javascript
js = document.querySelector("textarea[placeholder='Enter a description']").value = "%JSVideoDescription%";
try driver.executeScript(js)
sleep, 1000
; send a space and then backspace so element registers the input
Xpath = //textarea[@placeholder='Enter a description']
try driver.FindElementByXPath(Xpath).SendKeys(driver.Keys.SPACE)
try driver.FindElementByXPath(Xpath).SendKeys(driver.Keys.BackSpace)
sleep, 1000
js = return document.querySelector("textarea[placeholder='Enter a description']").textContent;
try, InputDescription := driver.executeScript(js)
message = InputDescription: %InputDescription%
DevModeMsgBox(InputDescription)
; if input description is less than 15 chars, try again
if(StrLen(InputDescription) < 15){
Continue
}
else, {
Break
}
}
; DevModeMsgBox("done")
/*
; Input Video Description
Loop, 15 { ; make a couple attempts to input description
TooltipThis("Inputting Video Description")
js = document.getElementsByName('description')[0].value = ""; ; clear any text from box
driver.executeScript(js) ;Executes a Javascript on the webpage, mostly used for buttons.
; try driver.findElementsByName("description").item[1].SendKeys(driver.Keys.Space) ; send an ENTER keystroke to make it register that data has been input and refresh
; sleep, 500
; Clear any text from a previous loop
; try driver.findElementsByName("description").item[1].clear()
; try driver.findElementsByName("description").item[1].SendKeys(driver.Keys.SPACE) ;;Clicks Item based on the Element Name
; ValueToCheckOptions = innertext,textContent,InnerHTML,outerHTML,value,href,option value
; JSText := FormatTextToJSText(TEXT)
js = document.getElementsByName('description')[0].value = "%DailyMotionJSDescription%";
try driver.executeScript(js)
sleep, 2000
try driver.findElementsByName("description").item[1].SendKeys(driver.Keys.Space) ; send an ENTER keystroke to make it register that data has been input and refresh
sleep, 2000
jsCheck = return document.getElementsByName('description')[0].value; ; Send content through javascript (Great for getting around emoji chrome limitaitons)
DescriptionInput := driver.executeScript(jsCheck) ;Executes a Javascript on the webpage, mostly used for buttons.
; Msgbox % "DescriptionInput: " DescriptionInput
if(StrLen(DescriptionInput) > 5)
break
}
*/
; Progress Percentage ; Progress Percentage
TooltipThis("Waiting for Video to Finish Uploading`nChecking Progress Every 5 seconds") TooltipThis("Waiting for Video to Finish Uploading`nChecking Progress Every 5 seconds")
; Xpath = //span[contains(text(),'Upload at')] ; Xpath = //span[contains(text(),'Upload at')]

Loading…
Cancel
Save