Basic Usage
Core Functionality
Authenticate
The first step is to initialize the SDK client with the credentials that have been provided to you:
# AUTHENTICATE CLIENT
client = pex.PexSearchClient("CLIENT_ID", "CLIENT_SECRET")
Generate Fingerprint
Before performing any searches you need to generate a fingerprint from a media file:
# CREATE AN AUDIO FINGERPRINT FROM MEDIA FILE
ft = client.fingerprint_file(
"/path/to/file.mp3",
pex.FingerprintType.AUDIO
)
# CREATE A MELODY + PHONETIC FINGERPRINT FROM MEDIA FILE
ft = client.fingerprint_file(
"/path/to/file.mp3",
pex.FingerprintType.MELODY | pex.FingerprintType.PHONETIC
)
# CREATE A CLASSIFICATION FINGERPRINT FROM MEDIA FILE
ft = client.fingerprint_file(
"/path/to/file.mp3",
pex.FingerprintType.CLASSIFICATION
)
Alternatively, a fingeprint can be created from a byte buffer holding a media file
# CREATE AN AUDIO FINGERPRINT FROM BYTE BUFFER HOLDING A MEDIA FILE
ft = client.fingerprint_buffer([]byte, pex.FingerprintType.AUDIO)
Search Functionality
Initiate Search
Once the fingerprint has been generated, you are ready to initiate a search:
# BUILD REQUEST FOR "IDENTIFY MUSIC" SEARCH TYPE
req = pex.PexSearchRequest(fingerprint=ft, type=pex.PexSearchType.IDENTIFY_MUSIC)
# BUILD REQUEST FOR "FIND MATCHES" SEARCH TYPE
req = pex.PexSearchRequest(fingerprint=ft, type=pex.PexSearchType.FIND_MATCHES)
# START SEARCH
future = client.start_search(req)
A search combines a fingerprint type (how your file is analyzed) with a search type (what kind of lookup is performed). The combination you choose determines the results you’ll see. Refer to Search Types & Use Cases for examples of common use cases and suggested combinations.
Retrieve Search Results
Once a search is complete, you can retrieve the results of the search:
# RETRIEVE SEARCH RESULTS
result = future.get()
Interpret Search Results
To view details on what's contained in a search response, please see the following section: Search Response
Last updated