How to get all media entries order by lastPlayedAt in PHP


I am using the php5.3 SDK:
We have 90k media entries, but I can only got 20k entries. The following code is straight forward. Could anyone help me out?

// Main entry point
public function mywrite(Route $route, Console $console)
// Max records is 500, the range cannot be too big.
$range = 3600 * 24;
$this->__mywrite($route, $console, $range);

// Count how many objects we can get
// $veryStartDate == 1446173087, sep 2015
// $maxDate == 1526469375, may 2018
public function __mywrite($route, $console, $range) {
$configObj = $this->readMyWriteHistoryConfigFile();
$lastProcessObj = $this->readMyWriteLastProcessFile();

$veryStartDate = $configObj->veryStartDate;
$maxDate = $configObj->maxDate;

// Set start Date
$startDate = $veryStartDate;
$endDate = $startDate + $range;

$totalCount = 0;
while($startDate <= $maxDate) {
    $objs = $this->listMediaByLastPlay($startDate, $endDate);

    $totalCount += count($objs);

    echo "\n$startDate - $endDate:\n";
    echo "\n". count($objs). "\n";

    $startDate = $endDate + 1;
    $endDate = $endDate + $range;
} // end while loop

// we get like 25k records, but we have 90k records....
echo "\ncount: $totalCount\n";

 // we call the client and get records by start last play date and end last play date
 public  function listMediaByLastPlay($startDate, $endDate) {
    // Page size
    $pageSize = 1000;
    // Client with admin
    $client = $this->getClient(\KalturaSessionType::ADMIN);
    // media
    $mediaObj = $client->media;

    // Set a range to pull, order by last played at
    $filter = new \KalturaMediaEntryFilter();
    $filter->lastPlayedAtGreaterThanOrEqual = $startDate;
    $filter->lastPlayedAtLessThanOrEqual = $endDate;
    $filter->orderBy = '+lastPlayedAt';

    // We still want more records
    $pager = new \KalturaFilterPager();
    $pager->pageSize = $pageSize;

    // now list.....
    $arr = $mediaObj->listAction($filter, $pager)->objects;
    $buf = array();

    foreach($arr as $k => $v) {
      $t = array();

      $t['dataUrl'] = $v->dataUrl;
      $t['flavorParamsIds'] = $v->flavorParamsIds;

      $t['plays'] = $v->plays;
      $t['views'] = $v->views;
      $t['lastPlayedAt'] = $v->lastPlayedAt;

      $buf[] = $t;

    return $buf;


Since you’re filtering by lastPlayedAtGreaterThanOrEqual and incrementing it in every request you should be able to list all your entries that ever played.
If you want to list all your entries, you can filter be create date instead.


I changed the filter to createdDate. I only got 50k records.

Even after set the privilege.

$priv = 'edit:*,sview:*,list:*,download:*,downloadasset:*,edituser:*,disableentitlement,privacycontext:*';
$this->client = $this->getClient(\KalturaSessionType::ADMIN, $priv);

No category filter (90k records)
(can only post 1 image)

I selected all categories (including sub categories, I think), but only 50k records

The 50k records remind that it is equivalent what I am currently doing. i.e. some categories are not involved and there are entries inside them.

If I select all categories in the image above, I can get 90k records.

Any idea?

Hi @kenpeter,

I’m not sure I understand the current situation… are you saying that when you make a media->list() [or baseEntry->list() if done via KMC] request without using the KalturaMediaEntryFilter and setting one of the following members/criteria:


You get back ~90,000 records and when passing one of the category filters you are getting ~50,000?
If so, that’s certainly possible since entries do not have to be attached to a category in order to be available/playable.

In terms of privileges, passing “disableentitlement” should be enough and this is what KMC does as well.
If you’re interested in how the content entitlement mechanism is implemented, please have a look here:

Passing disableentitlement in privileges when generating a KS will disable that mechanism entirely, thus returning ALL entries and categories, regardless of their entitlement configuration.


Thank for reply.

Done via KCM:
90k records. Only select “all categories”, nothing else.

50k records. Only select those visible categories.

Your point is correct that, media no need to attached to category.

for disableentitlement
If you look at my code just above your results.

$priv = ‘edit:,sview:,list:,download:,downloadasset:,edituser:,disableentitlement,privacycontext:*’;
$this->client = $this->getClient(\KalturaSessionType::ADMIN, $priv);

I did involved disableentitlement with others, still get 50k.
If I only involve disableentitlement, still get 50k.

Any idea?

HI @kenpeter,

Let’s start by checking the results you get when using [see my reply to you on the other thread you started].
If this returns the expected results, then you should compare it against what you’re doing in your own code [feel free to share the full code you’re running after verifying]. If it doesn’t return the expected results, seeing how you are a paying Kaltura customer, I suggest you open a ticket with our support team. This is because further investigation of your specific content should not be discussed in a public forum such as this one, of course.

Two additional points to consider here:

  • Like I said, KMC calls baseEntry->list(), not media->list(). If all your entries are media entries [videos, audio files, images] then that shouldn’t make a difference. If you have other type of entries associated with your partner, it might:)
  • Unless specified otherwise by setting one of the below members of KalturaMediaEntryFilter: