Indexes, videos, and tasks
The endpoints that return lists of items support filtering. The examples in this section are specific to listing your video indexing tasks. The same principles apply to other similar endpoints.
Note
Depending on the endpoint, you can filter on various fields. For details, see the API Reference section.
Prerequisites
- You're familiar with the concepts that are described on the Platform overview page.
- You've already created an index and uploaded at least one video to it.
Examples
Filter on a specific date
The following example code uses the created_at
parameter to return all the tasks created on a specific date:
from twelvelabs import TwelveLabs
client = TwelveLabs(api_key="<YOUR_API_KEY>")
tasks = client.task.list_pagination(
created_at="2022-05-17"
)
# Utility function to print a specific page
def print_page(page):
for task in page:
print(f"id={task.id} status={task.status} created_at={task.created_at}")
print_page(tasks.data)
while True:
try:
print_page(next(tasks))
except StopIteration:
break
import { TwelveLabs, Task } from 'twelvelabs-js';
const client = new TwelveLabs({ apiKey: '<YOUR_API_KEY>'});
const tasks = await client.task.listPagination({ createdAt: '2022-05-17' });
tasks.data.forEach((task: Task) => {
console.log(`id=${task.id} status=${task.status}`);
});
while (true) {
const nextPageData = await tasks.next();
if (!nextPageData) {
break;
}
nextPageData.forEach((task: Task) => {
console.log(`id=${task.id} status=${task.status} created_at=${task.createdAt}`);
});
}
The following example output was truncated for brevity:
id=6283ab5ef18e21febd160bc3 status=ready created_at=2022-05-17T14:04:14.001Z
id=6283a0a8f18e21febd160bbf status=ready created_at=2022-05-17T13:18:32.388Z
id=6283a00df18e21febd160bbc status=ready created_at=2022-05-17T13:15:57.053Z
Filter based on a file name
To filter based on a file name, use the filename
parameter as shown in the example below:
from twelvelabs import TwelveLabs
client = TwelveLabs(api_key="<YOUR_API_KEY>")
tasks = client.task.list_pagination(
filename="<YOUR_FILENAME>" # Example: filename="01.mp4"
)
# Utility function to print a specific page
def print_page(page):
for task in page:
print(f"id={task.id} status={task.status} created_at={task.created_at} metadata={task.metadata}")
print_page(tasks.data)
while True:
try:
print_page(next(tasks))
except StopIteration:
break
import { TwelveLabs, Task } from 'twelvelabs-js';
const client = new TwelveLabs({ apiKey: '<YOUR_API_KEY>'});
const tasks = await client.task.listPagination({ filename: '<YOUR_FILE_NAME>' }); // Example: filename="01.mp4"
tasks.data.forEach((task: Task) => {
console.log(`id=${task.id} status=${task.status} metadata=${task.metadata}`);
});
while (true) {
const nextPageData = await tasks.next();
if (!nextPageData) {
break;
}
nextPageData.forEach((task: Task) => {
console.log(`id=${task.id} status=${task.status} created_at=${task.createdAt} metadata=${task.metadata}`);
});
}
The following output was truncated for brevity:
id=65e5ae52bb29f13bdd6f37c8 status=ready created_at=2024-03-04T11:19:46.901Z metadata={'filename': '01.mp4', 'duration': 579.12, 'width': 640, 'height': 360}
id=65d46ef879384c4778ab30fa status=ready created_at=2024-02-20T09:20:56.321Z metadata={'filename': '01.mp4', 'duration': 579.12, 'width': 640, 'height': 360}
Filter based on duration
To filter based on the duration of a video, use the duration
parameter. The example below displays all the videos of a specific duration (810
seconds):
from twelvelabs import TwelveLabs
client = TwelveLabs(api_key="<YOUR_API_KEY>")
tasks = client.task.list_pagination(
duration=810
)
# Utility function to print a specific page
def print_page(page):
for task in page:
print(f"id={task.id} status={task.status} created_at={task.created_at} metadata={task.metadata}")
print_page(tasks.data)
while True:
try:
print_page(next(tasks))
except StopIteration:
break
import { TwelveLabs, Task } from 'twelvelabs-js';
const client = new TwelveLabs({ apiKey: '<YOUR_API_KEY>'});
const tasks = await client.task.listPagination({ duration: 810 });
tasks.data.forEach((task: Task) => {
console.log(`id=${task.id} status=${task.status}`);
});
while (true) {
const nextPageData = await tasks.next();
if (!nextPageData) {
break;
}
nextPageData.forEach((task: Task) => {
console.log(`id=${task.id} status=${task.status} created_at=${task.createdAt} metadata=${task.metadata}`);
});
}
The following example output was truncated for brevity:
id=65e5ae52bb29f13bdd6f37c8 status=ready created_at=2024-03-04T11:19:46.901Z metadata={'filename': '02.mp4', 'duration': 810, 'width': 640, 'height': 360}
id=65d46ef879384c4778ab30fa status=ready created_at=2024-02-20T09:20:56.321Z metadata={'filename': '02.mp4', 'duration': 810, 'width': 640, 'height': 360}
Updated 28 days ago