Custom metadata for a specific category of video?

Hi,

My organization has a couple of different types of videos, to which different metadata would naturally apply. I had in mind to create a metadata schema for each type, then apply the schemas to the relevant entries. For instance, apply the “Seminar Series” schema to videos of seminars, “News clips” schema to news clips, etc.

I have not figured out how to selectively apply an “Entity” schema only to those items to which it applies. It seems that all items get all of the custom metadata.

Is it possible to be more selective or is it standard practice to attach all metadata fields to all entries?

Hi @bryce_nordgren,

I’m afraid this cannot be done with the custom metadata mechanism.
Once you create a metadataProfile of type ENTRY, it will show for all entries, this cannot be conditioned.

However, determining whether or not you should populate custom data for a given entry is not that hard. You could, for example, set the entry’s ‘tags’ or ‘adminTags’ members and based on that, decide whether to populate a given custom metadata schema or not. Another option is to attach entries to categories and decide according to that, so for instance, if the entry is attached to the category “examples”, the “example” metadata schema should be populated.

@jess working with custom metadata of Entries is slightly different from that of Categories since the Metadata service requires a string type value for objectId parameter. Whereas the categoryId is of type integer. How do you get the metadata associated to a category?

Hi @adeelmiraj,

Below is a full example using the PHP client [can be obtained from https://github.com/kaltura/KalturaGeneratedAPIClientsPHP/archive/v13.20.0.tar.gz].
The objectId param should be the category ID, passed as a string [for PHP specifically, it doesn’t matter since it’s not a strongly typed language]. You didn’t mention your language of choice but the same should work with all our API clients.

<?php
require_once('/path/to/KalturaClient.php');

  $partnerId=;
  $partnerSecret='';
  $userId='';
  $config = new KalturaConfiguration($partnerId);
  $config->serviceUrl = 'https://www.kaltura.com';
  $client = new KalturaClient($config);
  $ks = $client->session->start(
    $partnerSecret,
    $userId,
    KalturaSessionType::ADMIN,
    $partnerId, 
    86400, 
    "disableentitlement");
  $client->setKS($ks);

  $objectType = KalturaMetadataObjectType::CATEGORY;

  // create a metadata profile
  $metadataPlugin = KalturaMetadataClientPlugin::get($client);
  $metadataProfile = new KalturaMetadataProfile();
  $metadataProfile->metadataObjectType = $objectType;
  
  $metadataProfile->createMode = "1";
  $metadataProfile->name = "z1";
  $metadataProfile->systemName = "myz1";
  $xsdData = "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><xsd:element name=\"metadata\"><xsd:complexType><xsd:sequence><xsd:element id=\"md_1FB651DF-20C9-BC17-60B9-6A7E93DBA671\" name=\"Myfield\" minOccurs=\"0\" maxOccurs=\"1\" type=\"textType\"><xsd:annotation><xsd:documentation></xsd:documentation><xsd:appinfo><label>myfield</label><key>myfield</key><searchable>true</searchable><timeControl>false</timeControl><description></description></xsd:appinfo></xsd:annotation></xsd:element></xsd:sequence></xsd:complexType></xsd:element><xsd:complexType name=\"textType\"><xsd:simpleContent><xsd:extension base=\"xsd:string\"></xsd:extension></xsd:simpleContent></xsd:complexType><xsd:complexType name=\"dateType\"><xsd:simpleContent><xsd:extension base=\"xsd:long\"></xsd:extension></xsd:simpleContent></xsd:complexType><xsd:complexType name=\"objectType\"><xsd:simpleContent><xsd:extension base=\"xsd:string\"></xsd:extension></xsd:simpleContent></xsd:complexType><xsd:simpleType name=\"listType\"><xsd:restriction base=\"xsd:string\"></xsd:restriction></xsd:simpleType></xsd:schema>";
  $viewsData = "";

  try {
    $result = $metadataPlugin->metadataProfile->add($metadataProfile, $xsdData, $viewsData);
    $metadataProfileId = $result->id;
    $objectId = ""; //category ID as string
    $xmlData = "<metadata><Myfield>LINUX RULES</Myfield></metadata>";

    try {
        // if created successfully, add metadata 
        $result = $metadataPlugin->metadata->add($metadataProfileId, $objectType, $objectId, $xmlData);
        var_dump($result);
    } catch (Exception $e) {
        echo $e->getMessage();
    }
  } catch (Exception $e) {
    echo $e->getMessage();
  }
  
  // retrieve metadata associated with a given category ID 
  $filter = new KalturaMetadataFilter();
  $filter->metadataObjectTypeEqual = KalturaMetadataObjectType::CATEGORY;
  $filter->objectIdEqual = ""; //category ID as string
  $pager = new KalturaFilterPager();

  try {
    $result = $metadataPlugin->metadata->listAction($filter, $pager);
    var_dump($result);
  } catch (Exception $e) {
    echo $e->getMessage();
  }

?>

You can learn about how to work with custom metadata by going through this tutorial:
https://developer.kaltura.com/workflows/Enrich_and_Organize_Metadata/Working_with_metadata;step=1

This tutorial explains how to work with ENTRY custom metadata objects/records whereas you’ll need to work with CATEGORY metadata but otherwise, the flow is similar and so are the service and action names [endpoints].

Each step also includes code samples.

Thank you so much @jess for the prompt reply. I’m using the Objective-C client library. I wasn’t setting KalturaMetadataObjectType in the KalturaMetadataFilter. Setting the type resolved the issue.