Stop playback on ffmpeg HTTP 404

This commit is contained in:
Storm Dragon
2026-06-14 01:45:18 -04:00
parent c310a1c318
commit e2df8972e7
2 changed files with 129 additions and 9 deletions
+46 -9
View File
@@ -66,6 +66,7 @@ class MumbleBot:
self.read_pcm_size = 0
self.pcm_buffer_size = 0
self.last_ffmpeg_err = ""
self.ffmpeg_fatal_error = ""
# Play/pause status
self.is_pause = False
@@ -528,13 +529,51 @@ class MumbleBot:
# The ffmpeg process is a thread
# prepare pipe for catching stderr of ffmpeg
if self.redirect_ffmpeg_log:
pipe_rd, pipe_wd = util.pipe_no_wait() # Let the pipe work in non-blocking mode
pipe_rd, pipe_wd = util.pipe_no_wait() # Let the pipe work in non-blocking mode
if pipe_rd is not None:
self.thread_stderr = os.fdopen(pipe_rd)
else:
pipe_rd, pipe_wd = None, None
self.thread = sp.Popen(command, stdout=sp.PIPE, stderr=pipe_wd, bufsize=self.pcm_buffer_size)
if pipe_wd is not None:
os.close(pipe_wd)
def _read_ffmpeg_stderr(self):
if not self.thread_stderr:
return
while True:
try:
line = self.thread_stderr.readline()
except (BlockingIOError, OSError):
return
if not line:
return
self.last_ffmpeg_err = line
stripped_line = line.strip("\n")
if self.redirect_ffmpeg_log:
self.log.debug("ffmpeg: " + stripped_line)
if "HTTP error 404" in line or "404 Not Found" in line:
self.ffmpeg_fatal_error = stripped_line
def _fail_current_ffmpeg_item(self):
current = var.playlist.current_item()
self._cleanup_ffmpeg_process()
self.last_ffmpeg_err = ""
if not current:
return
self.log.error("bot: cannot play music %s", current.format_debug_string())
self.log.error("bot: with ffmpeg error: %s", self.ffmpeg_fatal_error)
self.ffmpeg_fatal_error = ""
self.send_channel_msg(tr('unable_play', item=current.format_title()))
var.playlist.remove_by_id(current.id)
var.cache.free_and_delete(current.id)
def async_download_next(self):
# Function start if the next music isn't ready
@@ -616,13 +655,11 @@ class MumbleBot:
raw_music = self.thread.stdout.read(self.pcm_buffer_size)
self.read_pcm_size += len(raw_music)
if self.redirect_ffmpeg_log:
try:
self.last_ffmpeg_err = self.thread_stderr.readline()
if self.last_ffmpeg_err:
self.log.debug("ffmpeg: " + self.last_ffmpeg_err.strip("\n"))
except:
pass
self._read_ffmpeg_stderr()
if self.ffmpeg_fatal_error:
self._fail_current_ffmpeg_item()
raw_music = None
continue
if raw_music:
# Adjust the volume and send it to mumble