fix small edge cases

This commit is contained in:
insert 2024-12-07 11:15:18 -05:00
parent d0b976f784
commit 9f2ab61ee7
Signed by: insert
GPG key ID: A70775C389ACF105

View file

@ -51,11 +51,15 @@ def sqllen():
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:
if len(queue) == 2:
print("the queue is already propagated refusing to evaluate!")
return
elif len(queue) > 2:
print(f"The queue is larger than two videos this WILL cause issues: {queue}")
return
queue.append(link)
cur.execute(f"UPDATE queue SET hasplayed = true WHERE ROWID='{rowid}'")
print("Updated a line!!")
print(f"added {link} to queue")
con.commit()
def video_check(info, *, incomplete):
@ -202,10 +206,15 @@ def on_media_input_playback_ended(data):
obs.set_current_program_scene("waiting")
skip_list.clear()
if not queue:
obs.set_current_program_scene("waiting")
os.remove(f"{vid_dir}/{vidcounter}.mp4")
vidcounter = vidcounter + 1
return
if sqllen() >= 1:
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")
else:
obs.set_current_program_scene("waiting")
os.remove(f"{vid_dir}/{vidcounter}.mp4")
vidcounter = vidcounter + 1
return
wait_for_next_video()
print(queue)
#obs.set_current_program_scene("youtube2")
@ -227,7 +236,10 @@ def on_media_input_playback_ended(data):
if len(queue) > 1:
download_video(1)
os.rename(f"{vid_dir}/999zznext.mp4", f"{vid_dir}/{vidcounter+1}.mp4")
elif sqllen() >= 1 and len(queue) == 1:
propagate_queue(1)
download_video(1)
os.rename(f"{vid_dir}/999zznext.mp4", f"{vid_dir}/{vidcounter+1}.mp4")
@bot.slash_command(
name="stats",
@ -265,7 +277,7 @@ async def play(inter: disnake.AppCmdInter, link: str):
if countuser(inter.user.id) >= (int(os.getenv("MAX_QUEUE"))):
await inter.edit_original_response(f"You have reached the queue limit of {os.getenv('MAX_QUEUE')}, " + ("try again after one of your videos has played." if not (os.getenv("PERMANENT_MAX_QUEUE","FALSE") == "TRUE") else "you may not queue videos for the rest of the session."))
return
if urlparse(link).netloc == 'youtube.com' or urlparse(link).netloc == 'www.youtube.com' or urlparse(link).netloc == 'youtu.be':
if (urlparse(link).netloc == 'youtube.com' or urlparse(link).netloc == 'www.youtube.com' or urlparse(link).netloc == 'youtu.be') and urlparse(link).scheme == 'https':
cur.execute(f"""INSERT INTO queue VALUES
('{link}',{inter.user.id},false)
""")