Is there any way to re-queue videos in bulk?

I often need to re-queue existing videos in my development server.
A "Re-queue selected content" option in Update Options at admin/content would be really helpful.
Update Options

Only thing I could find relevant to this topic is #1517998: Mass video node creation and transcoding
Then, I was looking into possible hook_action_info() implementation for the Video module.
Seems like something like below is needed. But I am not really sure what it really involves to make it happen.
Any ideas, or suggestions?

/**
 * Implements hook_action_info().
 */
function video_action_info() {
  return array(
    'video_re_convert_video' => array(
      'type' => 'node',
      'label' => t('Re-queue selected content'),
      'configurable' => FALSE,
      'behavior' => array('changes_property'),
      'triggers' => array('node_presave'),
    ),
  );
}

function video_re_convert_video($node, $context = array()) {
  $factory = new TranscoderAbstractionAbstractFactory();
  $transcoder = $factory->getProduct();

  $video->video_status = VIDEO_RENDERING_INQUEUE;
  $transcoder->updateJob($video);

  watchdog('action', 'Re-queue @type %title to be transcoded.', array('@type' => node_type_get_name($node), '%title' => $node->title));
}

CommentFileSizeAuthor
Screen Shot 2012-09-22 at 2.33.19 PM.png65.03 KBosman
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jorrit’s picture

This is a very good suggestion. In next release (7.x-2.9) I intend to improve rules and token support and I suppose that this feature can be implemented then as well.

michael.k’s picture

If you were to add support for the Views Bulk Operations module, many types of changes could be made in bulk.

Every user has a different mashup of course, but VBO is indispensable in my workflow.

Jorrit’s picture

That was what I was also thinking about. For all that kind of stuff: wait for 2.9.

michael.k’s picture

Sweet!

theamoeba’s picture

I have been working on some code that uses the hook_node_operations hook.

/**
 * Implements hook_node_operations().
 */
function myvideomodule_node_operations() {
  $operations = array(
    'myvideomodule_re_encode_video' => array(
      'label' => t('Re-encode selected videos'),
      'callback' => 'myvideomodule_re_encode_video',
    ),
  );

  return $operations;
}

function myvideomodule_re_encode_video($nodes) {
  foreach ($nodes as $nid) {
    // Load the node.
    $__node = node_load($nid);

    // This only works on video nodes.
    if ($__node->type == 'video') {
      // Get the language code from the node.
      $langcode = $__node->language;

      // Now loop through the video field (field_video).
      foreach ($__node->field_video[$langcode] as $video_obj) {
        drupal_set_message('<pre>'. print_r($video_obj, true) .'</pre>');
        
        // Now we need to talk to the video module and change the status of each file.
        $video = video_jobs::load($video_obj['fid']);

        // Change the video status to pending encoding.
        $video->video_status = VIDEO_RENDERING_PENDING;

        // Set a new update time.
        $video->statusupdated = time();

        // Update the video object.
        video_jobs::update($video);
      }
    }
  }
}
selfsimilar’s picture

Post #5 was a great help. The only issue I had was I needed to change the foreach loop to:

foreach ($__node->field_type_video[$langcode] as $video_obj) {
//...
}
MilosL’s picture

Above code "adapted" for using as "Execute arbitrary PHP Script" in advanced actions - works with VBO (Views Bulk Operations).

$__node = node_load( $entity->nid);
    // Replace "clips" with your video content type
    if ($__node->type == 'clips') {
      // Get the language code from the node.
      $langcode = $__node->language;

      // Now loop through the video field (replace "field_online_clips" with your field containing video).
	  foreach ($__node->field_online_clips[$langcode] as $video_obj) {
       
        // Now we need to talk to the video module and change the status of each file.
        $video = video_jobs::load($video_obj['fid']);

        // Change the video status to pending encoding.
        $video->video_status = VIDEO_RENDERING_PENDING;

        // Set a new update time.
        $video->statusupdated = time();

        // Update the video object.
        video_jobs::update($video);
      }
    }
heshanlk’s picture

Issue summary: View changes
Status: Active » Needs review
chaitanya17’s picture

Hi osman,

In admin/content, we can't have Re-queue selected content option as not all content types will have video field.

Instead we can create separate content type view page that is having video field. And custom bulk operation through rules. In rules we need to define custom code need to be executed, and use @MilosL code.

With status message,

$__node = node_load( $entity->nid);
    // Replace "clips" with your video content type
    if ($__node->type == 'clips') {
      // Get the language code from the node.
      $langcode = $__node->language;

      // Now loop through the video field (replace "field_online_clips" with your field containing video).
	  foreach ($__node->field_online_clips[$langcode] as $video_obj) {
       
        // Now we need to talk to the video module and change the status of each file.
        $video = video_jobs::load($video_obj['fid']);

        // Change the video status to pending encoding.
        $video->video_status = VIDEO_RENDERING_PENDING;

        // Set a new update time.
        $video->statusupdated = time();

        // Update the video object.
        video_jobs::update($video);
      }
    }
 if ($video != '0') {
    drupal_set_message(t("Selected videos are successfully requeued for transcoding."), "success");
  }
  else {
    drupal_set_message(t("Videos requeuing failed or the videos are not yet transcoded. Please try again"), "error");
  }
heshanlk’s picture

Status: Needs review » Postponed