diff --git a/python_payload/apps/mp3_player/__init__.py b/python_payload/apps/mp3_player/__init__.py index 869e6c74ce82dd4a81a27fb658eac9c3a066ce66..f21ba54abae5e0692bd8e0b1652c521a27d67269 100644 --- a/python_payload/apps/mp3_player/__init__.py +++ b/python_payload/apps/mp3_player/__init__.py @@ -18,6 +18,8 @@ PETAL_C = 5 PETAL_D = 7 PETAL_E = 9 +PLAYLIST_MAX_LEN = 1000 + # taken from https://github.com/python/cpython/blob/main/Lib/bisect.py # Copyright (c) 2001-2024 Python Software Foundation; All Rights Reserved @@ -417,14 +419,24 @@ class ArtistsPage(NotPlaylistPage): artist = self.highlighted_item.artist if self.highlighted_item else None if artist is not None: # we don't accept unknown artist here bc spam risk artist_found = False + items_added = False + items_skipped = False for song in self.app.mp3_files: if song.artist == artist: - self.app.playlist.append(song.copy()) artist_found = True + if len(self.app.playlist) <= PLAYLIST_MAX_LEN: + self.app.playlist.append(song.copy()) + items_added = True + else: + items_skipped = True elif artist_found: break # list should be sorted so that should be all - self.app.save_request = True - self.label_state[PETAL_B] = None + if items_added: + self.app.save_request = True + self.label_state[PETAL_B] = None + if items_skipped: + # TODO: send toast once they exist + pass class MediaPage(NotPlaylistPage): @@ -438,9 +450,13 @@ class MediaPage(NotPlaylistPage): self.input.captouch.petals[PETAL_B].whole.pressed and self.highlighted_item is not None ): - self.app.playlist.append(self.highlighted_item.copy()) - self.app.save_request = True - self.label_state[PETAL_B] = None + if len(self.app.playlist) <= PLAYLIST_MAX_LEN: + self.app.playlist.append(self.highlighted_item.copy()) + self.app.save_request = True + self.label_state[PETAL_B] = None + else: + # TODO: send toast once they exist + pass class PlaylistPage(ListPage):