fix: 'jump' now remove files behind in one-shot mode. #79
This commit is contained in:
parent
5491f00c34
commit
020ddbca22
11
command.py
11
command.py
@ -113,10 +113,13 @@ def cmd_url_unban(bot, user, text, command, parameter):
|
||||
|
||||
def cmd_play(bot, user, text, command, parameter):
|
||||
if var.playlist.length() > 0:
|
||||
if parameter is not None and parameter.isdigit() and int(parameter) > 0 \
|
||||
and int(parameter) <= len(var.playlist):
|
||||
bot.stop()
|
||||
bot.launch_music(int(parameter) - 1)
|
||||
if parameter is not None:
|
||||
if parameter.isdigit() and int(parameter) > 0 and int(parameter) <= len(var.playlist):
|
||||
bot.kill_ffmpeg()
|
||||
bot.launch_music(int(parameter) - 1)
|
||||
else:
|
||||
bot.send_msg(constants.strings('invalid_index', index=parameter), text)
|
||||
|
||||
elif bot.is_pause:
|
||||
bot.resume()
|
||||
else:
|
||||
|
@ -170,6 +170,7 @@ which_command = Do you mean <br /> {commands}
|
||||
multiple_matches = Track not found! Possible candidates:
|
||||
queue_contents = Items on the playlist:
|
||||
queue_empty = Playlist is empty!
|
||||
invalid_index = Invalid index <i>{index}</i>. Use '!queue' to see your playlist.
|
||||
now_playing = Now playing {item}<br />{thumb}
|
||||
not_in_my_channel = You're not in my channel, command refused!
|
||||
pm_not_allowed = Private message aren't allowed.
|
||||
|
@ -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.stop()
|
||||
var.botamusique.kill_ffmpeg()
|
||||
var.botamusique.launch_music(int(request.form['play_music']))
|
||||
|
||||
elif 'delete_music_file' in request.form and ".." not in request.form['delete_music_file']:
|
||||
|
@ -18,6 +18,10 @@ class PlayList(list):
|
||||
self.mode = mode
|
||||
if mode == "random":
|
||||
self.randomize()
|
||||
if mode == "one-shot" and self.current_index > 0:
|
||||
for i in range(self.current_index):
|
||||
super().__delitem__(0)
|
||||
self.current_index = 0
|
||||
|
||||
def append(self, item):
|
||||
self.version += 1
|
||||
@ -122,9 +126,15 @@ class PlayList(list):
|
||||
return self[self.next_index()]
|
||||
|
||||
def jump(self, index):
|
||||
if self.mode == "one-shot":
|
||||
for i in range(index):
|
||||
super().__delitem__(0)
|
||||
self.current_index = 0
|
||||
else:
|
||||
self.current_index = index
|
||||
|
||||
self.version += 1
|
||||
self.current_index = index
|
||||
return self[index]
|
||||
return self[self.current_index]
|
||||
|
||||
def randomize(self):
|
||||
# current_index will lose track after shuffling, thus we take current music out before shuffling
|
||||
@ -158,6 +168,15 @@ class PlayList(list):
|
||||
self.extend(list(map(lambda v: json.loads(v[1]), items)))
|
||||
self.current_index = current_index
|
||||
|
||||
def _debug_print(self):
|
||||
print("===== Playlist(%d) ====" % self.current_index)
|
||||
for index, item in enumerate(self):
|
||||
if index == self.current_index:
|
||||
print("-> %d %s" % (index, item['title']))
|
||||
else:
|
||||
print("%d %s" % (index, item['title']))
|
||||
print("===== End ====")
|
||||
|
||||
|
||||
def get_playlist_info(url, start_index=0, user=""):
|
||||
items = []
|
||||
|
10
mumbleBot.py
10
mumbleBot.py
@ -752,6 +752,12 @@ if __name__ == '__main__':
|
||||
var.botamusique = MumbleBot(args)
|
||||
command.register_all_commands(var.botamusique)
|
||||
|
||||
# load playlist
|
||||
if var.config.getboolean('bot', 'save_playlist', fallback=True):
|
||||
logging.info("bot: load playlist from previous session")
|
||||
var.playlist.load()
|
||||
|
||||
# load playback mode
|
||||
playback_mode = None
|
||||
if var.db.has_option("playlist", "playback_mode"):
|
||||
playback_mode = var.db.get('playlist', 'playback_mode')
|
||||
@ -761,9 +767,5 @@ if __name__ == '__main__':
|
||||
if playback_mode in ["one-shot", "repeat", "random"]:
|
||||
var.playlist.set_mode(playback_mode)
|
||||
|
||||
if var.config.getboolean('bot', 'save_playlist', fallback=True):
|
||||
logging.info("bot: load playlist from previous session")
|
||||
var.playlist.load()
|
||||
|
||||
# Start the main loop.
|
||||
var.botamusique.loop()
|
||||
|
Loading…
x
Reference in New Issue
Block a user