From 8d63c013fb9dd06c277563e7226779c3c6fb86e2 Mon Sep 17 00:00:00 2001 From: insert Date: Sat, 25 Jan 2025 10:48:40 -0500 Subject: [PATCH] Only require one video to start playback --- newbot.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/newbot.py b/newbot.py index 135ab9b..f8dbb77 100644 --- a/newbot.py +++ b/newbot.py @@ -79,7 +79,7 @@ def propagate_queue(times): res = cur.execute(f"SELECT ROWID,link FROM queue WHERE hasplayed = false " + ("ORDER BY RANDOM() " if shuffle else "") + f"LIMIT {times}") for rowid,link in res.fetchall(): if len(queue) == 2: - print("the queue is already propagated refusing to evaluate!") + print("the queue is already propagated, exiting early") return elif len(queue) > 2: print(f"The queue is larger than two videos this WILL cause issues: {queue}") @@ -235,13 +235,15 @@ def on_media_input_playback_ended(data): global vidcounter try: queue.pop(0) - propagate_queue(1) + propagate_queue(2) except IndexError as e: print(f"Video ended but somehow it wasn't in the queue? Resetting {e}") obs.set_current_program_scene("waiting") skip_list.clear() if not queue: + print("queue is now empty") if sqllen() >= 1: + print("alternative download triggered") propagate_queue(2) download_video(0) #will be noticeably slow but this should not happen os.rename(f"{vid_dir}/999zznext.mp4", f"{vid_dir}/{vidcounter+1}.mp4") @@ -318,12 +320,17 @@ async def play(inter: disnake.AppCmdInter, link: str): """) con.commit() await inter.edit_original_response(f"added to queue!") - if (not os.path.isfile(f"{vid_dir}/{vidcounter}.mp4")) and sqllen() > 1 and len(queue) == 0: + scene = obs.get_current_program_scene() + if (not os.path.isfile(f"{vid_dir}/{vidcounter}.mp4")) and scene.scene_name == "waiting" and sqllen() >= 1 and len(queue) == 0: loop = asyncio.get_running_loop() - queue.clear() #safety + #queue.clear() #safety propagate_queue(2) - print(queue) await loop.run_in_executor(None, cold_run) + elif (not os.path.isfile(f"{vid_dir}/{vidcounter+1}.mp4")) and sqllen() >= 1 and len(queue) == 1: + loop = asyncio.get_running_loop() + propagate_queue(2) + await loop.run_in_executor(None, download_video, 1) + os.rename(f"{vid_dir}/999zznext.mp4", f"{vid_dir}/{vidcounter+1}.mp4") return else: await inter.edit_original_response(f"This bot only accepts youtube links") @@ -613,6 +620,7 @@ async def ensurewaiting(): loop = asyncio.get_running_loop() propagate_queue(2) await loop.run_in_executor(None, download_video, 0) + obs.set_current_program_scene("youtube") @tasks.loop(seconds=5) async def titlehandler():