You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
livestream-scheduler/Modules/Locals-Schedule.ahk

164 lines
6.8 KiB
Plaintext

5 months ago
LocalsSchedule:
;------------------------------------------------
CurrentSite := "Locals"
SaveOrPostProgress(Message:="Scheduling Post in Locals",PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
IniRead, LocalsPostPageURL, %SettingsIniFilepath%, General, LocalsPostPageURL, %A_Space%
if(LocalsPostPageURL = ""){
Message = LocalsPostPageURL is blank in Settings.ini. Please add the Locals server URL Under [General]`nLocalsPostPageURL=
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
Return
}
else {
; Reformat URL in case it has any extras we don't need.
LocalsPostPageURLArray := StrSplit(LocalsPostPageURL,".locals.com")
LocalsPostPageURL := LocalsPostPageURLArray[1] . ".locals.com/share?livestream"
}
Status := NavigateFromBaseURLTo(LocalsPostPageURL)
if(Status)
Return
try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
CheckForAlerts()
; Check Login Status on Locals
#Include, %A_ScriptDir%\Modules\Locals-Check-Login-Status.ahk
; Input Title and Description into Create a Livestream - First Screen
; ------------------------------------------------
Xpath = //input[@id='title']
; try, driver.FindElementByXPath(Xpath).SendKeys("TEST STRINGHERE")
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=LivestreamTitle)
Xpath = //textarea[@id='body']
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=LivestreamDescription)
; click next button
Xpath = //span[contains(text(),'Next')]
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
; Create a Livestream - Second Screen
; ------------------------------------------------
; check if "Schedule Livestream" checkbox is checked, check it if not
LivestreamScheduledCheckbox := driver.findElementByID("is_scheduled_livestream").isSelected() ;Checks if a checkbox is ticked or not and saves it to a variable, usually: 0 = Unchecked, -1 = Checked
if(LivestreamScheduledCheckbox = 0){
Xpath = //label[normalize-space()='Schedule this live stream?']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
LivestreamScheduledCheckbox := driver.findElementByID("is_scheduled_livestream").isSelected()
if(LivestreamScheduledCheckbox = 0){
Message = Failed to select the "Schedule Livestream" checkbox
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
}
}
; Make sure the "Notify Users" checkbox is checked
NotifyUsersCheckbox := driver.findElementByID("is_do_promo").isSelected() ;Checks if a checkbox is ticked or not and saves it to a variable, usually: 0 = Unchecked, -1 = Checked
if(NotifyUsersCheckbox = 0){
Xpath = //label[@for='is_do_promo']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
NotifyUsersCheckbox := driver.findElementByID("is_do_promo").isSelected()
if(NotifyUsersCheckbox = 0){
Message = Failed to select the "Notify Users" checkbox
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
}
}
FormatTime, LocalsLivestreamDate , %LivestreamDate%, MM/dd/yyyy ; _hhmmss
FormatTime, LocalsLivestreamTime , %LivestreamTime%, hh:mm tt ; _hhmmss
; clear data from date box and input date
Xpath = //input[@id='stream_schedule_date']
try, driver.FindElementByXPath(Xpath).SendKeys(driver.Keys.BackSpace).SendKeys(driver.Keys.BackSpace).SendKeys(driver.Keys.BackSpace).SendKeys(driver.Keys.BackSpace).SendKeys(driver.Keys.BackSpace).SendKeys(driver.Keys.BackSpace).SendKeys(driver.Keys.BackSpace).SendKeys(driver.Keys.BackSpace).SendKeys(driver.Keys.BackSpace).SendKeys(driver.Keys.BackSpace)
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=LocalsLivestreamDate)
; clear data from time box and input time
Xpath = //input[@id='stream_schedule_time']
try, driver.FindElementByXPath(Xpath).SendKeys(driver.Keys.BackSpace).SendKeys(driver.Keys.BackSpace).SendKeys(driver.Keys.BackSpace).SendKeys(driver.Keys.BackSpace).SendKeys(driver.Keys.BackSpace).SendKeys(driver.Keys.BackSpace).SendKeys(driver.Keys.BackSpace).SendKeys(driver.Keys.BackSpace).SendKeys(driver.Keys.BackSpace).SendKeys(driver.Keys.BackSpace)
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=LocalsLivestreamTime)
; click schedule button
Xpath = //span[normalize-space()='Schedule']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
if(Status){
Message = Failed to click schedule post button
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
}
LivestreamURL := GrabLocalsPostURLUsingTitle(LivestreamTitle)
if(!InStr(LivestreamURL, "https")){
; If url was not grabbed. wait 1 minute, reload page and then try grabbing URL again
; @todo
}
; Navigate to the post
Message = Navigating to Livestream Page to grab RTMP Settings
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
try, driver.Get(LivestreamURL) ;Open selected URL
driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding
; Switch to RSTP mode
Xpath = //a[normalize-space()='switch to RTMP']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
if(Status){
Message = Failed to switch Livestream to RTMP mode
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
}
; Open Stream Settings Popup Window
Xpath = //button[normalize-space()='Stream Settings']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
; Get RTMP Values from the popup
Xpath = //input[@id='rtmp_url']
try, LocalsRTMPURL := driver.findelementbyxpath(Xpath).Attribute("value")
/*Xpath = //div[@class='modal-wrapper modal-wrapper_stream']//div[5]
try, LocalsRTMPKey := driver.findelementbyxpath(Xpath).Attribute("value")
*/
Xpath = //div[@class='modal-wrapper modal-wrapper_stream']//div[5]
; Try ElementOuterHTML := driver.findelementbyxpath(Xpath).Attribute("outerHTML") ;XPATH-ID & Tag
; Pull Out the RTMPKey from the OuterHTML using RegEx
RTMPKey := GetHTMLValueFromXpathOuterHTML(XPATH, "value")
Msgbox % "RTMPKey: " RTMPKey
/*
regexMatch := RegExMatch(ElementOuterHTML, "value=""([^""]+)""", match)
if (regexMatch)
{
LocalsRTMPKey := match1
}
else {
Message = Failed to Pull out RTMPKey from OuterHTML of RTMPKey Element
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
}
*/
; Msgbox % "LocalsRTMPURL: " LocalsRTMPURL
; Msgbox % "LocalsRTMPKey: " LocalsRTMPKey
Return