Drastic optimizations to youtube player
This commit is contained in:
parent
cb37e1c7b6
commit
689629aa37
1 changed files with 7 additions and 10 deletions
17
bot.py
17
bot.py
|
@ -2,6 +2,7 @@ from selenium.webdriver.firefox.options import Options
|
||||||
from selenium import webdriver
|
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 time import sleep
|
from time import sleep
|
||||||
import time
|
import time
|
||||||
import disnake
|
import disnake
|
||||||
|
@ -39,35 +40,31 @@ async def on_ready():
|
||||||
|
|
||||||
def play_video(videourl):
|
def play_video(videourl):
|
||||||
driver.get(videourl)
|
driver.get(videourl)
|
||||||
sleep(4)
|
|
||||||
try:
|
try:
|
||||||
elem = driver.find_element(By.CLASS_NAME, "ytp-fullscreen-button")
|
elem = WebDriverWait(driver, 5, 0.2, None).until(lambda x: x.find_element(By.CLASS_NAME, "ytp-fullscreen-button"))
|
||||||
|
sleep(1)
|
||||||
elem.send_keys(Keys.RETURN)
|
elem.send_keys(Keys.RETURN)
|
||||||
except Exception:
|
except Exception:
|
||||||
return #if this errors there is no fullscreen options, such as playlists, so skip the link
|
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"]')
|
|
||||||
#elem.send_keys(Keys.RETURN)
|
|
||||||
try:
|
try:
|
||||||
elem = driver.find_element(By.XPATH, '//button[@data-tooltip-target-id="ytp-autonav-toggle-button"][@aria-label="Autoplay is on"]')
|
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)
|
elem.send_keys(Keys.RETURN)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
sleep(10)
|
#TODO: see if this is actually needed
|
||||||
try:
|
try:
|
||||||
elem = driver.find_element(By.XPATH, '//button[@aria-label="Dismiss"]')
|
elem = WebDriverWait(driver, 10, 0.2, (ElementNotVisibleException)).until(lambda x: x.find_element(By.XPATH, '//button[@aria-label="Dismiss"]').is_displayed())
|
||||||
elem.send_keys(Keys.RETURN)
|
elem.send_keys(Keys.RETURN)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
endscreen = driver.find_element(By.CLASS_NAME, "html5-endscreen")
|
endscreen = driver.find_element(By.CLASS_NAME, "html5-endscreen")
|
||||||
timeout = (float(os.getenv("MAX_MIN")) * 60) + time.time() - 10 #subtract 10 since 10 seconds of the video has played by this point
|
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:
|
while str(endscreen.get_attribute('style')) == "display: none;" and time.time() < timeout:
|
||||||
pass
|
pass
|
||||||
sleep(2)
|
sleep(1)
|
||||||
return
|
return
|
||||||
|
|
||||||
@bot.slash_command(
|
@bot.slash_command(
|
||||||
|
|
Loading…
Reference in a new issue