Skip to content

Commit

Permalink
player: fix next_song when the following songs are bad (#858)
Browse files Browse the repository at this point in the history
Before, next_song returns no song when the following songs are bad.
For example, the playlist has [valid_song1, valid_song2, bad_song1, bad_song2]
and the current song is valid_song2. At the this time, next_song
return None before. After this PR, next_song returns valid_song1.
  • Loading branch information
cosven authored Jul 28, 2024
1 parent 1f6496e commit 1eafc38
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 9 additions & 6 deletions feeluown/player/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,16 @@ def next_song(self):
next_song = self._get_good_song(random_=True)
else:
current_index = self._songs.index(self.current_song)
if current_index == len(self._songs) - 1:
if self.playback_mode in (PlaybackMode.loop, PlaybackMode.one_loop):
next_song = self._get_good_song()
elif self.playback_mode == PlaybackMode.sequential:
next_song = None
is_last_song = current_index == len(self._songs) - 1
if is_last_song and self.playback_mode == PlaybackMode.sequential:
next_song = None
else:
next_song = self._get_good_song(base=current_index+1, loop=False)
if is_last_song:
base_index = 0
else:
base_index = current_index + 1
loop = self.playback_mode != PlaybackMode.sequential
next_song = self._get_good_song(base=base_index, loop=loop)
return next_song

@property
Expand Down
7 changes: 7 additions & 0 deletions tests/player/test_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,10 @@ class Album:
# app_mock.library.album_upgrade.return_value = album
# When cover is a media object, prepare_metadata should also succeed.
await pl._metadata_mgr.prepare_for_song(ekaf_brief_song0)


def test_playlist_next_song(pl):
pl.mark_as_bad(pl.list()[1])
assert pl.next_song == pl.list()[0]
pl.playback_mode = PlaybackMode.sequential
assert pl.next_song is None

0 comments on commit 1eafc38

Please sign in to comment.