fix: random will not delete current song. changed one-shot icon.#79

This commit is contained in:
Terry Geng 2020-02-27 09:58:49 +08:00
parent 020ddbca22
commit 7800bd3639
5 changed files with 12 additions and 18 deletions

View File

@ -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:

View File

@ -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")

View File

@ -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):

View File

@ -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()

View File

@ -139,12 +139,8 @@
<div class="btn-group" style="float: right;">
<button type="button" id="oneshot-btn" class="btn btn-primary btn-space"
title="One-shot Playlist"
style="height: 38px; width: 45px"
onclick="request('post', {action : 'one-shot'})">
<span class="fa-stack" style="font-size: 0.9em; margin-left:-8px; margin-top:-2px;">
<i class="fas fa-slash fa-stack-1x"></i>
<i class="fas fa-redo fa-stack-1x"></i>
</span>
<i class="fas fa-tasks" aria-hidden="true"></i>
</button>
<button type="button" id="random-btn" class="btn btn-primary btn-space"