diff --git a/command.py b/command.py index dc71689..aa50bcf 100644 --- a/command.py +++ b/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: diff --git a/configuration.default.ini b/configuration.default.ini index be14edc..66df190 100644 --- a/configuration.default.ini +++ b/configuration.default.ini @@ -170,6 +170,7 @@ which_command = Do you mean
{commands} multiple_matches = Track not found! Possible candidates: queue_contents = Items on the playlist: queue_empty = Playlist is empty! +invalid_index = Invalid index {index}. Use '!queue' to see your playlist. now_playing = Now playing {item}
{thumb} not_in_my_channel = You're not in my channel, command refused! pm_not_allowed = Private message aren't allowed. diff --git a/interface.py b/interface.py index 1d07034..b5ffb07 100644 --- a/interface.py +++ b/interface.py @@ -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']: diff --git a/media/playlist.py b/media/playlist.py index 7074e55..496452b 100644 --- a/media/playlist.py +++ b/media/playlist.py @@ -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 = [] diff --git a/mumbleBot.py b/mumbleBot.py index 2418bf1..71bf713 100644 --- a/mumbleBot.py +++ b/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()