package host
import (
"encoding/json"
"errors"
"github.com/navidrome/navidrome/plugins/pdk/go/pdk"
)
type Library struct {
ID int32 `json:"id"`
Name string `json:"name"`
Path string `json:"path"`
MountPoint string `json:"mountPoint"`
LastScanAt int64 `json:"lastScanAt"`
TotalSongs int32 `json:"totalSongs"`
TotalAlbums int32 `json:"totalAlbums"`
TotalArtists int32 `json:"totalArtists"`
TotalSize int64 `json:"totalSize"`
TotalDuration float64 `json:"totalDuration"`
}
func library_getlibrary(uint64) uint64
func library_getalllibraries(uint64) uint64
type libraryGetLibraryRequest struct {
Id int32 `json:"id"`
}
type libraryGetLibraryResponse struct {
Result *Library `json:"result,omitempty"`
Error string `json:"error,omitempty"`
}
type libraryGetAllLibrariesResponse struct {
Result []Library `json:"result,omitempty"`
Error string `json:"error,omitempty"`
}
func LibraryGetLibrary(id int32) (*Library, error) {
req := libraryGetLibraryRequest{
Id: id,
}
reqBytes, err := json.Marshal(req)
if err != nil {
return nil, err
}
reqMem := pdk.AllocateBytes(reqBytes)
defer reqMem.Free()
responsePtr := library_getlibrary(reqMem.Offset())
responseMem := pdk.FindMemory(responsePtr)
responseBytes := responseMem.ReadBytes()
var response libraryGetLibraryResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return nil, err
}
if response.Error != "" {
return nil, errors.New(response.Error)
}
return response.Result, nil
}
func LibraryGetAllLibraries() ([]Library, error) {
reqMem := pdk.AllocateBytes([]byte("{}"))
defer reqMem.Free()
responsePtr := library_getalllibraries(reqMem.Offset())
responseMem := pdk.FindMemory(responsePtr)
responseBytes := responseMem.ReadBytes()
var response libraryGetAllLibrariesResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return nil, err
}
if response.Error != "" {
return nil, errors.New(response.Error)
}
return response.Result, nil
}