further improvements to youtube handler
This commit is contained in:
parent
689629aa37
commit
95af2f6c82
1 changed files with 5 additions and 9 deletions
14
bot.py
14
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)
|
||||
|
|
Loading…
Reference in a new issue