add more error checking

This commit is contained in:
insert 2024-07-18 07:27:56 -04:00
parent 03f2df68a5
commit 0042deb1f3
Signed by: insert
GPG key ID: A70775C389ACF105

12
bot.py
View file

@ -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)