繁体   English   中英

如何在Kaltura中检索超过10k标记的所有媒体条目?

[英]How to retrieve all media entries in Kaltura, beyond the 10k mark?

我正在使用php5.3 SDK: https : //github.com/kaltura/KalturaGeneratedAPIClientsPHP53我们有90k媒体条目,但我只能有20k条目。 以下代码简单明了。 有人可以帮我吗?

// 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;

}

您在每个响应的第一页上进行迭代,可能会有一个以上的页面。 kaltura ListResponse具有totalCount属性。 因此您的代码应类似于:

$pager = new \KalturaFilterPager();
$pageIndex = 1;
$entriesGot = 0;
$buf = array();

do
{
     $pager->pageSize = $pageSize;
     $pager->pageIndex = $pageIndex++;

     // now list.....
     $response = $mediaObj->listAction($filter, $pager);
     $arr = $response->objects;
     $entriesGot += count($arr);

     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;
}
}while($entriesGot < $response->totalCount);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM