Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying different PexSearch types #47

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 000init.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package pex
// #cgo LDFLAGS: -Wl,-rpath,/usr/local/lib
//
// #define PEX_SDK_MAJOR_VERSION 4
// #define PEX_SDK_MINOR_VERSION 0
// #define PEX_SDK_MINOR_VERSION 1
//
// #include <pex/sdk/version.h>
import "C"
Expand Down
26 changes: 24 additions & 2 deletions pex_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,31 @@ import (
"unsafe"
)

// PexSearchType can optionally be specified in the PexSearchRequest and will
// allow to retrieve results that are more relevant to the given use-case.
type PexSearchType int

const (
// IdentifyMusic is a type of PexSearch that will return results that will
// help identify the music in the provided media file.
IdentifyMusic = C.Pex_CheckSearchType_IdentifyMusic

// FindMatches is a type of PexSearch that will return all assets that
// matched against the given media file.
FindMatches = C.Pex_CheckSearchType_FindMatches
)

// Holds all data necessary to perform a pex search. A search can only be
// performed using a fingerprint, but additional parameters may be supported in
// the future.
type PexSearchRequest struct {
// A fingerprint obtained by calling either NewFingerprintFromFile
// or NewFingerprintFromBuffer. This field is required.
Fingerprint *Fingerprint

// Type is optional and when specified will allow to retrieve results that
// are more relevant to the given use-case.
Type PexSearchType
}

// This object is returned from PexSearchFuture.Get upon successful
Expand Down Expand Up @@ -82,13 +100,14 @@ type PexSearchFuture struct {
client *PexSearchClient

LookupIDs []string
Type PexSearchType
}

// Get blocks until the search result is ready and then returns it. It
// also releases all the allocated resources, so it will return an
// error when called multiple times.
func (x *PexSearchFuture) Get() (*PexSearchResult, error) {
return x.client.CheckSearch(x.LookupIDs)
return x.client.CheckSearch(x.LookupIDs, x.Type)
}

// PexSearchClient serves as an entry point to all operations that
Expand Down Expand Up @@ -178,10 +197,11 @@ func (x *PexSearchClient) StartSearch(req *PexSearchRequest) (*PexSearchFuture,
return &PexSearchFuture{
client: x,
LookupIDs: lookupIDs,
Type: req.Type,
}, nil
}

func (x *PexSearchClient) CheckSearch(lookupIDs []string) (*PexSearchResult, error) {
func (x *PexSearchClient) CheckSearch(lookupIDs []string, searchType PexSearchType) (*PexSearchResult, error) {
C.Pex_Lock()
defer C.Pex_Unlock()

Expand Down Expand Up @@ -209,6 +229,8 @@ func (x *PexSearchClient) CheckSearch(lookupIDs []string) (*PexSearchResult, err
C.Pex_CheckSearchRequest_AddLookupID(cRequest, cLookupID)
}

C.Pex_CheckSearchRequest_SetType(cRequest, C.Pex_CheckSearchType(searchType))

C.Pex_CheckSearch(x.c, cRequest, cResult, cStatus)
if err := statusToError(cStatus); err != nil {
return nil, err
Expand Down