From 7800bd3639c46f675c098093c69c9f676cc02c85 Mon Sep 17 00:00:00 2001 From: Terry Geng Date: Thu, 27 Feb 2020 09:58:49 +0800 Subject: [PATCH] fix: random will not delete current song. changed one-shot icon.#79 --- command.py | 9 ++++----- interface.py | 9 ++++----- media/playlist.py | 2 +- mumbleBot.py | 4 ++-- templates/index.html | 6 +----- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/command.py b/command.py index aa50bcf..4c59bd1 100644 --- a/command.py +++ b/command.py @@ -115,7 +115,7 @@ def cmd_play(bot, user, text, command, parameter): if var.playlist.length() > 0: if parameter is not None: if parameter.isdigit() and int(parameter) > 0 and int(parameter) <= len(var.playlist): - bot.kill_ffmpeg() + bot.interrupt_playing() bot.launch_music(int(parameter) - 1) else: bot.send_msg(constants.strings('invalid_index', index=parameter), text) @@ -540,14 +540,14 @@ def cmd_remove(bot, user, text, command, parameter): if index < len(var.playlist): if not bot.is_pause: - bot.kill_ffmpeg() + bot.interrupt_playing() var.playlist.current_index -= 1 # then the bot will move to next item else: # if item deleted is the last item of the queue var.playlist.current_index -= 1 if not bot.is_pause: - bot.kill_ffmpeg() + bot.interrupt_playing() else: removed = var.playlist.remove(index) @@ -606,9 +606,8 @@ def cmd_queue(bot, user, text, command, parameter): send_multi_lines(bot, msgs, text) def cmd_random(bot, user, text, command, parameter): - bot.stop() + bot.interrupt_playing() var.playlist.randomize() - bot.launch_music(0) def cmd_mode(bot, user, text, command, parameter): if not parameter: diff --git a/interface.py b/interface.py index b5ffb07..e811874 100644 --- a/interface.py +++ b/interface.py @@ -240,14 +240,14 @@ def post(): if index < len(var.playlist): if not var.botamusique.is_pause: - var.botamusique.kill_ffmpeg() + var.botamusique.interrupt_playing() var.playlist.current_index -= 1 # then the bot will move to next item else: # if item deleted is the last item of the queue var.playlist.current_index -= 1 if not var.botamusique.is_pause: - var.botamusique.kill_ffmpeg() + var.botamusique.interrupt_playing() else: var.playlist.remove(index) @@ -257,7 +257,7 @@ def post(): logging.info("web: jump to: " + util.format_debug_song_string(music)) if len(var.playlist) >= int(request.form['play_music']): - var.botamusique.kill_ffmpeg() + var.botamusique.interrupt_playing() var.botamusique.launch_music(int(request.form['play_music'])) elif 'delete_music_file' in request.form and ".." not in request.form['delete_music_file']: @@ -276,11 +276,10 @@ def post(): elif 'action' in request.form: action = request.form['action'] if action == "randomize": - var.botamusique.stop() + var.botamusique.interrupt_playing() var.playlist.set_mode("random") var.db.set('playlist', 'playback_mode', "random") logging.info("web: playback mode changed to random.") - var.botamusique.resume() if action == "one-shot": var.playlist.set_mode("one-shot") var.db.set('playlist', 'playback_mode', "one-shot") diff --git a/media/playlist.py b/media/playlist.py index 496452b..bfd278f 100644 --- a/media/playlist.py +++ b/media/playlist.py @@ -144,7 +144,7 @@ class PlayList(list): random.shuffle(self) #self.insert(0, current) - self.current_index = 0 + self.current_index = -1 self.version += 1 def clear(self): diff --git a/mumbleBot.py b/mumbleBot.py index 71bf713..ee76104 100644 --- a/mumbleBot.py +++ b/mumbleBot.py @@ -607,12 +607,12 @@ class MumbleBot: def stop(self): # stop and move to the next item in the playlist self.is_pause = True - self.kill_ffmpeg() + self.interrupt_playing() self.playhead = 0 var.playlist.next() logging.info("bot: music stopped.") - def kill_ffmpeg(self): + def interrupt_playing(self): # Kill the ffmpeg thread if self.thread: self.thread.kill() diff --git a/templates/index.html b/templates/index.html index 5a29f8e..d010a36 100644 --- a/templates/index.html +++ b/templates/index.html @@ -139,12 +139,8 @@