137 lines
3.8 KiB
Go
137 lines
3.8 KiB
Go
|
|
// Code generated by ndpgen. DO NOT EDIT.
|
||
|
|
//
|
||
|
|
// This file contains export wrappers for the SonicSimilarity capability.
|
||
|
|
// It is intended for use in Navidrome plugins built with TinyGo.
|
||
|
|
//
|
||
|
|
//go:build wasip1
|
||
|
|
|
||
|
|
package sonicsimilarity
|
||
|
|
|
||
|
|
import (
|
||
|
|
"github.com/navidrome/navidrome/plugins/pdk/go/pdk"
|
||
|
|
)
|
||
|
|
|
||
|
|
// FindSonicPathRequest represents the FindSonicPathRequest data structure.
|
||
|
|
type FindSonicPathRequest struct {
|
||
|
|
StartSong SongRef `json:"startSong"`
|
||
|
|
EndSong SongRef `json:"endSong"`
|
||
|
|
Count int32 `json:"count"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// GetSonicSimilarTracksRequest represents the GetSonicSimilarTracksRequest data structure.
|
||
|
|
type GetSonicSimilarTracksRequest struct {
|
||
|
|
Song SongRef `json:"song"`
|
||
|
|
Count int32 `json:"count"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// SongRef is a reference to a song with metadata for matching.
|
||
|
|
type SongRef struct {
|
||
|
|
// ID is the internal Navidrome mediafile ID (if known).
|
||
|
|
ID string `json:"id,omitempty"`
|
||
|
|
// Name is the song name.
|
||
|
|
Name string `json:"name"`
|
||
|
|
// MBID is the MusicBrainz ID for the song.
|
||
|
|
MBID string `json:"mbid,omitempty"`
|
||
|
|
// ISRC is the International Standard Recording Code for the song.
|
||
|
|
ISRC string `json:"isrc,omitempty"`
|
||
|
|
// Artist is the artist name.
|
||
|
|
Artist string `json:"artist,omitempty"`
|
||
|
|
// ArtistMBID is the MusicBrainz artist ID.
|
||
|
|
ArtistMBID string `json:"artistMbid,omitempty"`
|
||
|
|
// Album is the album name.
|
||
|
|
Album string `json:"album,omitempty"`
|
||
|
|
// AlbumMBID is the MusicBrainz release ID.
|
||
|
|
AlbumMBID string `json:"albumMbid,omitempty"`
|
||
|
|
// Duration is the song duration in seconds.
|
||
|
|
Duration float32 `json:"duration,omitempty"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// SonicMatch represents the SonicMatch data structure.
|
||
|
|
type SonicMatch struct {
|
||
|
|
Song SongRef `json:"song"`
|
||
|
|
Similarity float64 `json:"similarity"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// SonicSimilarityResponse represents the SonicSimilarityResponse data structure.
|
||
|
|
type SonicSimilarityResponse struct {
|
||
|
|
Matches []SonicMatch `json:"matches"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// SonicSimilarity requires all methods to be implemented.
|
||
|
|
// SonicSimilarity provides audio-similarity based track discovery.
|
||
|
|
type SonicSimilarity interface {
|
||
|
|
// GetSonicSimilarTracks
|
||
|
|
GetSonicSimilarTracks(GetSonicSimilarTracksRequest) (SonicSimilarityResponse, error)
|
||
|
|
// FindSonicPath
|
||
|
|
FindSonicPath(FindSonicPathRequest) (SonicSimilarityResponse, error)
|
||
|
|
} // Internal implementation holders
|
||
|
|
var (
|
||
|
|
sonicSimilarTracksImpl func(GetSonicSimilarTracksRequest) (SonicSimilarityResponse, error)
|
||
|
|
findSonicPathImpl func(FindSonicPathRequest) (SonicSimilarityResponse, error)
|
||
|
|
)
|
||
|
|
|
||
|
|
// Register registers a sonicsimilarity implementation.
|
||
|
|
// All methods are required.
|
||
|
|
func Register(impl SonicSimilarity) {
|
||
|
|
sonicSimilarTracksImpl = impl.GetSonicSimilarTracks
|
||
|
|
findSonicPathImpl = impl.FindSonicPath
|
||
|
|
}
|
||
|
|
|
||
|
|
// NotImplementedCode is the standard return code for unimplemented functions.
|
||
|
|
// The host recognizes this and skips the plugin gracefully.
|
||
|
|
const NotImplementedCode int32 = -2
|
||
|
|
|
||
|
|
//go:wasmexport nd_get_sonic_similar_tracks
|
||
|
|
func _NdGetSonicSimilarTracks() int32 {
|
||
|
|
if sonicSimilarTracksImpl == nil {
|
||
|
|
// Return standard code - host will skip this plugin gracefully
|
||
|
|
return NotImplementedCode
|
||
|
|
}
|
||
|
|
|
||
|
|
var input GetSonicSimilarTracksRequest
|
||
|
|
if err := pdk.InputJSON(&input); err != nil {
|
||
|
|
pdk.SetError(err)
|
||
|
|
return -1
|
||
|
|
}
|
||
|
|
|
||
|
|
output, err := sonicSimilarTracksImpl(input)
|
||
|
|
if err != nil {
|
||
|
|
pdk.SetError(err)
|
||
|
|
return -1
|
||
|
|
}
|
||
|
|
|
||
|
|
if err := pdk.OutputJSON(output); err != nil {
|
||
|
|
pdk.SetError(err)
|
||
|
|
return -1
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0
|
||
|
|
}
|
||
|
|
|
||
|
|
//go:wasmexport nd_find_sonic_path
|
||
|
|
func _NdFindSonicPath() int32 {
|
||
|
|
if findSonicPathImpl == nil {
|
||
|
|
// Return standard code - host will skip this plugin gracefully
|
||
|
|
return NotImplementedCode
|
||
|
|
}
|
||
|
|
|
||
|
|
var input FindSonicPathRequest
|
||
|
|
if err := pdk.InputJSON(&input); err != nil {
|
||
|
|
pdk.SetError(err)
|
||
|
|
return -1
|
||
|
|
}
|
||
|
|
|
||
|
|
output, err := findSonicPathImpl(input)
|
||
|
|
if err != nil {
|
||
|
|
pdk.SetError(err)
|
||
|
|
return -1
|
||
|
|
}
|
||
|
|
|
||
|
|
if err := pdk.OutputJSON(output); err != nil {
|
||
|
|
pdk.SetError(err)
|
||
|
|
return -1
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0
|
||
|
|
}
|