From 0042deb1f3a045f1ff11bd5815c809328764d9ce Mon Sep 17 00:00:00 2001 From: insert Date: Thu, 18 Jul 2024 07:27:56 -0400 Subject: [PATCH] add more error checking --- bot.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bot.py b/bot.py index 1b4aff1..ac5e270 100644 --- a/bot.py +++ b/bot.py @@ -35,8 +35,11 @@ async def on_ready(): def play_video(videourl): driver.get(videourl) sleep(4) - elem = driver.find_element(By.CLASS_NAME, "ytp-fullscreen-button") - elem.send_keys(Keys.RETURN) + try: + elem = driver.find_element(By.CLASS_NAME, "ytp-fullscreen-button") + 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 #sleep(1.5) #elem = driver.find_element(By.XPATH, '//button[@aria-keyshortcuts="k"]') @@ -52,7 +55,10 @@ def play_video(videourl): elem.send_keys(Keys.RETURN) except Exception: pass - endscreen = driver.find_element(By.CLASS_NAME, "html5-endscreen") + try: + endscreen = driver.find_element(By.CLASS_NAME, "html5-endscreen") + except Exception: + return #same as above while str(endscreen.get_attribute('style')) == "display: none;": pass sleep(2)