package host
import (
"encoding/json"
"errors"
"github.com/navidrome/navidrome/plugins/pdk/go/types"
"github.com/navidrome/navidrome/plugins/pdk/go/pdk"
)
type MatchOptions struct {
Username string `json:"username"`
}
func matcher_matchsongs(uint64) uint64
type matcherMatchSongsRequest struct {
Songs []types.SongRef `json:"songs"`
Opts MatchOptions `json:"opts"`
}
type matcherMatchSongsResponse struct {
Results []*types.Track `json:"results,omitempty"`
Error string `json:"error,omitempty"`
}
func MatcherMatchSongs(songs []types.SongRef, opts MatchOptions) ([]*types.Track, error) {
req := matcherMatchSongsRequest{
Songs: songs,
Opts: opts,
}
reqBytes, err := json.Marshal(req)
if err != nil {
return nil, err
}
reqMem := pdk.AllocateBytes(reqBytes)
defer reqMem.Free()
responsePtr := matcher_matchsongs(reqMem.Offset())
responseMem := pdk.FindMemory(responsePtr)
responseBytes := responseMem.ReadBytes()
var response matcherMatchSongsResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return nil, err
}
if response.Error != "" {
return nil, errors.New(response.Error)
}
return response.Results, nil
}