Add playlist database #39

Merged
matthias merged 5 commits from 23-add-playlist-db into main 2025-10-27 20:37:51 +00:00
Owner

Add playlist database based on the micropython 'btree' module.
Supported features are:

  • Create playlist
  • Load playlist
  • Store position in playlist

Different playlist modes will be added in a followup for #24.

Implements #23.

The playlist data is stored in the btree database in a hierarchical
schema. The hierarchy levels are separated by the '/' character.
Currently, the schema is as follows: The top level for a playlist is the
'tag' id encoded as a hexadecimal string. Beneath this, the 'playlist'
key contains the elements in the playlist. The keys used for the
playlist entries should be decimal integers, prefixed with sufficient
zeros such that they are in the correct order when sorted lexicographically.
When writing a playlist using the playlistdb module, the keys are 00000, 00001,
etc. by default. The 'playlistpos' key is also located under the 'tag' key and
stores the key of the current playlist entry.

For example, a playlist with two entries 'a.mp3' and 'b.mp3' for a tag
with the id '00aa11bb22' would be stored in the following key/value
pairs in the btree db:

  • 00aa11bb22/playlist/00000: a.mp3
  • 00aa11bb22/playlist/00001: b.mp3
  • 00aa11bb22/playlistpos: 00000
Add playlist database based on the micropython 'btree' module. Supported features are: * Create playlist * Load playlist * Store position in playlist Different playlist modes will be added in a followup for #24. Implements #23. The playlist data is stored in the btree database in a hierarchical schema. The hierarchy levels are separated by the '/' character. Currently, the schema is as follows: The top level for a playlist is the 'tag' id encoded as a hexadecimal string. Beneath this, the 'playlist' key contains the elements in the playlist. The keys used for the playlist entries should be decimal integers, prefixed with sufficient zeros such that they are in the correct order when sorted lexicographically. When writing a playlist using the playlistdb module, the keys are 00000, 00001, etc. by default. The 'playlistpos' key is also located under the 'tag' key and stores the key of the current playlist entry. For example, a playlist with two entries 'a.mp3' and 'b.mp3' for a tag with the id '00aa11bb22' would be stored in the following key/value pairs in the btree db: - 00aa11bb22/playlist/00000: a.mp3 - 00aa11bb22/playlist/00001: b.mp3 - 00aa11bb22/playlistpos: 00000
matthias self-assigned this 2025-08-27 14:18:31 +00:00
matthias added 1 commit 2025-08-27 14:18:31 +00:00
Add playlist database
All checks were successful
Build RPi Pico firmware image / Build-Firmware (push) Successful in 3m22s
Check code formatting / Check-C-Format (push) Successful in 7s
Check code formatting / Check-Python-Flake8 (push) Successful in 9s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 5s
Run unit tests on host / Run-Unit-Tests (push) Successful in 8s
Run pytests / Check-Pytest (push) Successful in 10s
5723c3e327
Add playlist database based on the micropython 'btree' module.
Supported features are:
* Create playlist
* Load playlist
* Store position in playlist

Different playlist modes will be added in a followup for #24.

Implements #23.

The playlist data is stored in the btree database in a hierarchical
schema. The hierarchy levels are separated by the '/' character.
Currently, the schema is as follows: The top level for a playlist is the
'tag' id encoded as a hexadecimal string. Beneath this, the 'playlist'
key contains the elements in the playlist. The exact keys used for the
playlist entries are not specified, they are enumerated in native sort
order to build the playlist. When writing a playlist using the
playlistdb module, the keys are 000, 001, etc. by default.  The
'playlistpos' key is also located under the 'tag' key and stores the key
of the current playlist entry.

For example, a playlist with two entries 'a.mp3' and 'b.mp3' for a tag
with the id '00aa11bb22' would be stored in the following key/value
pairs in the btree db:
- 00aa11bb22/playlist/000: a.mp3
- 00aa11bb22/playlist/001: b.mp3
- 00aa11bb22/playlistpos: 000

