RumbleSetRTMP:
;------------------------------------------------


CurrentSite := "Rumble Studio"

Status := NavigateFromBaseURLTo("https://studio.rumble.com/settings/connections")
if(Status)
Return

try driver.executeScript("return document.readyState").equals("complete") ; wait until page loads completely before proceeding

CheckForAlerts()

Message = Inputting Custom RTMP Settings into Rumble Studio
SaveOrPostProgress(Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")


IniRead, LocalsRTMPURL, %PostStatusesFilepath%, Livestream,LocalsRTMPURL, %A_Space%
IniRead, LocalsRTMPKey, %PostStatusesFilepath%, Livestream,LocalsRTMPKey, %A_Space%

IniRead, OdyseeRTMPKey, %PostStatusesFilepath%, Livestream,OdyseeRTMPKey, %A_Space%
IniRead, OdyseeRTMPURL, %PostStatusesFilepath%, Livestream,OdyseeRTMPURL, %A_Space%


if(LocalsRTMPURL = ""){
	Message = Skipping. No LocalsRTMPURL in Status.ini file
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	Return
}

if(OdyseeRTMPURL = ""){
	Message = Skipping. No OdyseeRTMPURL in Status.ini file
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	Return
}



Loop, 10 {

	; IndexPlusOne := A_index + 1
	IndexMinusOne := A_index - 1
	Xpath = (//div[@class='flex shrink-0 items-center gap-x-4'])[%A_index%]
	XpathCheckbox = (//img[@alt='More options'])[%IndexMinusOne%]


	try SecondaryPlatformCheckboxName := driver.findelementbyxpath(Xpath).Attribute("innerText") ;XPATH Inner Text

	if(SecondaryPlatformCheckboxName = "LOCALS RTMP USE" OR SecondaryPlatformCheckboxName = "ODYSEE RTMP"){

		if(SecondaryPlatformCheckboxName = "LOCALS RTMP USE"){
			SiteRTMPURL := LocalsRTMPURL
			SiteRTMPKey := LocalsRTMPKey
		}

		if(SecondaryPlatformCheckboxName = "ODYSEE RTMP"){
			SiteRTMPURL :=  OdyseeRTMPURL
			SiteRTMPKey := OdyseeRTMPKey
		}

		Status := Selenium_LoopToClickXpath(Xpath:=XpathCheckbox,NumOfLoops:=2,SleepLength:=1000)
		if(Status){
			Message = Failed to click into 3 dot menu for %SecondaryPlatformCheckboxName%
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			Return
		}

		; click Edit RTMP in the popup menu
		Xpath = (//span[normalize-space()='Edit RTMP'])[1]
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
		if(Status){
			Message = Failed to click into 3 dot menu for %SecondaryPlatformCheckboxName%
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		}


		; Input New RTMP Info
		XpathRTMP = (//input[@placeholder='Enter the RTMP URL'])[1]
		XpathStreamkey = (//input[@placeholder='Enter the stream key'])[1] 

		Status := Selenium_LoopToSendValueToXpath(Xpath:=XpathRTMP,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=SiteRTMPURL,ClearElement:=1)
		Status := Selenium_LoopToSendValueToXpath(Xpath:=XpathStreamkey,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=SiteRTMPKey,ClearElement:=1)

		; click save button
		Xpath = (//button[@class='rounded-full block px-6 py-2 bg-primary hover:brightness-[0.92] cursor-pointer'])[1]
		Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
		if(Status){
			Message = Failed to Click Save Button for %SecondaryPlatformCheckboxName% modified RMTP Settings
			SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
			Return
		}
		break
	}
}

RumbleCustomRTMPs := "Success"
IniWrite, %RumbleCustomRTMPs%, %PostStatusesFilepath%, Livestream,RumbleCustomRTMPs
