Basic Usage

Core Functionality

Authenticate

The first step is to initialize the SDK client with the credentials that have been provided to you:

Note: If you are both a Search: Custom Database and Search: Pex Registry customer, each product will require a separate set of credentials.

# AUTHENTICATE CLIENT
client = pex.PrivateSearchClient("CLIENT_ID", "CLIENT_SECRET")

Note: There might be a slight delay the first time you authenticate as the SDK downloads and installs necessary updates

Generate Fingerprint

First, generate a fingerprint from the media file you. You can either generate a fingerprint to ingest into your custom database or you can generate a fingerprint to initiate a search with.

# CREATE AUDIO FINGERPRINT FROM MEDIA FILE
ft = client.fingerprint_file("/path/to/file.mp3", pex.FingerprintType.AUDIO)

# CREATE MELODY FINGERPRINT FROM MEDIA FILE
ft = client.fingerprint_file("/path/to/file.mp3", pex.FingerprintType.MELODY)

# CREATE AUDIO FINGERPRINT FROM BYTE BUFFER HOLDING A MEDIA FILE
ft = client.fingerprint_buffer([]byte, pex.FingerprintType.AUDIO)

# CREATE MELODY FINGERPRINT FROM BYTE BUFFER HOLDING A MEDIA FILE
ft = client.fingerprint_buffer([]byte, pex.FingerprintType.MELODY)

Note: When creating audio fingerprints, the SDK uses a single CPU. For melody fingerprints, the SDK uses two CPUs, if available.

If you need to process larger volumes of files, running computations in parallel is recommended. This can significantly improve processing capacity.

For information on the difference between audio and melody fingerprints and the use cases they address, please see our FAQ page

Searching Functionality

Generate Fingerprint

Before performing any searches you need to generate a fingerprint from a media file:

# CREATE AUDIO FINGERPRINT FROM MEDIA FILE
ft = client.fingerprint_file("/path/to/file.mp3", pex.FingerprintType.AUDIO)

# CREATE MELODY FINGERPRINT FROM MEDIA FILE
ft = client.fingerprint_file("/path/to/file.mp3", pex.FingerprintType.MELODY)

# CREATE AUDIO FINGERPRINT FROM BYTE BUFFER HOLDING A MEDIA FILE
ft = client.fingerprint_buffer([]byte, pex.FingerprintType.AUDIO)

# CREATE MELODY FINGERPRINT FROM BYTE BUFFER HOLDING A MEDIA FILE
ft = client.fingerprint_buffer([]byte, pex.FingerprintType.MELODY)

Note: Our SDK's computations are single-threaded. If you need to process larger volumes of files, running computations in parallel is recommended. This can significantly improve processing capacity.

For information on the difference between audio and melody fingerprints and the use cases they address, please see our FAQ page

Once the fingerprint has been generated, you are ready to initiate a search:

# BUILD CUSTOM DATABASE SEARCH REQUEST
req = pex.PrivateSearchRequest(fingerprint=ft)

# START SEARCH
future = client.start_search(req)

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

Catalog Management

Add Fingerprint to Custom Database

Now that the fingerprint has been generated, you can add that fingerprint file to your custom database. You can associate a "custom_id" string of your choosing for each fingerprint (to help you uniquely identify each fingerprint that is in your database):

# ADD FINGERPRINT CUSTOM DATABASE
client.ingest("custom_id", ft)

Note: After ingesting an asset, it will take a short time (generally a few minutes) before it is available in your custom database to be searched against

Archive Fingerprint from your Custom Database

If you would like to remove an asset from your Custom Database so that it can no longer be matched against, you can do so with this command:

# ARCHIVE FINGERPRINT
client.archive("custom_id")

Lists Assets in your Custom Database

If you would like to view what assets are currently in your Custom Database, you can do so with the Lister functionality:

lister = client.list_entries(pex.ListEntriesRequest())
// To limit the number of entries:
//   lister = client.list_entries(pex.ListEntriesRequest(limit=5))

while lister.has_next_page:
  entries = lister.list()

  for entry in entries:
    print(entry)

Last updated