Create Video node programmatically

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
Airborn's picture

Dear,

I would like to ask for some help regarding the topic mentioned in the title. My objective is to record a video through a webcam and pass it somehow to the Video module and create a Video node out of it. I can already upload videos to the module and transcode it through Zencoder and I'm already solved the recording part with the "Media: Webcam" module (https://drupal.org/project/media_webcam) but I don't know how to connect those two and pass the recorded video to the Video module.

Can you help me with this?

Thank you,
Alex

Comments

I tried to make a small

Airborn's picture

I tried to make a small extension which gets the node before save with the hook_node_presave() but I don't know exaclty how to convert it to a Video node :S

Okay it seems to be solved

Airborn's picture

Okay it seems to be solved with this small hack:

function webcam_video_converter_node_presave($node) {
    if ($node->type = 'webcam') {
        $node->type = 'video';
        $node->field_video['und'][0] = array_merge($node->field_webcam['und'][0], array(
            'display' => 1,
            'dimensions' => '1280x720',
            'convert_video_on_save' => 1,
            'bypass_autoconversion' => 0,
            'use_default_video_thumb' => 0,
            'conversionstatus' => NULL,
            'thumbnail' => 0,
        ));
    }
}

If you have a better solution, please inform me :)

Alex

There is a strange behavious

Airborn's picture

There is a strange behavious while using this code. The files are transcoded they are moved to S3 and after a time they are disappearing from there. I can't understand the reason.

I think it was because of a

Airborn's picture

I think it was because of a mistype in the if statement. Of course we need == insted of = :)
But I will test it a bit.

And the thumbnails are not

Airborn's picture

And the thumbnails are not created.

This one is also fixed by the

Airborn's picture

This one is also fixed by the fix above

Video

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: