feat(library): add media library browsing API - #382
Conversation
|
Hello, Sergey. This is really cool. 🎉 There are few minor corrections I'd like to have, but overall looks good to me.
I'm going to rework object composition a little bit to provide Player implementations with ThreadPoolWorkQueue, so this could be avoided, but I think for the first iteration we can keep things as-is.
This is OK to me. User configured media library in this way.
I'll take care of this. By the way, did you consider adding API for browsing nodes with grouping other than FS entries, e.g. Artist/Album/Track, etc ? |
Thanks, yep, grouping by Artist/Album/Genre on server side will make library api complete. I'll prepare another PR soon |
|
|
||
| routes.get("info", &LibraryController::getInfo); | ||
| routes.get("items/:range", &LibraryController::getItems); | ||
| routes.get("browse/:range", &LibraryController::browse); |
There was a problem hiding this comment.
Could I suggest you URLs format?
/api/library/items <- flat result
/api/library/items/by-path <- grouped by directory structure
/api/library/items/by-columns <- grouped by title formatting expressions
There was a problem hiding this comment.
Sounds good, /api/library/items stays flat, the way the SDK returns
But grouped results has the same response schema, so how about the same url with a parameter:
/api/library/items/{range}?group_by=%folder%|%artist%|%album%
There was a problem hiding this comment.
You'll also need current values for %folder% and %artist%,
directory grouping request however wants current directory path.
So to summarize:
Common parameters:
- paging parameters
- ordering parameters
- list of columns to return
- user defined search string
Specific to directory structure:
- current path
Custom grouping structure:
- N title formatting expressions for grouping
- N-1 values for specify current "path" within grouping structure
Combining these into single endpoint would be difficult to understand for consumers.
Underlying implementation likely will be different as well.
There was a problem hiding this comment.
Other random note:
Maybe moving range parameter from URL to query string would be more easy to read.
Playlists are naturally ordered, but with media library we first apply search criteria and then paging.
Current URL structure pretends other way.
We can have some default value for range e.g. 0:1000, which will cover typical use cases.
There was a problem hiding this comment.
Fair points. Default of 0:1000 isn't the same as a maximum, I would rather keep it unbounded by default
|
@sb-3000 I have two ideas
|
Media library API (foobar2000)
Adds read access to the foobar2000 media library, plus the two operations a
library browser needs: artwork and adding to playlists.
Endpoints
GET /api/library/info→{supported, enabled, itemCount}GET /api/library/items/{offset}:{count}—columns(required),view,path,query,sort,descview=flat(default): paged track list, optional query filter andtitle-format sort
view=folders: one tree level — subfolders first with a recursiveitemCount, then tracks with the requested columns. Response carriespath,parentPath(absent at top level) andpathSeparatorGET /api/artwork/library?path=&subsong=— artwork without going through aplaylist. A folder prefers its own image file (
folder/cover/front/album/artwork× common extensions), falling back to the first track's art.POST /api/library/items/add—{plref, path, subsong, query, index, replace, play}. Resolves the selection to metadb handles server side and inserts themwith
playlist_insert_items. RequireschangePlaylists.Notes on design
(
library_manager::get_relative_path), so browsing starts at library foldersrather than filesystem roots. Multiple library folders merge into one tree.
several tracks in one file, so
subsongis exposed as a first-class fieldon track nodes.
addinserts handles directly, a single subsong can be added on itsown, and the music-directories restriction does not apply — nothing is
resolved from client-supplied filesystem paths.
Playerreportssupported: falseandthe endpoints return 501.
Known limitations
per item. Fine for interactive use; a folder-thumbnail grid multiplies it.
libraryevent key for/api/query, so clients cannot observe librarychanges.
Testing
API tests in
js/api_tests/src/library_api_tests.jsplus a permissions case.Verified manually against a 9540-track library including cue-sheet albums and
SACD ISOs; the automated tests run against an empty library, so tree
resolution and subsong handling are not covered by CI.