Signed-off-by: Matthias Blankertz <matthias@blankertz.org>
matthias requested review from stefank 2025-08-27 14:18:32 +00:00
matthias added a new dependency 2025-08-27 14:18:46 +00:00
stefank reviewed 2025-08-27 19:41:08 +00:00
@@ -80,1 +70,3 @@
self._play(self.playlist[self.playlist_pos])
def _set_playlist(self, tag: bytes):
self.playlist = self.playlist_db.getPlaylistForTag(tag)
self._play(self.playlist.getCurrentPath())
Member

playlist may be None if no playlist was found for tag

`playlist` may be None if no playlist was found for `tag`
matthias marked this conversation as resolved
matthias added 2 commits 2025-08-28 10:17:56 +00:00
- Increase the formatting of playlist entries to allow up to 100000
  tracks. Also enforce that playlist entries are indexed by integers
  using the validate method.

- Add a validate method to validate the data stored in the
  btreedb. Optionally dump the contents to stdout. For testing, add a
  validate+dump by default when opening the db. This can be removed once
  the playlistdb is validated.
app: Fix bug when a tag that has no playlist is encountered
All checks were successful
Build RPi Pico firmware image / Build-Firmware (push) Successful in 3m23s
Check code formatting / Check-C-Format (push) Successful in 7s
Check code formatting / Check-Python-Flake8 (push) Successful in 9s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 5s
Run unit tests on host / Run-Unit-Tests (push) Successful in 8s
Run pytests / Check-Pytest (push) Successful in 10s
a84d7d9c1a
matthias changed target branch from add-pytest-infrastructure to main 2025-08-28 15:37:13 +00:00
matthias force-pushed 23-add-playlist-db from a84d7d9c1a to e862019b20 2025-08-28 15:37:51 +00:00 Compare
matthias force-pushed 23-add-playlist-db from e862019b20 to 5d5526835c 2025-08-28 16:06:41 +00:00 Compare
matthias force-pushed 23-add-playlist-db from 5d5526835c to 6645c4443b 2025-09-06 19:51:01 +00:00 Compare
matthias added 2 commits 2025-10-07 20:24:19 +00:00
playlistdb: micropython does not have bytes.removeprefix()
All checks were successful
Build RPi Pico firmware image / Build-Firmware (push) Successful in 3m22s
Check code formatting / Check-C-Format (push) Successful in 7s
Check code formatting / Check-Python-Flake8 (push) Successful in 9s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 5s
Run unit tests on host / Run-Unit-Tests (push) Successful in 8s
Run pytests / Check-Pytest (push) Successful in 10s
6645c4443b
playlistdb: micropython does not have bytes.removeprefix()
All checks were successful
Build RPi Pico firmware image / Build-Firmware (push) Successful in 3m26s
Check code formatting / Check-C-Format (push) Successful in 8s
Check code formatting / Check-Python-Flake8 (push) Successful in 11s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 5s
Run unit tests on host / Run-Unit-Tests (push) Successful in 9s
Run pytests / Check-Pytest (push) Successful in 11s
fef9e690cd
stefank added 1 commit 2025-10-14 19:21:23 +00:00
playlistdb: testing lexicographic sorting of db entries
All checks were successful
Build RPi Pico firmware image / Build-Firmware (push) Successful in 3m21s
Check code formatting / Check-C-Format (push) Successful in 7s
Check code formatting / Check-Python-Flake8 (push) Successful in 9s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 4s
Run unit tests on host / Run-Unit-Tests (push) Successful in 8s
Run pytests / Check-Pytest (push) Successful in 11s
5625f43f81
stefank approved these changes 2025-10-14 19:25:33 +00:00
stefank left a comment
Member

Approve everything up until my commit. Than one might be reviewed by you ;)

Approve everything up until my commit. Than one might be reviewed by you ;)
matthias merged commit 92f9ce3d5a into main 2025-10-27 20:37:51 +00:00
matthias deleted branch 23-add-playlist-db 2025-10-27 20:37:51 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Depends on
#38 add-pytest-infrastructure
TonBERRY/tonberry-pico
Reference: TonBERRY/tonberry-pico#39