Use the PHP API to get a list of uncaptioned videos

I am trying to get a report that lists all of our videos along with whether or not the video has a caption or not. As far as I can tell there is no way to do this through the interface, so I am trying to do it through the API, but am having a hard time getting the information I need.

Any chance someone out there might be willing to put together some sample code that lists the Video ID and some way of indicating whether or not hte video has a caption asset associated with it or not using the API?

Hi,

Here it is:

<?php


if ($argc < 3){
    echo "\nUsage: ".$argv[0] . ' <partner id> <admin secret> <service url>'."\n\n";
    exit (1);
}
require_once('/opt/kaltura/web/content/clientlibs/php5/KalturaClient.php');
$userId = null;
$expiry = null;
$privileges = null;
$partnerId=$argv[1];
$secret = $argv[2];
$type = KalturaSessionType::ADMIN;
$config = new KalturaConfiguration($partnerId);
$config->serviceUrl = $argv[3];
$client = new KalturaClient($config);
$ks = $client->session->start($secret, $userId, $type, $partnerId, $expiry, $privileges);
$client->setKs($ks);

$filter = new KalturaMediaEntryFilter();
$total_media_entries = $client->media->count($filter);
$pager = new KalturaFilterPager();
$page_index=1;
$pager->pageSize = 500;
$processed_entries=0;

while ($processed_entries < $total_media_entries){
    $pager->pageIndex=$page_index;
    $result = $client->media->listAction($filter, $pager);
        foreach ($result->objects as $entry) {
            $processed_entries++;
            $filter = new KalturaAssetFilter();
            $filter->entryIdEqual = $entry->id;
            $pager = null;
            $captionPlugin = KalturaCaptionClientPlugin::get($client);
            $cap_result = $captionPlugin->captionAsset->listAction($filter, $pager);
            if ($cap_result->totalCount){
                echo $cap_result->totalCount. ' found for entry ID: '. $entry->id. "\n\n";
                foreach ($cap_result->objects as $cap_obj) {
                    echo 'Caption lang is: '. $cap_obj->language."\nCaption ID is: ".$cap_obj->id."\n\n";
                }
                echo "==================\n";
            }
        }
    $page_index++;
}

Run like so:

$ captions.php <partner id> <admin secret> <service url>

Sample output:

1 found for entry ID: 0_0cgmx910

Caption lang is: English
Caption ID is: 0_30975jlh

==================
3 found for entry ID: 0_ckl8o219

Caption lang is: English
Caption ID is: 0_bvdv7yor

Caption lang is: English
Caption ID is: 0_hrxr8xdc

Caption lang is: English
Caption ID is: 0_sygf2hu0

==================
1 Like

And if what you want is just an indication of whether or not there are captions attached, just change:

if ($cap_result->totalCount){

to:

if (!$cap_result->totalCount){
  echo "No caption assets\n";
}
1 Like

Thank you so much @jess, I really appreciate your help!

Most welcome:) hope it helps.