You are here

function video_ffmpeg_helper_nodeapi in Video 5

Same name and namespace in other branches
  1. 6 plugins/video_ffmpeg_helper/video_ffmpeg_helper.module \video_ffmpeg_helper_nodeapi()
  2. 6.2 plugins/video_ffmpeg_helper/video_ffmpeg_helper.module \video_ffmpeg_helper_nodeapi()

Implementation of hook_nodeapi()

NOTE: video_ffmpeg nodeapi is executed after video_player rendering

File

plugins/video_ffmpeg_helper/video_ffmpeg_helper.module, line 238
Provide some api for use ffmpeg. Simplify video nodes creation.

Code

function video_ffmpeg_helper_nodeapi(&$node, $op, $teaser) {
  if ($node->type == 'video' && $node->vtype == 'upload') {
    switch ($op) {
      case 'load':

        // let's check if we have a valid encoded video
        if (isset($node->serial_data['video_encoded_fid']) && is_numeric($node->serial_data['video_encoded_fid']) && $node->serial_data['video_encoded_fid'] > 0) {

          // this video have an encoded version. let's use it insted of the original one. We can safely do this as video_ffmpeg_helper will be scheduled by Drupal after video and video_upload modules
          $output = array();
          $file = _video_upload_get_file($node->serial_data['video_encoded_fid']);
          $output['current_video_rendered_file'] = $file;
          $output['vidfile'] = file_create_url($file->filepath);

          // set the filesize
          $output['size'] = $file->filesize;
          return $output;
        }

        //print $node->serial_data['video_encoded_fid']; die;
        if (variable_get('video_ffmpeg_helper_auto_resolution', false) || variable_get('video_ffmpeg_helper_auto_playtime', false)) {
          _video_ffmpeg_helper_get_video_info($node);
        }
        break;
      case 'submit':
        break;
      case 'update':

        /* delete the already existing batch script, we'll recreate it below */
        if (variable_get('video_ffmpeg_helper_auto_conversion', false)) {
          db_query('DELETE FROM {video_rendering} WHERE vid = %d AND nid = %d', $node->vid, $node->nid);
        }

      /* FALLTHROUGH */
      case 'insert':
        if (variable_get('video_ffmpeg_helper_auto_conversion', false) && $node->new_video_upload_file_fid > 0 && !$node->video_ffmpeg_helper_convertion_bypass) {

          // add rendering job to queue
          _video_ffmpeg_helper_add_rendering($node);
        }
        break;
      case 'prepare':

        // for future uses
        break;
      case 'view':
        if ($teaser == FALSE) {
          if (_video_ffmpeg_helper_is_being_processed($node)) {

            // if the video is still being processed we display a "rendering in progress" message
            $node->content['video_player']['#value'] = theme('video_ffmpeg_helper_inprogress', $node);
          }
          else {
            if ($node->serial_data['video_encoded_fid'] == -1) {

              // conversion failed
              $node->content['video_player']['#value'] = theme('video_ffmpeg_helper_encoding_failed', $node);
            }
          }
        }

        //print_r($node); die;
        break;
      case 'alter':

        // for future uses
        break;
      case 'delete':
        db_query('DELETE FROM {video_rendering} WHERE vid = %d AND nid = %d', $node->vid, $node->nid);
        if ($node->serial_data['video_encoded_fid'] > 0) {
          $file = _video_upload_get_file($node->serial_data['video_encoded_fid']);
          _video_upload_delete_file($file);
        }
        break;
    }
  }
}