Compare commits
No commits in common. "ca886b1c71bacd26ee75c8d820a8b3d9705f0caf" and "03f2df68a51483b84cae520b634788b80f2e66db" have entirely different histories.
ca886b1c71
...
03f2df68a5
1 changed files with 3 additions and 32 deletions
35
bot.py
35
bot.py
|
@ -4,7 +4,6 @@ from selenium.webdriver.common.keys import Keys
|
|||
from selenium.webdriver.common.by import By
|
||||
from time import sleep
|
||||
import disnake
|
||||
import random
|
||||
from urllib.parse import urlparse
|
||||
from disnake.ext import commands
|
||||
from disnake import TextInputStyle
|
||||
|
@ -20,7 +19,6 @@ handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(me
|
|||
logger.addHandler(handler)
|
||||
|
||||
queue = []
|
||||
shuffle = False
|
||||
load_dotenv()
|
||||
options = Options()
|
||||
options.profile = webdriver.FirefoxProfile(os.getenv("PROFILE_PATH"))
|
||||
|
@ -37,11 +35,8 @@ async def on_ready():
|
|||
def play_video(videourl):
|
||||
driver.get(videourl)
|
||||
sleep(4)
|
||||
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
|
||||
elem = driver.find_element(By.CLASS_NAME, "ytp-fullscreen-button")
|
||||
elem.send_keys(Keys.RETURN)
|
||||
#guess I don't need this
|
||||
#sleep(1.5)
|
||||
#elem = driver.find_element(By.XPATH, '//button[@aria-keyshortcuts="k"]')
|
||||
|
@ -57,10 +52,7 @@ def play_video(videourl):
|
|||
elem.send_keys(Keys.RETURN)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
endscreen = driver.find_element(By.CLASS_NAME, "html5-endscreen")
|
||||
except Exception:
|
||||
return #same as above
|
||||
endscreen = driver.find_element(By.CLASS_NAME, "html5-endscreen")
|
||||
while str(endscreen.get_attribute('style')) == "display: none;":
|
||||
pass
|
||||
sleep(2)
|
||||
|
@ -83,23 +75,6 @@ async def play(inter: disnake.AppCmdInter, link: str):
|
|||
await inter.edit_original_response(f"This bot only accepts youtube links")
|
||||
return
|
||||
|
||||
@bot.slash_command(
|
||||
name="shuffle",
|
||||
description="toggles shuffle on or off, the queue cannot be unshuffled once it is shuffled",
|
||||
)
|
||||
async def shuffleplay(inter: disnake.AppCmdInter, toggle: str = commands.Param(choices=["on", "off"])):
|
||||
await inter.response.defer(ephemeral=True)
|
||||
if toggle == "on":
|
||||
global shuffle
|
||||
shuffle = True
|
||||
await inter.edit_original_response(f"shuffle enabled")
|
||||
return
|
||||
else:
|
||||
global shuffle
|
||||
shuffle = False
|
||||
await inter.edit_original_response(f"shuffle disabled")
|
||||
return
|
||||
|
||||
@bot.slash_command(
|
||||
name="queue",
|
||||
description="list the videos in queue",
|
||||
|
@ -163,11 +138,7 @@ async def remove(inter: disnake.AppCmdInter, toremove: int):
|
|||
|
||||
async def queuehandler():
|
||||
loop = asyncio.get_running_loop()
|
||||
global queue
|
||||
while queue:
|
||||
if shuffle:
|
||||
random.shuffle(queue)
|
||||
print(queue)
|
||||
driver.maximize_window()
|
||||
await loop.run_in_executor(None, play_video, queue[0])
|
||||
queue.pop(0)
|
||||
|
|
Loading…
Reference in a new issue