Fetching of all media inside a parent category

Hello,

So I am trying to retrieve a list of all media under a category with some subcategories.

For example, I have a parent category, Main which has subcategories child_1, child_2…, child_i, where i = 50, and I want all the media from all subcategories.

To do so I make a media.list request and filter on ‘categoryAncestorIdIn’ using the ID for Main. However, this gives me a peculiar response where the media entries returned are not in any of the subcategories.

Am I just using the wrong filter field here? if so which one should I be using?

Also as a side question is there a way to filter out archived/hidden media?

All help is appreciated!

Hi @Jamie ,

However, this gives me a peculiar response where the media entries returned are not in any of the subcategories.

Please explain what you mean by ‘a peculiar response’.

Also as a side question is there a way to filter out archived/hidden media?

Please define ‘archived/hidden’. Feel free to provide sample entry IDs.

Cheers,

Hi @jess,

I think I have got myself muddled up in the first post, hopefully this clears things up.

So In our system, we have some high-level categories for example, ‘Youtube’ which has the subcategories Projects, Careers, Events and so on. Then we have the category I want to query called ‘Trades’ which would include Engineering, Architecture etc.

So let’s say the Category ID for Trades is 123456, so I would use the media.list endpoint and specify in the filter for 'categoryAncestorIdIn’ = 123456, then make the request. This returns entries like this…

{
      ...,
      "id": "1_00o07a38",
      "categories": "Projects",
      "categoriesIds": "56789",
      ...
    },

So as you can see the category given to this media entry is from a completely different category and when I check the subcategories of Trades ‘Projects’ is not one of them. Then when I look at the video itself in the KMC it says it is in the ‘Projects’ Category as well as ‘Engineering’ which is a subcategory of Trade.

So the real question is, how to have the categories field provide all the related categories or even better only the categories that are subcategories of the ancestor ID.

Please define ‘archived/hidden’. Feel free to provide sample entry IDs.

So I believe there is an option to make media ‘unlisted’ in Kaltura, when you request media from the API is this unlisted media returned?

Thanks,

Hi @Jamie ,

1_00o07a38 is returned because it is associated with a sub category under the YouTube category (that’s not its exact name but since that’s how you referred to it, I’m doing the same) so yes, if you passed the “YouTube” cat ID in KalturaMediaEntryFilter.categoryAncestorIdIn when calling media.list(), the response will include it. If you passed something else, I’ll need you to share the exact value. Post the full KalturaMediaEntryFilter object you passed in the media.list() payload.

For reference, here are the category related members that are available to you on the KalturaMediaEntryFilter object:

categoriesFullNameIn
categoriesIdsMatchOr
categoriesMatchOr
categoriesIdsEmpty
categoriesIdsNotContains
categoriesNotContains
categoriesIdsMatchAnd
categoriesMatchAnd
categoryAncestorIdIn

As to unlisted, I’d say that, in a sense, it’s almost the exact opposite of hidden, as the KMS UI reads:

Media will be visible to anyone with a link to the [KMS entry] page.

I agree that the phrasing may be somewhat confusing.

Basically, when publishing an entry as unlisted, the entry will be associated with the `MediaSpace>Unlisted’ category.

Cheers,

Hi @jess ,

This is the query I am making…

filter = KalturaMediaEntryFilter()
filter.categoryAncestorIdIn = "19562491"
pager = KalturaFilterPager()
pager.pageSize = 1

result = client.media.list(filter, pager)

I have set the page size to 1 just to make it easy to compare results …

{
  "objects": [
    {
      ...,
      "id": "1_vtbv0tqp", 
      "tags": "bridges, angus low",
      "categories": "People",
      "categoriesIds": "3539951",
      ...
    }
  ]
}

So this is returning media from the Youtube category which is not a subcategory of Skills Networks. Although, when looking at the video in the KMC you can see it is in both. I don’t believe the query is at fault here as I want all the media under this one category even if it is also in another. However, I need the response to list all the categories, which would be “People, Bridge and Civil Structures”.

Is there a way I can achieve this result?

Thanks,

Hi @Jamie ,

I understand your question better now:)

As noted in my previous response, the entry in question (ID 1_vtbv0tqp) should indeed be returned because, among other category associations, it is associated with a sub category that resides under category ID 19562491. I also understand your confusion in light of the fact the KalturaMediaEntry returned in the KalturaMediaListResponse only includes one category in its categories and categoriesIds members. The reason for that is that those two members are deprecated. In order to get ALL category assoc for a given entry, please use the categoryEntry.list() API. For instance:

<?php
  $filter = new KalturaCategoryEntryFilter();
  $filter->entryIdEqual = "1_vtbv0tqp";
  $pager = new KalturaFilterPager();

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

Cheers,

Hi @jess,

I have tried the endpoint you suggested but it gives the same results…

filter = KalturaCategoryEntryFilter()
filter.entryIdEqual = "1_vtbv0tqp"
pager = KalturaFilterPager()

result = client.categoryEntry.list(filter, pager)
print(result)
{
  "objects": [
    {
      "categoryId": 3539951,
      "entryId": "1_vtbv0tqp",
      "createdAt": 1341115200,
      "categoryFullIds": "3539951",
      "status": 2,
      "objectType": "KalturaCategoryEntry"
    }
  ],
  "totalCount": 1,
  "objectType": "KalturaCategoryEntryListResponse"
}

… As you can see it is still only returning the one category ID which works out to be People and does not mention Bridge and Civil Structures

Is there another way to get it?

Thanks,

Hi @Jamie ,

Did you remember to set disableentitlement in the privileges param when generating the KS?

Hi @jess ,

This request was made using the kaltura web API does that set the privileges param?

I have also just tried it in python with the privileges param set to “*,disableentitlement” and got the same result

Hi @Jamie ,

If you mean developer.kaltura.com, then no, it does not (nor should it, it’s not always what one would want).
You can generate a KS with that privilege using https://developer.kaltura.com/console/service/session/action/start (or by any other means) and then set it under Global Parameters when you make the request.
Alternatively, you can use said KS when signing into the console by inputting it under Kaltura Session ID (ks) rather than inputting the username and password.

Hi @jess,

My mistake you were right it was the privileges, my apologies. I have now got it working, currently, the response is something like this…

{
 'categoryFullIds': '9635461>9635471>9635481>19562491>41487211',
 'categoryId': 41487211,
 'createdAt': 1460385870,
 'creatorUserId': '',
 'entryId': '1_vtbv0tqp',
 'relatedObjects': {},
}, 
{...},
{...}

… it is now returning all categories which is great.

Thank you for all the help!

You’re welcome, @Jamie.