diff --git a/bot.py b/bot.py index 2fa513e..b7e40d9 100644 --- a/bot.py +++ b/bot.py @@ -3,7 +3,7 @@ from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait -from selenium.common.exceptions import NoSuchElementException, ElementNotVisibleException +from selenium.common.exceptions import NoSuchElementException, ElementNotVisibleException, TimeoutException from time import sleep import time import disnake @@ -46,23 +46,24 @@ def play_video(videourl): elem = WebDriverWait(driver, 8, 0.2, None).until(lambda x: x.find_element(By.CLASS_NAME, "ytp-fullscreen-button")) sleep(1) elem.send_keys(Keys.RETURN) - except Exception as e: + except (NoSuchElementException,TimeoutException) as e: print(e) return #if this errors there is no fullscreen options, such as playlists, so skip the link try: elem = driver.find_element(By.XPATH, '//button[@data-tooltip-target-id="ytp-autonav-toggle-button"][@aria-label="Autoplay is on"]') elem.send_keys(Keys.RETURN) - except Exception: + except (NoSuchElementException,ElementNotVisibleException,TimeoutException): pass try: elem = WebDriverWait(driver, 5, 0.2, (NoSuchElementException,ElementNotVisibleException)).until(lambda x: x.find_element(By.XPATH, '//button[@aria-label="Dismiss"]')) elem.send_keys(Keys.RETURN) - except Exception as e: + except (NoSuchElementException,ElementNotVisibleException,TimeoutException) as e: print(e) try: elem = WebDriverWait(driver, (float(os.getenv("MAX_MIN")) * 60), 1, None).until(lambda x: x.find_element(By.CLASS_NAME, "html5-endscreen").is_displayed()) - except Exception as e: + except (NoSuchElementException,ElementNotVisibleException,TimeoutException) as e: print(e) + sleep(1) return #same as above sleep(1) return