Rerun Flavor Generation from all Videos

Hi,

A large part of our Videos in our Kaltura System dont own all Flavors.

I rerun some of the Videos manually over the Entry Investigation Interface.
But we have at least 2500 Videos in our System.

Is there a possibility to automate this?

Dear Raumen837

Hi @Raumen837,

Yes. As a general rule, anything that can be done using the Admin Console can be done via the API because the Admin Console, KMC, KMS and all other Kaltura web I/F make use of the API to accomplish their goals. In Admin Console specifically, there are very exceptions to that rule but flavour conversion is not one of these exceptions:)

If you wish to reconvert all flavours of a specific entry, you can call media->convert(), there is an example for that in the sanity tests: https://github.com/kaltura/platform-install-packages/blob/Lynx-12.5.0/RPM/scripts/postinst/recon.php
That script accepts an entry ID as a param and calls media->convert() passing along the entry ID.
Obviously, you’ll want to change it so it calls media->list() and then iterate over the list of entries calling media->convert() for each. You can see the script passes null as $conversionProfileId and so, the default conversion profile will be used, if you have several profiles, you can pass the profile ID instead of null.

Alternatively, if you only want to reconvert SOME of the flavour assets, you can use flavorAsset->reconvert(), passing along a specific flavour ID.

Here is a simple code sample for iterating over all the media entries and their respective flavour assets:

<?php
if ($argc < 4){
    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 = "disableentitlement";
$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) {
            $filter = new KalturaAssetFilter();
            $filter->entryIdEqual = $entry->id;
            // you can filter and only get flavor assets with certain tags
            //$filter->tagsLike = 'source';
            //$filter->tagsMultiLikeAnd='mobile,web,mbr,ipad,ipadnew';
            // or status
            // $filter->statusIn=
            $pager = null;
            $result = $client->flavorAsset->listAction($filter, $pager);
            echo 'Flavour assets for entry ID '. $entry->id ."\n";
            foreach ($result->objects as $flavour) {
                // currently just printing the ID and tags, here is where you would call flavorAsset->reconvert()
                echo $flavour->id . "\n";
                echo $flavour->tags . "\n";
            }
            $processed_entries++;
        }
    $page_index++;
}

Thanks !
This is what I am looking for :slight_smile: