def next(self, playlist, iter): next_fallback = OrderInOrder.next(self, playlist, iter) OrderRemembered.next(self, playlist, iter) selected = app.window.songlist.get_selected_songs() if not selected: return next_fallback selected_iter = playlist.find(selected[0]) selected_path = playlist.get_path(selected_iter) current_path = iter and playlist.get_path(iter) if selected_path in (current_path, self.__last_path): return next_fallback self.__last_path = selected_path return selected_iter
def _next(self, playlist, current_song, delay_on=True): grouping = str(pconfig.gettext("grouping")).strip() grouping_filter = str(pconfig.gettext("grouping_filter")).strip() delay = pconfig.getint("delay") def same_group(song_iter_a, song_iter_b): if song_iter_a is None or song_iter_b is None: return False song_a = playlist.get_value(song_iter_a) song_b = playlist.get_value(song_iter_b) if not self._tag_defined(grouping_filter, song_a): return False if not self._tag_defined(grouping_filter, song_b): return False return song_a(grouping) == song_b(grouping) # Keep track of played songs OrderRemembered.next(self, playlist, current_song) remaining = OrderRemembered.remaining(self, playlist) # Check if playlist is finished or empty if not remaining: OrderRemembered.reset(self, playlist) return None # Play next song in current grouping next_song = OrderInOrder.next(self, playlist, current_song) if same_group(next_song, current_song): return next_song # Pause for a moment before picking new group if delay_on: self._resume_after_delay(delay) # Pick random song at the start of a new group while True: song_location = random.choice(list(remaining.keys())) new_song = playlist.get_iter(song_location) new_song_prev = (playlist.get_iter(song_location - 1) if song_location >= 1 else None) if not same_group(new_song, new_song_prev): return new_song