[Extension] Bookmarks!

Hello,
I am finally released a standalone bookmarks extension for Mopidy. It was somewhat more complex to do than I expected, and some API choices were difficult to make, but it’s finally there and working !

Presentation

From the Readme,

Bookmarks are playlist that can be synced with the current playback state, so that you can easily stop listening to some tracklist, listen to something else, and later resume at the position where you stopped. This is most usefull when listening to audiobooks.

Bookmarks are playlists saved in a sqlite database.
When synchronising between a bookmark and playback state, the current track and current time will be saved periodically (every 0.5 second by default). As soon as the tracklist changes, or the stop_sync command is received, synchronisation will stop.
A bookmark can then be resumed with the resume command, replacing the tracklist with the bookmark tracks, and resuming playback from the saved state.

To use this extension, one must use a compatible client – I will push a new version of mowecl using the extension soon --, or directly make calls with a websocket client.

I have published this as a separate extension in the hope that it can serve people not using mowecl, and maybe not even using a web client.

API Choices

After many iterations, I came with the following API:

  • use the Mopidy Playlist API to create/update/delete bookmarks
  • provide a websocket server for bookmark specific commands (essentially start and stop syncing)

This means that bookmarks will be seen as playlists to any client connecting to Mopidy, which can either be a good or a bad thing depending on each person preferences, but I think in most cases this will just be more convenient.

What’s next

There’s one feature I will add soon: the possibility to choose which event will stop a bookmark synchronisation. For example, you could choose to stop sync only when the tracklist is cleared, so that you can incrementally build a playlist, without having to save it each time.
I might also add an http API (additionnaly to the websocket one) so that access will be easier from non-javascript applications.

I don’t have much more ideas of what could be added, but I’d be glad to hear some.

Security concerns

I might have been a bit over-paranoid on this, but I thought it would be important to prevent an attacker from creating a giant bookmark that would eat up all disk-space (this was mostly before thinking of using the mopidy playlist API, so maybe this is not so much of a concern, at least not more than with a giant m3u playlist). So I have set up configurable limits to the number of bookmarks and the size of saved data per bookmark (I have yet to create a global disable switch).
Note that the extension also provide a simple key/value store, with just the same possible issue.

Possible issues

To sync the current bookmark at regular intervals, a loop is running. Since the loop will not exit before waking from sleep, setting a long interval will mean that mopidy might take a long time to stop (it will wait for the loop to exit). This is not really noticeable with an interval of 0.5 seconds, but might be an issue for some.