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
| routes.get("info", &LibraryController::getInfo); | ||
| routes.get("items/:range", &LibraryController::getItems); | ||
| routes.get("browse/:range", &LibraryController::browse); | ||
| routes.post("items/add", ControllerAction<LibraryController>(&LibraryController::addItems)); |
There was a problem hiding this comment.
Maybe something like /api/library/items/add-to-playlist/:plref.
Otherwise it might look like this method adds something to library.
There was a problem hiding this comment.
Or maybe even moving this under playlists prefix would look more natural, e.g.
/api/playlists/:plref/items/add-from-library
| return Response::json({{"libraryNodes", player_->getLibraryNodes(query, range, columnsQuery.get())}}); | ||
| } | ||
|
|
||
| ResponsePtr LibraryController::addItems() |
There was a problem hiding this comment.
This endpoint is for adding query result.
What if consumer (e.g. web UI) already have set of item paths (plus subsong) and wants to add them as-is?
There was a problem hiding this comment.
Also, I think we need to add something like itemPath/subsong in query results, so the consumer can refer to found library items in such API.
For grouped query result such information exists, but for flat query result there is no such info.
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.