From 95af2f6c82409486aa8b98bb9d426865427b89a2 Mon Sep 17 00:00:00 2001 From: insert Date: Sun, 4 Aug 2024 12:33:31 -0400 Subject: [PATCH] further improvements to youtube handler --- bot.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/bot.py b/bot.py index ab4d63c..b93b570 100644 --- a/bot.py +++ b/bot.py @@ -3,6 +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 time import sleep import time import disnake @@ -51,19 +52,15 @@ def play_video(videourl): elem.send_keys(Keys.RETURN) except Exception: pass - #TODO: see if this is actually needed try: - elem = WebDriverWait(driver, 10, 0.2, (ElementNotVisibleException)).until(lambda x: x.find_element(By.XPATH, '//button[@aria-label="Dismiss"]').is_displayed()) + 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: - pass + except Exception as e: + print(e) try: - endscreen = driver.find_element(By.CLASS_NAME, "html5-endscreen") - timeout = (float(os.getenv("MAX_MIN")) * 60) + time.time() + 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: return #same as above - while str(endscreen.get_attribute('style')) == "display: none;" and time.time() < timeout: - pass sleep(1) return @@ -235,7 +232,6 @@ async def queuehandler(): random.shuffle(user_queue) print(queue) print(user_queue) - driver.maximize_window() await loop.run_in_executor(None, play_video, queue[0]) queue.pop(0) user_queue.pop(0)