Related to mass import of video files and Mass video node creation and transcoding.

Can be useful if you have huge amount of videos to import(and/or you don't need original files stored on your server), or you need import videos listed by html pages or rss feeds ... Sources for import are with Feeds nearly unlimited.
Required: Feeds, and for encoding without local copy also Media and Media Feeds

  • in media_feeds.module (Media Feeds module)
    after line 26
    if (module_exists('image')) {
        $field_types[] = 'image';
      }

    we need

    if (module_exists('video')) {
    $field_types[] = 'video';
      }
    /
  • This adds ability for video field mapping in Feeds. As provider can be used Remote stream wrapper for http://, https://, feed://, and probably also for public:// and private:// .

If you need local copy of original file in your system, you can try slightly modified

  • /mappers/file.inc from Feeds Module
    replace line 11
    if (in_array($info['type'], array('file', 'image'))) {
    

    with

    if (in_array($info['type'], array('file', 'image', 'video'))) {
    

    This (import with local copy) works without any of following modifications.

OK, we can import our nodes with Feeds now, and they are also added to video queue...

Issue 1: Thumbnails are not created.
Issue 2: We need path, where encoded files should be stored (only for files without local copy)
Issue 3: We need set default dimensions for video_queue table

  • video_field.inc
    (solves issue 1)
    after line 1217
    else {
    		drupal_set_message(t('Transcoding job was successfully queued for %transcoder-name. The video %video-name will be converted soon.', array('%transcoder-name' => $transcoder->getTranscoder()->getName(), '%video-name' => $video->filename)));
        }
    

    insert

    // if video was not created through the form, we probably need generate thumbnails. 
     // if thumbnail(s) already exists or autocreation for thumbnails is disabled, do nothing.
    	if (empty($item['thumbnail']) && $field['settings']['autothumbnail'] == 'auto' && $transcoder->hasTranscoder() ) {
    		$thumbs = $transcoder->extractFrames($item, $field);
    			if ($thumbs === FALSE) {
    			  drupal_set_message('Thumbnails creation for '.$video->filename.' failed','error');
    			}
    			else {
    			 drupal_set_message('Thumbnails successfully created for '.$video->filename.'.','status');
    			}
    		}
    
  • transcoder.inc
    (solves isue 2)
    after line 145
    $this->transcoder->setInput((array) $video);
        $transcodingsuccess = TRUE;
        $output = array();
    

    delete

    $output_directory = str_replace('original', 'converted', drupal_dirname($video->uri)) . '/' . $video->fid;
    $output_directory = $converted_scheme . '://' . file_uri_target($output_directory);
    

    and insert

    // Set output directory for converted files
    	// for following operations, we need 'file_directory' prefix from current bundle
    	$entity = entity_load('node', array("$video->entity_id"));
    	$entity = reset($entity);
    	list(, , $bundle) = entity_extract_ids('node', $entity);
    	$instance = field_info_instance('node', $video->data['field_name'], $bundle);
    	$fdirectory = $instance['settings']['file_directory'];
    	
    	// if path not contains 'file_directory' string (probably because original video has been not copied to local file system)
    	if ((!empty($fdirectory)) && strpos(drupal_dirname($video->uri), $fdirectory) === false){
    	// replace last path level from file_directory with '/imported' or add '/imported' if only one level found ... 
    	if (strrpos($fdirectory,'/') !== false){
    	$fdirectory = substr($fdirectory, 0, strrpos($fdirectory,'/')).'/imported';
    	}
    	
    	//... and append source path and fid
    	$output_directory = $fdirectory . '/'. file_uri_target(drupal_dirname($video->uri)) . '/' . $video->fid;
    	$output_directory = $converted_scheme . '://' . $output_directory;
    	}
    	else {
    	// original behaviour for videos with original files in local file system
    	$output_directory = str_replace('original', 'converted', drupal_dirname($video->uri)) . '/' . $video->fid;
    	$output_directory = $converted_scheme . '://' . file_uri_target($output_directory);
    	}
    
  • video_field.inc
    (solves issue 3)
    somewhere by line 1200
    replace
    // @todo get the default dimension when not available in $item
    with
    // get the default dimension when not available in $item
    	  $info_instance = field_info_instance('node', $field['field_name'], $bundle);
    	  if (empty($item['dimensions'])) {
    	  	  $item['dimensions'] = $info_instance['settings']['default_dimensions'];
    		  }
    
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MilosL’s picture

Status: Needs review » Needs work

The last submitted patch, 1: video-mediafeeds-2131809-1.patch, failed testing.

MilosL’s picture

Status: Needs work » Needs review
Related issues: +#2132079: Mapper for Video module files, +#2132063: Feeds integration: mapper
FileSize
5.21 KB

Added allowed file extensions check and some code improvements.

Status: Needs review » Needs work

The last submitted patch, 3: video-mediafeeds-2131809-2.patch, failed testing.

MilosL’s picture

Status: Needs work » Needs review
FileSize
5.78 KB

Improved file validation.

Status: Needs review » Needs work

The last submitted patch, 5: video-mediafeeds-2131809-3.patch, failed testing.

MilosL’s picture

Status: Needs work » Needs review
FileSize
5.76 KB
heshanlk’s picture

Status: Needs review » Fixed

  • heshanlk committed e845ebb on 7.x-2.x authored by MilosL
    Issue #2131809 by MilosL: Integration with Media Feeds for bulk import...

Status: Fixed » Closed (fixed)

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