In views, video duration is showing up as a number of seconds, i.e. 106, 2344, etc... . How do I break it up to display in hours, minutes & seconds?

Comments

timofey’s picture

Title: How do I display video duration in ##:## instead of #,###,###? » [BUG] Duration of the video is
Category: support » bug

I've done some digging, and it looks like it's a BUG. (I've updated the Post Title)

In modules/kaltura/plugins/kaltura_views/kaltura_views.module

    'kaltura_duration' => array(
      'title' => t('kaltura item duration'),
      'help' => t(''),
      'field' => array(
        'handler' => 'views_handler_field_numeric',
        'click_sortable' => FALSE,
      ),
      'filter' => array(
        'handler' => 'views_handler_filter_numeric',
      ),
      'sort' => array(
        'handler' => 'views_handler_sort',
      ),
    ),    

and

    'kaltura_duration' => array(
      'label' => 'kaltura item duration',
      'set_precision' => FALSE,
      'precision' => 0,
      'decimal' => '.',
      'separator' => ',',
      'prefix' => '',
      'suffix' => '',
      'exclude' => 0,
      'id' => 'kaltura_duration',
      'table' => 'node_kaltura',
      'field' => 'kaltura_duration',
      'relationship' => 'none',
    ),

Duration is handled as views_handler_field_numeric, causing duration to become #,###,### instead of ##:##:##.

A temporary fix can be to handle duration as a string and convert mysql duration field from INT to TIME

timofey’s picture

Title: [BUG] Duration of the video is » [BUG] Duration of the video is displayed as numeric
timofey’s picture

Status: Active » Patch (to be ported)

I just made a fix. I don't know how to make the patches yet;) sorry...

Open modules/kaltura/plugins/kaltura_views/kaltura_views.module
On line 123, replace
'handler' => 'views_handler_field_numeric',
with
'handler' => 'views_handler_field_kaltura_duration',

Add the following code to line 330, right after class views_handler_field_kaltura_thumb extends views_handler_field { ... }

/*
 * Declaration of new field handler that extends the basic field handler of views module
 * We want to theme the duration field ourselvs.
 */
class views_handler_field_kaltura_duration extends views_handler_field {
  function theme($data) {
    $secs = $data->node_kaltura_kaltura_duration;
      if ($secs > 60*60) { $hr = (int)($secs/60); $hr = ($hr < 10)? '0'. $hr: $hr; $min = (int)($secs/60/60); $min = ($min < 10)? '0'. $min: $min; $sec = (int)(($secs/60)%60); $sec = ($sec < 10)? '0'. $sec: $sec; $durationoutput = ($hr .':'. ($min) .':'. ($sec)); }
      else { $min = (int)($secs/60); $min = ($min < 10)? '0'. $min: $min; $sec = (int)($secs%60); $sec = ($sec < 10)? '0'. $sec: $sec; $durationoutput = ($min .':'. ($sec)); }
    return theme('node_kaltura_entry_duration', $durationoutput);
  }
}

Open modules/kaltura/plugins/node_kaltura_entry/node_kaltura_entry.module
Add this to line 398:

    'node_kaltura_entry_duration' => array(
      'arguments' => array('themeParams' => NULL),
    ),

Add this to line 563 (used to be line 560)

  $node->content['kaltura_duration'] = array(
    '#value' => theme('node_kaltura_entry_duration', $durationoutput),
    '#weight' => 0,
  );

Add this to line 639 (used to be line 632)

/*
 * function to render the duration field into HTML
 */
function theme_node_kaltura_entry_duration($durationoutput) {
    return $durationoutput;
}

That's all folks.

jweedman’s picture

BAM! Worked like a charm!

Thanks for your greatly detailed fix. Saved me a ton of time!

oferc’s picture

Version: 6.x-1.4 » 6.x-1.5
Status: Patch (to be ported) » Fixed

We have released a new version of the Drupal module that works with Kaltura’s new platform version - Andromeda.

The new module should solve the issue discussed here, and it also includes great new and exciting features at
http://www.kaltura.org/features-coming-next-version

The new version is now available for download at http://drupal.org/project/kaltura#downloads.

If you wish to upgrade an existing account and migrate your content, you can learn more in our forums , or contact us for assistance at http://corp.kaltura.com/about/contact

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.