Sample Code

The following is some sample code that provides examples on performing Search: Custom Database functions:

Performing a search against your Custom Database

main.py
#!/usr/bin/env python3

import json
import pex

CLIENT_ID = "#YOUR_CLIENT_ID_HERE"
CLIENT_SECRET = "#YOUR_CLIENT_SECRET_HERE"
INPUT_FILE = "/path/to/file.mp3"

def main():
    # Initialize and authenticate the client
    client = pex.PrivateSearchClient(CLIENT_ID, CLIENT_SECRET)

    # Create an audio fingerprint from input file
    ft = client.fingerprint_file(INPUT_FILE, pex.FingerprintType.AUDIO)

    # Build a search request
    req = pex.PrivateSearchRequest(fingerprint=ft)

    # Start the search against your custom database
    future = client.start_search(req)

    # Retrieve the result
    result = future.get()

    # Print the result
    print(json.dumps(result, indent=2))

if __name__ == '__main__':
    main()

Ingesting an Asset into your Custom Database

main.py
#!/usr/bin/env python3

import json
import pex

CLIENT_ID = "#YOUR_CLIENT_ID_HERE"
CLIENT_SECRET = "#YOUR_CLIENT_SECRET_HERE"
INPUT_FILE = "/path/to/file.mp3"
PROVIDED_ID = "provided_id"

def main():
    # Initialize and authenticate the client
    client = pex.PrivateSearchClient(CLIENT_ID, CLIENT_SECRET)

    # Create an audio fingerprint from input file
    ft = client.fingerprint_file(INPUT_FILE, pex.FingerprintType.AUDIO)

    # Build a search request
    req = pex.PrivateSearchRequest(fingerprint=ft)

    # Ingest FT in your Custom Database
    client.ingest(PROVIDED_ID, ft)

if __name__ == '__main__':
    main()

Archiving an Asset in your Custom Database

main.py
#!/usr/bin/env python3

import json
import pex

CLIENT_ID = "#YOUR_CLIENT_ID_HERE"
CLIENT_SECRET = "#YOUR_CLIENT_SECRET_HERE"
PROVIDED_ID = "provided_id"

def main():
    # Initialize and authenticate the client
    client = pex.PrivateSearchClient(CLIENT_ID, CLIENT_SECRET)

    # Archive a FT
    client.archive(PROVIDED_ID)

if __name__ == '__main__':
    main()

Listing Assets in your Custom Database

main.py
#!/usr/bin/env python3

import json
import pex

CLIENT_ID = "#YOUR_CLIENT_ID_HERE"
CLIENT_SECRET = "#YOUR_CLIENT_SECRET_HERE"

def main():
    # Initialize and authenticate the client
    client = pex.PrivateSearchClient(CLIENT_ID, CLIENT_SECRET)

    # List FTs
    lister = client.list_entries(pex.ListEntriesRequest())
    while lister.has_next_page:
      entries = lister.list()
      for entry in entries:
        print(entry)

if __name__ == '__main__':
    main()

Last updated