Fix small edge cases
This commit is contained in:
parent
0aab1dffdd
commit
b765f8d1eb
1 changed files with 13 additions and 3 deletions
16
newbot.py
16
newbot.py
|
@ -32,7 +32,7 @@ queue = []
|
|||
user_queue = []
|
||||
skip_list = []
|
||||
shuffle = True
|
||||
downloading = False
|
||||
retries = 0
|
||||
failures = 0
|
||||
vidcounter = 0
|
||||
temp_dir = TemporaryDirectory()
|
||||
|
@ -119,19 +119,22 @@ async def on_ready():
|
|||
|
||||
|
||||
def download_video(index):
|
||||
global retries
|
||||
while len(os.listdir(full_dl_dir)) != 0:
|
||||
pass
|
||||
try:
|
||||
ydl.download(queue[index])
|
||||
retries = 0
|
||||
sleep(2) #allow ytdlp to fully cleanup
|
||||
except Exception:
|
||||
print("handling youtube exception")
|
||||
global failures
|
||||
if failures % 2 == 0:
|
||||
if retries % 2 == 0:
|
||||
queue.pop(index)
|
||||
if not (os.getenv("PERMANENT_MAX_QUEUE","FALSE") == "TRUE"):
|
||||
user_queue.pop(index)
|
||||
failures = failures + 1
|
||||
retries = retries + 1
|
||||
download_video(index)
|
||||
|
||||
|
||||
|
@ -171,7 +174,11 @@ def cold_run():
|
|||
|
||||
def on_media_input_playback_ended(data):
|
||||
global vidcounter
|
||||
queue.pop(0)
|
||||
try:
|
||||
queue.pop(0)
|
||||
except IndexError:
|
||||
print("Video ended but somehow it wasn't in the queue? Resetting")
|
||||
obs.set_current_program_scene("waiting")
|
||||
if not (os.getenv("PERMANENT_MAX_QUEUE","FALSE") == "TRUE"):
|
||||
user_queue.pop(0)
|
||||
skip_list.clear()
|
||||
|
@ -503,8 +510,11 @@ async def videotimer():
|
|||
#obs.trigger_media_input_action("player", "OBS_WEBSOCKET_MEDIA_INPUT_ACTION_PAUSE")
|
||||
os.remove(f"{vid_dir}/{vidcounter}.mp4")
|
||||
vidcounter = vidcounter + 1
|
||||
nowplayingid = obs.get_scene_item_id("youtube", "nowplaying")
|
||||
obs.set_input_settings("player", {'playlist': [{'hidden': False, 'selected': False, 'value': f"{str(vid_dir)}"}]}, True)
|
||||
obs.trigger_media_input_action("player", "OBS_WEBSOCKET_MEDIA_INPUT_ACTION_RESTART")
|
||||
obs.set_input_settings("nowplaying", {'text': f'{vid_details["title"]}\nBy {vid_details["channel"]}'}, True)
|
||||
obs.set_scene_item_enabled("youtube", nowplayingid.scene_item_id, True)
|
||||
if len(queue) > 1:
|
||||
await loop.run_in_executor(None, download_video, 1)
|
||||
os.rename(f"{vid_dir}/999zznext.mp4", f"{vid_dir}/{vidcounter+1}.mp4")
|
||||
|
|
Loading…
Reference in a new issue