add more error checking

This commit is contained in:
insert 2024-07-18 07:27:56 -04:00
parent 03f2df68a5
commit 0042deb1f3
Signed by: insert
GPG key ID: A70775C389ACF105

6
bot.py
View file

@ -35,8 +35,11 @@ async def on_ready():
def play_video(videourl): def play_video(videourl):
driver.get(videourl) driver.get(videourl)
sleep(4) sleep(4)
try:
elem = driver.find_element(By.CLASS_NAME, "ytp-fullscreen-button") elem = driver.find_element(By.CLASS_NAME, "ytp-fullscreen-button")
elem.send_keys(Keys.RETURN) elem.send_keys(Keys.RETURN)
except Exception:
return #if this errors there is no fullscreen options, such as playlists, so skip the link
#guess I don't need this #guess I don't need this
#sleep(1.5) #sleep(1.5)
#elem = driver.find_element(By.XPATH, '//button[@aria-keyshortcuts="k"]') #elem = driver.find_element(By.XPATH, '//button[@aria-keyshortcuts="k"]')
@ -52,7 +55,10 @@ def play_video(videourl):
elem.send_keys(Keys.RETURN) elem.send_keys(Keys.RETURN)
except Exception: except Exception:
pass pass
try:
endscreen = driver.find_element(By.CLASS_NAME, "html5-endscreen") endscreen = driver.find_element(By.CLASS_NAME, "html5-endscreen")
except Exception:
return #same as above
while str(endscreen.get_attribute('style')) == "display: none;": while str(endscreen.get_attribute('style')) == "display: none;":
pass pass
sleep(2) sleep(2)