further improvements to youtube handler

This commit is contained in:
insert 2024-08-04 12:33:31 -04:00
parent 689629aa37
commit 95af2f6c82
Signed by: insert
GPG key ID: A70775C389ACF105

14
bot.py
View file

@ -3,6 +3,7 @@ from selenium import webdriver
from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support.wait import WebDriverWait
from selenium.common.exceptions import NoSuchElementException, ElementNotVisibleException
from time import sleep from time import sleep
import time import time
import disnake import disnake
@ -51,19 +52,15 @@ def play_video(videourl):
elem.send_keys(Keys.RETURN) elem.send_keys(Keys.RETURN)
except Exception: except Exception:
pass pass
#TODO: see if this is actually needed
try: 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) elem.send_keys(Keys.RETURN)
except Exception: except Exception as e:
pass print(e)
try: try:
endscreen = driver.find_element(By.CLASS_NAME, "html5-endscreen") elem = WebDriverWait(driver, (float(os.getenv("MAX_MIN")) * 60), 1, None).until(lambda x: x.find_element(By.CLASS_NAME, "html5-endscreen").is_displayed())
timeout = (float(os.getenv("MAX_MIN")) * 60) + time.time()
except Exception: except Exception:
return #same as above return #same as above
while str(endscreen.get_attribute('style')) == "display: none;" and time.time() < timeout:
pass
sleep(1) sleep(1)
return return
@ -235,7 +232,6 @@ async def queuehandler():
random.shuffle(user_queue) random.shuffle(user_queue)
print(queue) print(queue)
print(user_queue) print(user_queue)
driver.maximize_window()
await loop.run_in_executor(None, play_video, queue[0]) await loop.run_in_executor(None, play_video, queue[0])
queue.pop(0) queue.pop(0)
user_queue.pop(0) user_queue.pop(0)