I have 1200 Videos and I would like to transcode and create the nodes programmatically for the videos. Now I am looking for easiest way to solve this issue. The description and the title should later on be created by a friend that helps me. What would be the easiest way to solve this problem? I am open for any hint or idea.

Comments

Jorrit’s picture

Status: Active » Postponed (maintainer needs more info)

At this moment there is no integration with node import modules, unfortunately. Are you using a module to import your content? I may be able to make the Video module compatible with that module.
Also, in what format do you have your video information? Do you have an excel sheet or CSV file with all file names and node title, etc.?

Jorrit’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

I have no experience with mass import myself, because I never needed it. So in order to prepare the Video module for handling mass imports, I need some information as to how the import process is performed apart from the video part. Please reopen this issue or contact me if you have more information.

Drupalized’s picture

sub

broncomania’s picture

The import should create the blank nodes including their videos. The missing content (body,title) should be later inserted for a better workflow. The transcoding can be done by the cron jobs or better drush for processing all the videos at once.

broncomania’s picture

Status: Closed (cannot reproduce) » Active
Jorrit’s picture

I haven't tested the following code, but it should give you an idea:

foreach($fileuris as $fileuri) {
	$fileobject = new stdClass();
	$fileobject->uri = $fileuri;
	$fileobject->filename = basename($fileuri);
	$fileobject->filemime = file_get_mimetype($fileuri);
	$fileobject->uid = 1;
	
	$fileobject = file_save($fileobject);

	$node = new stdClass();
	$node->type = 'yournodetype';
	$node->title = 'Some title';
	$node->uid = 1;
	$node->field_video['und'][0] = array('fid' => $fileobject->fid);

	node_save($node);
}

This code assumes that you have a list of fileuri's (such as s3://yourfile.mp4 or public://yourfile.mp4).

syakely’s picture

I am currently doing this.

What I am doing is moving over all the original files that I want the nodes to use. My nodes already have all the titles, body, users (first I'm importing the users and retaining their uid), Then I have the batch opt, look to see if the file exists, if so, create a file object so it gets saved into file_managed table, then do much as Jorrit has above.

if ($file_exists) {
  $filename = drupal_basename($file_path);
  $uri = 'private://videos/original/'. $filename;
  $file = (object) NULL;
  $file->uid = $data_model->uid;
  $file->fid = '';
  $file->uri = $uri;
  $file->filename = $filename;
  $file->filemime = file_get_mimetype($file_path);
  $file->status = 1;
     
  $file = file_save($file);
  $new_node->field_video['und'][0] = (array)$file;
  }
  // Save the node.
node_save($new_node);

then I'm having cron do the conversions.
One thing to note is that the video dimensions in the video_queue table will not get set when doing this..... not sure how I'm going to handle this..... I might just do a simple query to put it in after migration and before transcoding.

Jorrit’s picture

You don't need to set the status to 1. Attaching the file to a node should be enough, node_save will cause the status to be set. You can set "$new_node->field_video['und'][0]['thumbnail']" to the fid of the thumbnail, if you want.

Tsubo’s picture

I've been working on a slightly different process of migrating existing video files stored in an existing file field, moving them into a video field and processing them via zencoder - and stumbled onto the same issue with the dimensions not being saved in the video_queue when programmatically triggering a node save .

I solved the issue by checking the 'Use preset dimensions for video conversion' in the preset tab of the video module configuration options, and then ensuring that the desired dimensions are correctly specified in the video preset itself.

Hope this helps.

Jorrit’s picture

Tsubo: When you set field_file['und'][0]['dimensions'] to lets say '640x360', doesn't it work?

Tsubo’s picture

To be honest I hadn't actually tried this approach. I had moved our file data from the file field to the video field using SQL, and was purely triggering a node save programmatically to fire off the transcoding process. My issue was that although (default) video dimensions are specified in the video field (manage fields) unless you actually save the node via the UI they are not picked up.

I'm guessing this is because this dimension data is pulled in by the form API. The result I was getting was that no dimension data was being to sent to Zencoder so I was getting a Zencoder 422 error.

However, if you set 'Use preset dimensions for video conversion' this does get picked up on a programmatic node-save....

I'll have a play with doing the whole process programmatically next time :-)

Unless Bronco is still having issues I'm guessing you can close this one.

Tsubo’s picture

Well..... now I think about it. Last statement was not entirely true. Dimension data did get sent to Zencoder this way, but it didn't get written to the 'video_queue' table..... which was odd..... but it worked none the less. :-)

ferrangil’s picture

I will eventually migrate a D5 site with 60.000 videos using op_video module to a D7 site with video module. I will probably re-transcode the videos, to get new thumbnails, more than one transcoded video, etc. I will probably use a custom php file with a code like the one posted here, with node_save's and these kind of things.

Mouser76’s picture

I'm interested in this as well--could someone explain where to put the php code to do a mass import? In my case the videos are already converted, so all I'd really need is the video file upload field and the thumbnail.

hypertext200’s picture

Issue summary: View changes
Status: Active » Closed (works as designed)