]> git.0d.be Git - botaradio.git/commitdiff
fix: delete file if ffmpeg failed
authorTerry Geng <gengyanda@gmail.com>
Tue, 10 Mar 2020 14:59:52 +0000 (22:59 +0800)
committerTerry Geng <gengyanda@gmail.com>
Tue, 10 Mar 2020 14:59:52 +0000 (22:59 +0800)
configuration.default.ini
mumbleBot.py

index e42117c03d378697c86753ab87b24fd1f0c6d571..b549c522c2d095df3a1ddf3edc00fc3b8b1ba810 100644 (file)
@@ -198,6 +198,7 @@ multiple_file_found  = Found:
 bad_url = Bad URL requested.
 preconfigurated_radio = Preconfigurated Radio available:
 unable_download = Error while downloading music...
+unable_play = Unable to play {item}. Removed from the library.
 which_command = Do you mean <br /> {commands}
 multiple_matches = File not found! Possible candidates:
 queue_contents = Items on the playlist:
index 17b1bf69860b34e1140431923a22e34f6d626979..0ae9e424a877ffba3b22f1cdd9ad5b27cf801053 100644 (file)
@@ -72,6 +72,8 @@ class MumbleBot:
         self.pause_at_id = ""
         self.playhead = -1
         self.song_start_at = -1
+        self.last_ffmpeg_err = ""
+        self.read_pcm_size = 0
         #self.download_threads = []
         self.wait_for_downloading = False # flag for the loop are waiting for download to complete in the other thread
 
@@ -343,6 +345,7 @@ class MumbleBot:
         self.thread_stderr = os.fdopen(pipe_rd)
         self.thread = sp.Popen(command, stdout=sp.PIPE, stderr=pipe_wd, bufsize=480)
         self.is_pause = False
+        self.read_pcm_size = 0
         self.song_start_at = -1
         self.playhead = 0
         self.last_volume_cycle_time = time.time()
@@ -388,11 +391,12 @@ class MumbleBot:
                 self.playhead = time.time() - self.song_start_at
 
                 raw_music = self.thread.stdout.read(480)
+                self.read_pcm_size += 480
 
                 try:
-                    stderr_msg = self.thread_stderr.readline()
-                    if stderr_msg:
-                        self.log.debug("ffmpeg: " + stderr_msg.strip("\n"))
+                    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
 
@@ -407,7 +411,19 @@ class MumbleBot:
                 time.sleep(0.1)
 
             if not self.is_pause and (self.thread is None or not raw_music):
-                # ffmpeg thread has gone. indicate that last song has finished. move to the next song.
+                # ffmpeg thread has gone. indicate that last song has finished, or something is wrong.
+                if self.read_pcm_size < 481 and len(var.playlist) > 0 and var.playlist.current_index != -1:
+                    current = var.playlist.current_item()
+                    self.log.error("bot: cannot play music %s", current.format_debug_string())
+                    if self.last_ffmpeg_err:
+                        self.log.error("bot: with ffmpeg error: %s", self.last_ffmpeg_err)
+                        self.last_ffmpeg_err = ""
+
+                self.send_msg(constants.strings('unable', item=current.format_short_string()))
+                var.playlist.remove_by_id(current.id)
+                var.cache.free_and_delete(current.id)
+
+                # move to the next song.
                 if not self.wait_for_downloading:
                     if var.playlist.next():
                         current = var.playlist.current_item()