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()
main.go
package main
import (
"encoding/json"
"fmt"
pex "github.com/Pexeso/pex-sdk-go/v4"
)
const (
clientID = "#YOUR_CLIENT_ID_HERE"
clientSecret = "#YOUR_CLIENT_SECRET_HERE"
inputFile = "/path/to/file.mp3"
)
func main() {
// Initialize and authenticate the client
client, err := pex.NewPrivateSearchClient(clientID, clientSecret)
if err != nil {
panic(err)
}
defer client.Close()
// Create an audio fingerprint from input file
ft, err := client.FingerprintFile(inputFile, pex.FingerprintTypeAudio)
if err != nil {
panic(err)
}
// Build a search request
req := &pex.PrivateSearchRequest{
Fingerprint: ft,
}
// Start the search against your custom database
fut, err := client.StartSearch(req)
if err != nil {
panic(err)
}
// Retrieve the result
res, err := fut.Get()
if err != nil {
panic(err)
}
// Print the result
j, err := json.MarshalIndent(res, "", " ")
if err != nil {
panic(err)
}
fmt.Println(string(j))
}
index.php
<?php
require __DIR__ . '/vendor/autoload.php';
const CLIENT_ID = "#YOUR_CLIENT_ID_HERE";
const CLIENT_SECRET = "#YOUR_CLIENT_SECRET_HERE";
const INPUT_FILE = "/path/to/file.mp3";
// Initialize and authenticate the client
$client = new Pex\PrivateSearchClient(CLIENT_ID, CLIENT_SECRET);
// Create an audio fingerprint from input file
$ft = $client->fingerprintFile(INPUT_FILE, [Pex\FingerprintType::Audio]);
// Build a search request
$req = new \Pex\PrivateSearchRequest($ft);
// Start the search against your custom database
$fut = $client->startSearch($req);
// Retrieve the result
$res = $fut->get();
// Print the result
var_dump($res);
main.js
const pex = require("pex-sdk");
const CLIENT_ID = "#YOUR_CLIENT_ID_HERE";
const CLIENT_SECRET = "#YOUR_CLIENT_SECRET_HERE";
const INPUT_FILE = "/path/to/file.mp3";
async function main() {
try {
// Initialize and authenticate the client
let client = new pex.PrivateSearchClient(CLIENT_ID, CLIENT_SECRET)
// Connect to the PrivateSearch server. This operation is asynchronous and
// returns a promise, just like most operations in this package.
await client.connect()
// Create an audio fingerprint from input file
let ft = await client.fingerprintFile(INPUT_FILE, [pex.AUDIO])
// Start the search against your custom database and await the result
let result = await client.startSearch({
fingerprint: ft,
})
// Pretty print the result
console.log(JSON.stringify(result, null, 2))
} catch (err) {
// If any of the operations above fail, this block will be executed.
console.log(err)
}
}
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()
package main
import (
"encoding/json"
"fmt"
pex "github.com/Pexeso/pex-sdk-go/v4"
)
const (
clientID = "#YOUR_CLIENT_ID_HERE"
clientSecret = "#YOUR_CLIENT_SECRET_HERE"
inputFile = "/path/to/file.mp3"
providedID = "PROVIDED_ID"
)
func main() {
// Initialize and authenticate the client
client, err := pex.NewPrivateSearchClient(clientID, clientSecret)
if err != nil {
panic(err)
}
defer client.Close()
// Create an audio fingerprint from input file
ft, err := client.FingerprintFile(inputFile, pex.FingerprintTypeAudio)
if err != nil {
panic(err)
}
// Ingest FT into your custom database
if err := client.Ingest(providedID, ft); err != nil {
panic(err)
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
const CLIENT_ID = "#YOUR_CLIENT_ID_HERE";
const CLIENT_SECRET = "#YOUR_CLIENT_SECRET_HERE";
const INPUT_FILE = "/path/to/file.mp3";
const PROVIDED_ID = "PROVIDED_ID";
// Initialize and authenticate the client
$client = new Pex\PrivateSearchClient(CLIENT_ID, CLIENT_SECRET);
// Create an audio fingerprint from input file
$ft = $client->fingerprintFile(INPUT_FILE, [Pex\FingerprintType::Audio]);
// Ingest FT into Custom Database
$client->ingest(PROVIDED_ID, $ft);
const pex = require("pex-sdk");
const CLIENT_ID = "#YOUR_CLIENT_ID_HERE";
const CLIENT_SECRET = "#YOUR_CLIENT_SECRET_HERE";
const INPUT_FILE = "/path/to/file.mp3";
const PROVIDED_ID = "PROVIDED_ID";
async function main() {
try {
// Initialize and authenticate the client
let client = new pex.PrivateSearchClient(CLIENT_ID, CLIENT_SECRET)
// Connect to the PrivateSearch server. This operation is asynchronous and
// returns a promise, just like most operations in this package.
await client.connect()
// Create an audio fingerprint from input file
let ft = await client.fingerprintFile(INPUT_FILE, [pex.AUDIO])
// Ingest Asset
await client.ingest(PROVIDED_ID, ft)
} catch (error) {
console.error("An error occurred:", error);
}
}
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()
package main
import (
"encoding/json"
"fmt"
pex "github.com/Pexeso/pex-sdk-go/v4"
)
const (
clientID = "#YOUR_CLIENT_ID_HERE"
clientSecret = "#YOUR_CLIENT_SECRET_HERE"
providedID = "PROVIDED_ID"
)
func main() {
// Initialize and authenticate the client
client, err := pex.NewPrivateSearchClient(clientID, clientSecret)
if err != nil {
panic(err)
}
defer client.Close()
// Archive FT
if err := client.Archive(providedID); err != nil {
panic(err)
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
const CLIENT_ID = "#YOUR_CLIENT_ID_HERE";
const CLIENT_SECRET = "#YOUR_CLIENT_SECRET_HERE";
const PROVIDED_ID = "PROVIDED_ID";
// Initialize and authenticate the client
$client = new Pex\PrivateSearchClient(CLIENT_ID, CLIENT_SECRET);
// Create an audio fingerprint from input file
$ft = $client->fingerprintFile(INPUT_FILE, [Pex\FingerprintType::Audio]);
// Ingest FT into Custom Database
$client->archive(PROVIDED_ID);
const pex = require("pex-sdk");
const CLIENT_ID = "#YOUR_CLIENT_ID_HERE";
const CLIENT_SECRET = "#YOUR_CLIENT_SECRET_HERE";
const PROVIDED_ID = "PROVIDED_ID";
async function main() {
try {
// Initialize and authenticate the client
let client = new pex.PrivateSearchClient(CLIENT_ID, CLIENT_SECRET)
// Connect to the PrivateSearch server. This operation is asynchronous and
// returns a promise, just like most operations in this package.
await client.connect()
// Archive Asset
await client.archive(PROVIDED_ID)
} catch (error) {
console.error("An error occurred:", error);
}
}
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()
package main
import (
"encoding/json"
"fmt"
pex "github.com/Pexeso/pex-sdk-go/v4"
)
const (
clientID = "#YOUR_CLIENT_ID_HERE"
clientSecret = "#YOUR_CLIENT_SECRET_HERE"
)
func main() {
// Initialize and authenticate the client
client, err := pex.NewPrivateSearchClient(clientID, clientSecret)
if err != nil {
panic(err)
}
defer client.Close()
// List FTs
lister := client.ListEntries(&pex.ListEntriesRequest{})
for lister.HasNextPage {
entries, err := lister.List()
if err != nil {
panic(err)
}
for _, entry := range entries {
fmt.Println(entry)
}
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
const CLIENT_ID = "#YOUR_CLIENT_ID_HERE";
const CLIENT_SECRET = "#YOUR_CLIENT_SECRET_HERE";
const INPUT_FILE = "/path/to/file.mp3";
const PROVIDED_ID = "PROVIDED_ID";
// Initialize and authenticate the client
$client = new Pex\PrivateSearchClient(CLIENT_ID, CLIENT_SECRET);
// Create an audio fingerprint from input file
$ft = $client->fingerprintFile(INPUT_FILE, [Pex\FingerprintType::Audio]);
// List Assets
$lister = $client->listEntries(new Pex\ListEntriesRequest());
while ($lister->hasNextPage()) {
$entries = $lister->list();
foreach ($entries as $entry) {
echo json_encode($entry, JSON_PRETTY_PRINT) . PHP_EOL;
}
}
const pex = require("pex-sdk");
const CLIENT_ID = "#YOUR_CLIENT_ID_HERE";
const CLIENT_SECRET = "#YOUR_CLIENT_SECRET_HERE";
async function main() {
try {
// Initialize and authenticate the client
let client = new pex.PrivateSearchClient(CLIENT_ID, CLIENT_SECRET)
// Connect to the PrivateSearch server. This operation is asynchronous and
// returns a promise, just like most operations in this package.
await client.connect()
// List entries
let lister = client.listEntries({});
while (await lister.hasNextPage()) {
let entries = await lister.list();
for (const entry of entries) {
console.log(entry);
}
}
} catch (error) {
console.error("An error occurred:", error);
}
}
main()
Last updated