From 7235ebc06e881ebefe1d2c45a3b0f5304e26b936 Mon Sep 17 00:00:00 2001 From: Heshan Date: Sun, 6 Mar 2011 23:22:38 +0530 Subject: Completed general video upload with Video field and auto thumbnails creation using FFMPEG --- css/video.css | 11 +- includes/preset.inc | 8 +- includes/transcoder.inc | 37 +- includes/video.field.inc | 424 ++++++++++++++++++++ includes/video.preset.inc | 22 +- includes/video_helper.inc | 10 +- modules/video_zencoder/includes/zencoder.inc | 2 +- .../video_zencoder/transcoders/video_zencoder.inc | 2 +- modules/video_zencoder/video_zencoder.module | 2 +- theme/video-play-html5.tpl.php | 6 +- transcoders/video_ffmpeg.inc | 17 +- video.css | 14 - video.field.inc | 425 --------------------- video.info | 1 + video.install | 39 +- video.module | 97 ++--- video_preset/.cvsignore | 1 - 17 files changed, 589 insertions(+), 529 deletions(-) create mode 100644 includes/video.field.inc delete mode 100644 video.field.inc delete mode 100644 video_preset/.cvsignore diff --git a/css/video.css b/css/video.css index b880ea3..51d59d2 100644 --- a/css/video.css +++ b/css/video.css @@ -130,4 +130,13 @@ br.video_image_clear { display/**/: none; } - \ No newline at end of file +div.video-preview { + float: left; /* LTR */ + padding: 0 10px 10px 0; /* LTR */ +} +div.video-widget-data { + float: left; /* LTR */ +} +div.video-widget-data input.text-field { + width: auto; +} diff --git a/includes/preset.inc b/includes/preset.inc index 30ea6ac..52d814b 100644 --- a/includes/preset.inc +++ b/includes/preset.inc @@ -27,7 +27,7 @@ class video_preset { $form['video_preset'] = array( '#markup' => t('No Preset were found. Please use the !create_link link to create a new Video Preset, or upload an existing Feature to your modules directory.', - array('!create_link' => l(t('Create Video Preset'), 'admin/structure/video/add'))), + array('!create_link' => l(t('Create Video Preset'), 'admin/config/media/video/presets/add'))), '#prefix' => '
', '#suffix' => '
', ); @@ -35,7 +35,7 @@ class video_preset { } $preset = array(); foreach ($presets as $id => $value) { - $preset[$id] = $value['name'] . ' ' . l(t('edit'), ('admin/structure/video/preset/' . $value['name'])); + $preset[$id] = $value['name'] . ' ' . l(t('edit'), ('admin/config/media/video/presets/preset/' . $value['name'])); // $help[] = $value['name'] . ' - ' . $value['description'] . ' ' . l(t('edit'), preset_get_preset_path('video', $value['name'])); } @@ -47,8 +47,8 @@ class video_preset { '#description' => t('Please use the !manage_link link to manage Video Presets. Use the !create_link link to create a new Video Preset, or upload an existing Feature to your modules directory.', - array('!manage_link' => l(t('Manage Video Preset'), 'admin/structure/video'), - '!create_link' => l(t('Create Video Preset'), 'admin/structure/video/add'))), + array('!manage_link' => l(t('Manage Video Preset'), 'admin/config/media/video/presets'), + '!create_link' => l(t('Create Video Preset'), 'admin/config/media/video/presets/add'))), '#prefix' => '
', '#suffix' => '
', ); diff --git a/includes/transcoder.inc b/includes/transcoder.inc index dee668d..a57fe91 100644 --- a/includes/transcoder.inc +++ b/includes/transcoder.inc @@ -6,9 +6,6 @@ * * @todo need more commenting * - Add Metadata support - * Add autoloading - * # http://stackoverflow.com/questions/3343208/php-class-lazy-loading - * # http://php.net/manual/en/language.oop5.autoload.php * */ @@ -57,11 +54,41 @@ class video_transcoder { } public function generate_thumbnails($video) { - return $this->transcoder->generate_thumbnails($video); + // Save thiumnails to the vide_thumbnails table + $thumbnails = array(); + $vid = $video['fid']; + $thumbs = $this->transcoder->generate_thumbnails($video); + foreach ($thumbs as $file) { + $existing_file = file_load_multiple(array(), array('uri' => $file->uri)); + if ($existing_file) // check thumbnail file exists + $file = (array) $existing_file; + else { // create new file entries for thumbnails + drupal_write_record('file_managed', $file); + $file = file_load_multiple(array(), array('uri' => $file->uri)); + } + if (!empty($file)) + $thumbnails = array_merge($file, $thumbnails); + } + $exists = db_query('SELECT 1 FROM {video_thumbnails} WHERE vid = :vid', array(':vid' => $vid))->fetchField(); + if ($exists == FALSE) { // returns TRUE is there is a record. + $insertquery = db_insert('video_thumbnails') // Table name no longer needs {} + ->fields(array( + 'vid' => $vid, + 'thumbnails' => serialize($thumbnails), + )) + ->execute(); + } else { + $updatequery = db_update('video_thumbnails') + ->fields(array( + 'thumbnails' => serialize($thumbnails), + )) + ->condition('vid', $vid) + ->execute(); + } + return unserialize(db_query('SELECT thumbnails FROM {video_thumbnails} WHERE vid = :vid', array(':vid' => $vid))->fetchField()); } public function convert_video(&$video) { - module_load_include('inc', 'video', '/includes/preset'); $video_preset = new video_preset(); $presets = $video_preset->properties(); $video->presets = $presets; diff --git a/includes/video.field.inc b/includes/video.field.inc new file mode 100644 index 0000000..a342bc4 --- /dev/null +++ b/includes/video.field.inc @@ -0,0 +1,424 @@ + array( + 'label' => t('Video'), + 'description' => t('This field stores the ID of an video file as an integer value.'), + 'settings' => array( + 'uri_scheme' => variable_get('file_default_scheme', 'public'), + 'autoconversion' => 0, + 'autothumbnail' => 'no', + 'default_video_thumbnail' => 0, + 'preview_video_thumb_style' => 'thumbnail', + ), + 'instance_settings' => array( + 'file_extensions' => 'mp4 ogg avi mov wmv flv', + 'file_directory' => 'videos/original', + 'max_filesize' => '', + 'default_dimensions' => '640x350', + 'default_player_dimensions' => '640x350' + ), + 'default_widget' => 'video_upload', + 'default_formatter' => 'video', + ), + ); +} + +/** + * Implements hook_field_settings_form(). + */ +function video_field_settings_form($field, $instance) { + $defaults = field_info_field_settings($field['type']); + $settings = array_merge($defaults, $field['settings']); + $scheme_options = array(); + foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) { + $scheme_options[$scheme] = $stream_wrapper['name']; + } + $form['uri_scheme'] = array( + '#type' => 'radios', + '#title' => t('Upload destination'), + '#options' => $scheme_options, + '#default_value' => $settings['uri_scheme'], + '#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'), + ); + $form = $form + video_default_field_settings($settings); + return $form; +} + +/** + * Element specific validation for video default value. + * + */ +function video_field_default_thumbnail_validate($element, &$form_state) { + $settings = $form_state['values']['field']['settings']; + // Make the file permanent and store it in the form. + if (!empty($settings['default_video_thumbnail']['fid'])) { + $file = file_load($settings['default_video_thumbnail']['fid']); + $file->status |= FILE_STATUS_PERMANENT; + $file = file_save($file); + $form_state['values']['field']['settings']['default_video_thumbnail'] = (array) $file; + } +} + +/** + * Implements hook_field_instance_settings_form(). + */ +function video_field_instance_settings_form($field, $instance) { + $widget = $instance['widget']; + $instance_settings = $instance['settings']; + $settings = $instance['settings']; + // Use the file field instance settings form as a basis. + $form = file_field_instance_settings_form($field, $instance); + // Remove the description option. + unset($form['description_field']); + // add settings by widget type + switch ($instance['widget']['type']) { + case 'video_upload': + break; + case 'video_ftp': + $form['ftp_path'] = array( + '#type' => 'textfield', + '#title' => t('FTP Filepath'), + '#default_value' => !empty($widget['ftp_path']) ? $widget['ftp_path'] : 'ftpvideos', + '#description' => t('The subdirectory within the "files/" directory where you have upload the videos for attachment. Once the video is attached it will be moved from this directory to the main files directory.'), + '#required' => TRUE, + '#weight' => 3, + ); + break; + } + //default settings + $default = video_default_instance_settings($settings); + $form = $default + $form; + return $form; +} + +/** + * Implements hook_field_load(). + */ +function video_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) { + file_field_load($entity_type, $entities, $field, $instances, $langcode, $items, $age); +} + +/** + * Implements hook_field_prepare_view(). + */ +function video_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) { + // If there are no files specified at all, use the default. + foreach ($entities as $id => $entity) { + if (empty($items[$id]) && $field['settings']['default_video_thumbnail']) { + if ($file = file_load($field['settings']['default_video_thumbnail'])) { + $items[$id][0] = (array) $file + array( + 'is_default' => TRUE, + ); + } + } + } +} + +/** + * Implements hook_field_presave(). + */ +function video_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) { + file_field_presave($entity_type, $entity, $field, $instance, $langcode, $items); +} + +/** + * Implements hook_field_insert(). + */ +function video_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) { + file_field_insert($entity_type, $entity, $field, $instance, $langcode, $items); +} + +/** + * Implements hook_field_update(). + */ +function video_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) { + file_field_update($entity_type, $entity, $field, $instance, $langcode, $items); +} + +/** + * Implements hook_field_delete(). + */ +function video_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) { + file_field_delete($entity_type, $entity, $field, $instance, $langcode, $items); +} + +/** + * Implements hook_field_delete_revision(). + */ +function video_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, &$items) { + file_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, $items); +} + +/** + * Implements hook_field_is_empty(). + */ +function video_field_is_empty($item, $field) { + return file_field_is_empty($item, $field); +} + +/** + * Implements hook_field_widget_info(). + */ +function video_field_widget_info() { + return array( + 'video_upload' => array( + 'label' => t('Video Upload'), + 'field types' => array('video'), + 'settings' => array( + 'progress_indicator' => 'throbber', + ), + 'behaviors' => array( + 'multiple values' => FIELD_BEHAVIOR_CUSTOM, + 'default value' => FIELD_BEHAVIOR_NONE, + ), + ), + 'video_ftp' => array( + 'label' => t('Video FTP'), + 'field types' => array('video'), + 'settings' => array( + 'progress_indicator' => 'throbber', + ), + 'behaviors' => array( + 'multiple values' => FIELD_BEHAVIOR_CUSTOM, + 'default value' => FIELD_BEHAVIOR_NONE, + ), + ), + ); +} + +/** + * Implements hook_field_widget_settings_form(). + */ +function video_field_widget_settings_form($field, $instance) { + // Use the file widget settings form. + $form = file_field_widget_settings_form($field, $instance); + + return $form; +} + +/** + * Implements hook_field_widget_form(). + */ +function video_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) { +// return; + // Add display_field setting to field because file_field_widget_form() assumes it is set. + $field['settings']['display_field'] = 0; + + $elements = file_field_widget_form($form, $form_state, $field, $instance, $langcode, $items, $delta, $element); + $settings = $instance['settings']; + foreach (element_children($elements) as $delta) { + + // If not using custom extension validation, ensure this is an image. + $supported_extensions = array('mp4', 'ogg', 'avi', 'mov', 'wmv', 'flv'); + $extensions = isset($elements[$delta]['#upload_validators']['file_validate_extensions'][0]) ? $elements[$delta]['#upload_validators']['file_validate_extensions'][0] : implode(' ', $supported_extensions); + $extensions = array_intersect(explode(' ', $extensions), $supported_extensions); + $elements[$delta]['#upload_validators']['file_validate_extensions'][0] = implode(' ', $extensions); + + // Add all extra functionality provided by the image widget. + $elements[$delta]['#process'][] = 'video_field_widget_process'; + } + + if ($field['cardinality'] == 1) { + // If there's only one field, return it as delta 0. + if (empty($elements[0]['#default_value']['fid'])) { + $elements[0]['#description'] = theme('file_upload_help', array('description' => $instance['description'], 'upload_validators' => $elements[0]['#upload_validators'])); + } + } else { + $elements['#file_upload_description'] = theme('file_upload_help', array('upload_validators' => $elements[0]['#upload_validators'])); + } + return $elements; +} + +/** + * An element #process callback for the image_image field type. + * + * Expands the image_image type to include the alt and title fields. + */ +function video_field_widget_process($element, &$form_state, $form) { + $item = $element['#value']; + $item['fid'] = $element['fid']['#value']; + $field = field_widget_field($element, $form_state); + $instance = field_widget_instance($element, $form_state); + $settings = $field['settings']; + $element['#theme'] = 'video_widget'; + $element['#attached']['css'][] = drupal_get_path('module', 'video') . '/css/video.css'; + $element['preview'] = array(); + // preview the video thumbnail +// if (isset($element['preview']) && $element['#value']['fid'] != 0) { +// $element['preview']['#value'] = theme('video_widget_preview', $element['#value']); +// } + // Add the image preview. + if ($settings['default_video_thumbnail'] && $element['#value']['fid'] != 0) { + $default_thumbnail = file_load($settings['default_video_thumbnail']); +// $element['preview'] = array( +// '#type' => 'markup', +// '#markup' => theme('image_style', array('style_name' => $settings['preview_video_thumb_style'], 'path' => $default_thumbnail->uri)), +// ); + } + // Title is not necessary for each individual field. + if ($field['cardinality'] != 1) { + unset($element['#title']); + } + // add file elements by widget type + switch ($instance['widget']['type']) { + case 'video_upload': + break; + case 'video_ftp': + break; + } + // Create our thumbnails + video_thumb_process($element, $form_state); + + + // Add our extra fields if in preview mode + if (!empty($item['fid'])) { + video_widget_element_settings($element, $form_state); + } + + // Lets use the clicked_button #submit[0] value here instead and see how that works out for now... + if ($form_state['submitted'] == 1) { + video_widget_process($element, $form_state); + } + return $element; +} + +/** + * Formatters + */ + +/** + * Implementation of CCK's hook_field_formatter_info(). + */ +function video_field_formatter_info() { + $formatters = array( + 'video' => array( + 'label' => t('Video'), + 'field types' => array('video'), + 'settings' => array('video_style' => '', 'video_link' => ''), + ), + 'video_thumbnail' => array( + 'label' => t('Video thumbnail'), + 'field types' => array('video'), + 'settings' => array('video_style' => '', 'video_link' => ''), + ), + //'video_colorbox' => array( + // 'label' => t('Video Thumbnail to Colorbox'), + // 'field types' => array('filefield'), + // 'description' => t('Displays the video thumbnail and adds colorbox support.'), + //), +// 'video_media_js' => array( +// 'label' => t('Video inject with jMedia'), +// 'field types' => array('video'), +// 'description' => t('Displays the video by using jmedia javascript.'), +// ), + ); + return $formatters; +} + +/** + * Implements hook_field_formatter_settings_form(). + */ +function video_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { + $display = $instance['display'][$view_mode]; + $settings = $display['settings']; + + $image_styles = image_style_options(FALSE); + $element['video_style'] = array( + '#title' => t('Video thumbnail style'), + '#type' => 'select', + '#default_value' => $settings['video_style'], + '#empty_option' => t('None (original video thumbnail)'), + '#options' => $image_styles, + ); + + $link_types = array( + 'content' => t('Content'), + 'file' => t('File'), + ); + $element['video_link'] = array( + '#title' => t('Link video or video thumbanil to'), + '#type' => 'select', + '#default_value' => $settings['video_link'], + '#empty_option' => t('Nothing'), + '#options' => $link_types, + ); + + return $element; +} + +/** + * Implements hook_field_formatter_settings_summary(). + */ +function video_field_formatter_settings_summary($field, $instance, $view_mode) { + $display = $instance['display'][$view_mode]; + $settings = $display['settings']; + + $summary = array(); + + $image_styles = image_style_options(FALSE); + // Unset possible 'No defined styles' option. + unset($image_styles['']); + // Styles could be lost because of enabled/disabled modules that defines + // their styles in code. + if (isset($image_styles[$settings['video_style']])) { + $summary[] = t('Video thumbnail style: @style', array('@style' => $image_styles[$settings['video_style']])); + } else { + $summary[] = t('Original video thumbnail'); + } + + $link_types = array( + 'content' => t('Linked to content'), + 'file' => t('Linked to video file'), + ); + // Display this setting only if image is linked. + if (isset($link_types[$settings['video_link']])) { + $summary[] = $link_types[$settings['video_link']]; + } + + return implode('
', $summary); +} + +/** + * Implements hook_field_formatter_view(). + */ +function video_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { + $element = array(); + + // Check if the formatter involves a link. + if ($display['settings']['video_link'] == 'content') { + $uri = entity_uri($entity_type, $entity); + } elseif ($display['settings']['video_link'] == 'file') { + $link_file = TRUE; + } + + // set the display + $theme = $display['type']; + foreach ($items as $delta => $item) { + if (isset($link_file)) { + $uri = array( + 'path' => file_create_url($item['uri']), + 'options' => array(), + ); + } + $element[$delta] = array( + '#theme' => $theme, + '#item' => $item, + '#video_style' => $display['settings']['video_style'], + '#path' => isset($uri) ? $uri : '', + '#entity' => $entity, + '#field' => $field, + '#instance' => $instance + ); + } + return $element; +} \ No newline at end of file diff --git a/includes/video.preset.inc b/includes/video.preset.inc index 534e5d3..4036c82 100644 --- a/includes/video.preset.inc +++ b/includes/video.preset.inc @@ -40,7 +40,7 @@ function video_preset_default_form($form, &$form_state, $preset) { '#type' => 'fieldset', '#title' => t('Video settings'), '#collapsible' => TRUE, - '#collapsed' => TRUE + '#collapsed' => FALSE ); $form['settings']['video']['video_codec'] = array( '#type' => 'select', @@ -324,7 +324,7 @@ function video_preset_default_form($form, &$form_state, $preset) { '#type' => 'fieldset', '#title' => t('Command line options'), '#collapsible' => TRUE, - '#collapsed' => TRUE + '#collapsed' => FALSE ); $tokes = array( '!cmd_path - Path to transcoder', @@ -355,20 +355,20 @@ function video_presets_overview() { $row = array(); $row[] = check_plain($preset['name']); $row[] = array('data' => filter_xss_admin($preset['description']), 'class' => 'description'); - $row[] = array('data' => l(t('edit'), 'admin/structure/video/preset/' . $preset['name'])); + $row[] = array('data' => l(t('edit'), 'admin/config/media/video/presets/preset/' . $preset['name'])); if (!isset($preset['default'])) { - $row[] = array('data' => l(t('delete'), 'admin/structure/video/preset/' . $preset['name'] . '/delete')); + $row[] = array('data' => l(t('delete'), 'admin/config/media/video/presets/preset/' . $preset['name'] . '/delete')); } - $row[] = array('data' => l(t('export'), 'admin/structure/video/preset/' . $preset['name'] . '/export')); + $row[] = array('data' => l(t('export'), 'admin/config/media/video/presets/preset/' . $preset['name'] . '/export')); $rows[] = $row; } return theme('table', array('header' => $header, 'rows' => $rows)); } else { return t('No Preset were found. Please use the !create_link link to create a new video preset, or upload an existing Feature to your modules directory.', - array('!create_link' => l(t('Create Video Preset'), 'admin/structure/video/add'))); + array('!create_link' => l(t('Create Video Preset'), 'admin/config/media/video/presets/add'))); } } @@ -486,7 +486,7 @@ function video_preset_submit($form, &$form_state) { // Save this preset. video_preset_save($preset); drupal_set_message(t('Preset !preset successfully saved.', array('!preset' => $preset['name']))); - $form_state['redirect'] = 'admin/structure/video'; + $form_state['redirect'] = 'admin/config/media/video/presets'; } /** @@ -494,7 +494,7 @@ function video_preset_submit($form, &$form_state) { */ function video_preset_delete_submit($form, &$form_state) { $preset['name'] = $form_state['values']['name']; - $form_state['redirect'] = 'admin/structure/video/preset/' . $preset['name'] . '/delete'; + $form_state['redirect'] = 'admin/config/media/video/presets/preset/' . $preset['name'] . '/delete'; } /** @@ -504,7 +504,7 @@ function video_preset_delete_confirm($form, &$form_state, $preset) { $form['name'] = array('#type' => 'value', '#value' => $preset['name']); $message = t('Are you sure you want to delete the preset %name?', array('%name' => $preset['name'])); $caption = '

' . t('This action cannot be undone.') . '

'; - return confirm_form($form, $message, 'admin/structure/video', $caption, t('Delete')); + return confirm_form($form, $message, 'admin/config/media/video/presets', $caption, t('Delete')); } /** @@ -515,7 +515,7 @@ function video_preset_delete_confirm_submit($form, &$form_state) { video_preset_delete($form_state['values']['name']); } - $form_state['redirect'] = 'admin/structure/video'; + $form_state['redirect'] = 'admin/config/media/video/presets'; } /** @@ -580,7 +580,7 @@ function video_preset_import_validate($form, &$form_state) { function video_preset_import_submit($form, &$form_state) { $preset = $form_state['preset']; video_preset_save($preset); - $form_state['redirect'] = 'admin/structure/video/preset/' . $preset['name']; + $form_state['redirect'] = 'admin/config/media/video/presets/preset/' . $preset['name']; } /** diff --git a/includes/video_helper.inc b/includes/video_helper.inc index 0205a50..b41f657 100644 --- a/includes/video_helper.inc +++ b/includes/video_helper.inc @@ -94,15 +94,19 @@ class video_helper { // Setup our thumbnail path. $default_thumbnail = file_load($field_settings['default_video_thumbnail']); - $use_default_img = isset($variables['item']['use_default_video_thumb']) ? $variables['item']['use_default_video_thumb'] : false; + $use_default_img = isset($variables['item']['use_default_video_thumb']) ? + $variables['item']['use_default_video_thumb'] : FALSE; + if ($use_default_img && !empty($field_settings['default_video_thumbnail'])) { + // Check the checkbox to use default thumbnail on node $thumbnail->filepath = $default_thumbnail->uri; - } elseif (isset($variables['item']['video_thumb']) ? $variables['item']['video_thumb'] : false) { + } elseif (isset($variables['item']['video_thumb']) ? $variables['item']['video_thumb'] : FALSE) { + // actual video thumbnails is present $thumbnail_load = file_load($variables['item']['video_thumb']); $thumbnail->filepath = $thumbnail_load->uri; } else { //need some type of default if nothing is present - drupal_set_message(t('No thumbnail has been configured for the video !title.', array('!title' => $variables['entity']->title)), 'error'); +// drupal_set_message(t('No thumbnail has been configured for the video !title.', array('!title' => $variables['entity']->title)), 'error'); return; } diff --git a/modules/video_zencoder/includes/zencoder.inc b/modules/video_zencoder/includes/zencoder.inc index c3023b0..fd273ba 100644 --- a/modules/video_zencoder/includes/zencoder.inc +++ b/modules/video_zencoder/includes/zencoder.inc @@ -53,7 +53,7 @@ class video_zencoder_api { // watchdog('zencoder', $input_name); // thumbnails // Setup our thmbnail path. - $video_thumb_path = variable_get('video_thumb_path', 'video_thumbs'); + $video_thumb_path = variable_get('video_thumb_path', 'videos/thumbnails'); $final_thumb_path = file_default_scheme() . ':/' . $video_thumb_path . '/' . $file->fid; // Notifications diff --git a/modules/video_zencoder/transcoders/video_zencoder.inc b/modules/video_zencoder/transcoders/video_zencoder.inc index 1eb246a..baaffc2 100644 --- a/modules/video_zencoder/transcoders/video_zencoder.inc +++ b/modules/video_zencoder/transcoders/video_zencoder.inc @@ -19,7 +19,7 @@ class video_zencoder implements transcoder_interface { public function generate_thumbnails($video) { global $user; // Setup our thmbnail path. - $video_thumb_path = variable_get('video_thumb_path', 'video_thumbs'); + $video_thumb_path = variable_get('video_thumb_path', 'videos/thumbnails'); $final_thumb_path = file_default_scheme() . ':/' . $video_thumb_path . '/' . $video['fid']; // Ensure the destination directory exists and is writable. diff --git a/modules/video_zencoder/video_zencoder.module b/modules/video_zencoder/video_zencoder.module index 7f2218e..0919866 100644 --- a/modules/video_zencoder/video_zencoder.module +++ b/modules/video_zencoder/video_zencoder.module @@ -88,7 +88,7 @@ function _video_zencoder_postback_jobs() { // update the thumbanils // this will update the default thumbnails, if user want to select another one then they wil need to edit the node // Setup our thmbnail path. - $video_thumb_path = variable_get('video_thumb_path', 'video_thumbs'); + $video_thumb_path = variable_get('video_thumb_path', 'videos/thumbnails'); $final_thumb_path = file_default_scheme() . ':/' . $video_thumb_path . '/' . $fid; // $i = rand(0, (variable_get('no_of_video_thumbs', 5) - 1)); $filename = $fid . '_' . sprintf("%04d", 1) . '.png'; diff --git a/theme/video-play-html5.tpl.php b/theme/video-play-html5.tpl.php index 038fa20..cb4d51a 100644 --- a/theme/video-play-html5.tpl.php +++ b/theme/video-play-html5.tpl.php @@ -15,10 +15,10 @@ \ No newline at end of file diff --git a/transcoders/video_ffmpeg.inc b/transcoders/video_ffmpeg.inc index e5b2695..d76efb5 100644 --- a/transcoders/video_ffmpeg.inc +++ b/transcoders/video_ffmpeg.inc @@ -6,7 +6,6 @@ * */ - class video_ffmpeg implements transcoder_interface { // Naming for our radio options. Makes it easy to extend our transcoders. @@ -40,7 +39,7 @@ class video_ffmpeg implements transcoder_interface { public function run_command($options) { // $command = $this->nice . ' ' . $this->params['cmd_path'] . ' ' . $options . ' 2>&1'; $command = $options . ' 2>&1'; - watchdog('video_ffmpeg', 'Executing command: ' . $command, array(), WATCHDOG_DEBUG); + watchdog('transcoder', 'Executing command: ' . $command, array(), WATCHDOG_DEBUG); ob_start(); passthru($command, $command_return); $output = ob_get_contents(); @@ -51,7 +50,7 @@ class video_ffmpeg implements transcoder_interface { public function generate_thumbnails($video) { global $user; // Setup our thmbnail path. - $video_thumb_path = variable_get('video_thumb_path', 'video_thumbs'); + $video_thumb_path = variable_get('video_thumb_path', 'videos/thumbnails'); // Get the file system directory. $schema_thumb_path = file_default_scheme() . '://' . $video_thumb_path . '/' . $video['fid']; file_prepare_directory($schema_thumb_path, FILE_CREATE_DIRECTORY); @@ -66,8 +65,8 @@ class video_ffmpeg implements transcoder_interface { $files = NULL; for ($i = 1; $i <= $total_thumbs; $i++) { $seek = ($duration / $total_thumbs) * $i - 1; //adding minus one to prevent seek times equaling the last second of the video - $filename = file_munge_filename("/video-thumb-for-" . $video['fid'] . "-$i.jpg", '', TRUE); - $thumbfile = $schema_thumb_path . $filename; + $filename = file_munge_filename("video-thumb-for-" . $video['fid'] . "-$i.jpg", '', TRUE); + $thumbfile = $schema_thumb_path . '/' . $filename; //skip files already exists, this will save ffmpeg traffic if (!is_file(drupal_realpath($thumbfile))) { //setup the command to be passed to the transcoder. @@ -78,7 +77,7 @@ class video_ffmpeg implements transcoder_interface { $error_param = array('%file' => $thumbfile, '%cmd' => $options, '%out' => $command_output); $error_msg = t("Error generating thumbnail for video: generated file %file does not exist.
Command Executed:
%cmd
Command Output:
%out", $error_param); // Log the error message. - watchdog('video_transcoder', $error_msg, array(), WATCHDOG_ERROR); + watchdog('transcoder', $error_msg, array(), WATCHDOG_ERROR); continue; } } @@ -110,11 +109,11 @@ class video_ffmpeg implements transcoder_interface { $converted = $files . '/videos/converted'; if (!field_file_check_directory($original, FILE_CREATE_DIRECTORY)) { - watchdog('video_transcoder', 'Video conversion failed. Could not create the directory: ' . $orginal, array(), WATCHDOG_ERROR); + watchdog('transcoder', 'Video conversion failed. Could not create the directory: ' . $orginal, array(), WATCHDOG_ERROR); return false; } if (!field_file_check_directory($converted, FILE_CREATE_DIRECTORY)) { - watchdog('video_transcoder', 'Video conversion failed. Could not create the directory: ' . $converted, array(), WATCHDOG_ERROR); + watchdog('transcoder', 'Video conversion failed. Could not create the directory: ' . $converted, array(), WATCHDOG_ERROR); return false; } @@ -318,7 +317,7 @@ class video_ffmpeg implements transcoder_interface { '#type' => 'textfield', '#title' => t('Path to save thumbnails'), '#description' => t('Path to save video thumbnails extracted from the videos.'), - '#default_value' => variable_get('video_thumb_path', 'video_thumbs'), + '#default_value' => variable_get('video_thumb_path', 'videos/thumbnails'), ); $form['autothumb']['advanced'] = array( '#type' => 'fieldset', diff --git a/video.css b/video.css index e32fb59..e69de29 100644 --- a/video.css +++ b/video.css @@ -1,14 +0,0 @@ - -/** - * Image upload widget. - */ -div.video-preview { - float: left; /* LTR */ - padding: 0 10px 10px 0; /* LTR */ -} -div.video-widget-data { - float: left; /* LTR */ -} -div.video-widget-data input.text-field { - width: auto; -} diff --git a/video.field.inc b/video.field.inc deleted file mode 100644 index ea53cda..0000000 --- a/video.field.inc +++ /dev/null @@ -1,425 +0,0 @@ - array( - 'label' => t('Video'), - 'description' => t('This field stores the ID of an video file as an integer value.'), - 'settings' => array( - 'uri_scheme' => variable_get('file_default_scheme', 'public'), - 'autoconversion' => 0, - 'autothumbnail' => 'no', - 'default_video_thumbnail' => 0, - 'preview_video_thumb_style' => 'thumbnail', - ), - 'instance_settings' => array( - 'file_extensions' => 'mp4 ogg avi mov wmv flv', - 'file_directory' => 'videos/original', - 'max_filesize' => '', - 'default_dimensions' => '640x350', - 'default_player_dimensions' => '640x350' - ), - 'default_widget' => 'video_upload', - 'default_formatter' => 'video', - ), - ); -} - -/** - * Implements hook_field_settings_form(). - */ -function video_field_settings_form($field, $instance) { - $defaults = field_info_field_settings($field['type']); - $settings = array_merge($defaults, $field['settings']); - $scheme_options = array(); - foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) { - $scheme_options[$scheme] = $stream_wrapper['name']; - } - $form['uri_scheme'] = array( - '#type' => 'radios', - '#title' => t('Upload destination'), - '#options' => $scheme_options, - '#default_value' => $settings['uri_scheme'], - '#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'), - ); - $form = $form + video_default_field_settings($settings); - return $form; -} - -/** - * Element specific validation for video default value. - * - */ -function video_field_default_thumbnail_validate($element, &$form_state) { - $settings = $form_state['values']['field']['settings']; - // Make the file permanent and store it in the form. - if (!empty($settings['default_video_thumbnail']['fid'])) { - $file = file_load($settings['default_video_thumbnail']['fid']); - $file->status |= FILE_STATUS_PERMANENT; - $file = file_save($file); - $form_state['values']['field']['settings']['default_video_thumbnail'] = (array) $file; - } -} - -/** - * Implements hook_field_instance_settings_form(). - */ -function video_field_instance_settings_form($field, $instance) { - $widget = $instance['widget']; - $instance_settings = $instance['settings']; - $settings = $instance['settings']; - // Use the file field instance settings form as a basis. - $form = file_field_instance_settings_form($field, $instance); - // Remove the description option. - unset($form['description_field']); - // add settings by widget type - switch ($instance['widget']['type']) { - case 'video_upload': - break; - case 'video_ftp': - $form['ftp_path'] = array( - '#type' => 'textfield', - '#title' => t('FTP Filepath'), - '#default_value' => !empty($widget['ftp_path']) ? $widget['ftp_path'] : 'ftpvideos', - '#description' => t('The subdirectory within the "files/" directory where you have upload the videos for attachment. Once the video is attached it will be moved from this directory to the main files directory.'), - '#required' => TRUE, - '#weight' => 3, - ); - break; - } - //default settings - $default = video_default_instance_settings($settings); - $form = $default + $form; - return $form; -} - -/** - * Implements hook_field_load(). - */ -function video_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) { - file_field_load($entity_type, $entities, $field, $instances, $langcode, $items, $age); -} - -/** - * Implements hook_field_prepare_view(). - */ -function video_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) { - // If there are no files specified at all, use the default. - foreach ($entities as $id => $entity) { - if (empty($items[$id]) && $field['settings']['default_video_thumbnail']) { - if ($file = file_load($field['settings']['default_video_thumbnail'])) { - $items[$id][0] = (array) $file + array( - 'is_default' => TRUE, - ); - } - } - } -} - -/** - * Implements hook_field_presave(). - */ -function video_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) { - file_field_presave($entity_type, $entity, $field, $instance, $langcode, $items); -} - -/** - * Implements hook_field_insert(). - */ -function video_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) { - file_field_insert($entity_type, $entity, $field, $instance, $langcode, $items); -} - -/** - * Implements hook_field_update(). - */ -function video_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) { - file_field_update($entity_type, $entity, $field, $instance, $langcode, $items); -} - -/** - * Implements hook_field_delete(). - */ -function video_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) { - file_field_delete($entity_type, $entity, $field, $instance, $langcode, $items); -} - -/** - * Implements hook_field_delete_revision(). - */ -function video_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, &$items) { - file_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, $items); -} - -/** - * Implements hook_field_is_empty(). - */ -function video_field_is_empty($item, $field) { - return file_field_is_empty($item, $field); -} - -/** - * Implements hook_field_widget_info(). - */ -function video_field_widget_info() { - return array( - 'video_upload' => array( - 'label' => t('Video Upload'), - 'field types' => array('video'), - 'settings' => array( - 'progress_indicator' => 'throbber', - ), - 'behaviors' => array( - 'multiple values' => FIELD_BEHAVIOR_CUSTOM, - 'default value' => FIELD_BEHAVIOR_NONE, - ), - ), - 'video_ftp' => array( - 'label' => t('Video FTP'), - 'field types' => array('video'), - 'settings' => array( - 'progress_indicator' => 'throbber', - ), - 'behaviors' => array( - 'multiple values' => FIELD_BEHAVIOR_CUSTOM, - 'default value' => FIELD_BEHAVIOR_NONE, - ), - ), - ); -} - -/** - * Implements hook_field_widget_settings_form(). - */ -function video_field_widget_settings_form($field, $instance) { - // Use the file widget settings form. - $form = file_field_widget_settings_form($field, $instance); - - return $form; -} - -/** - * Implements hook_field_widget_form(). - */ -function video_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) { -// return; - // Add display_field setting to field because file_field_widget_form() assumes it is set. - $field['settings']['display_field'] = 0; - - $elements = file_field_widget_form($form, $form_state, $field, $instance, $langcode, $items, $delta, $element); - $settings = $instance['settings']; - foreach (element_children($elements) as $delta) { - - // If not using custom extension validation, ensure this is an image. - $supported_extensions = array('mp4', 'ogg', 'avi', 'mov', 'wmv', 'flv'); - $extensions = isset($elements[$delta]['#upload_validators']['file_validate_extensions'][0]) ? $elements[$delta]['#upload_validators']['file_validate_extensions'][0] : implode(' ', $supported_extensions); - $extensions = array_intersect(explode(' ', $extensions), $supported_extensions); - $elements[$delta]['#upload_validators']['file_validate_extensions'][0] = implode(' ', $extensions); - - // Add all extra functionality provided by the image widget. - $elements[$delta]['#process'][] = 'video_field_widget_process'; - } - - if ($field['cardinality'] == 1) { - // If there's only one field, return it as delta 0. - if (empty($elements[0]['#default_value']['fid'])) { - $elements[0]['#description'] = theme('file_upload_help', array('description' => $instance['description'], 'upload_validators' => $elements[0]['#upload_validators'])); - } - } else { - $elements['#file_upload_description'] = theme('file_upload_help', array('upload_validators' => $elements[0]['#upload_validators'])); - } - return $elements; -} - -/** - * An element #process callback for the image_image field type. - * - * Expands the image_image type to include the alt and title fields. - */ -function video_field_widget_process($element, &$form_state, $form) { - $item = $element['#value']; - $item['fid'] = $element['fid']['#value']; - $field = field_widget_field($element, $form_state); - $instance = field_widget_instance($element, $form_state); - $settings = $field['settings']; - $element['#theme'] = 'video_widget'; - $element['#attached']['css'][] = drupal_get_path('module', 'image') . '/video.css'; - // preview the video thumbnail -// if (isset($element['preview']) && $element['#value']['fid'] != 0) { -// $element['preview']['#value'] = theme('video_widget_preview', $element['#value']); -// } - // Add the image preview. - if ($settings['default_video_thumbnail'] && $element['#value']['fid'] != 0) { - $element['preview'] = array(); - $default_thumbnail = file_load($settings['default_video_thumbnail']); -// $element['preview'] = array( -// '#type' => 'markup', -// '#markup' => theme('image_style', array('style_name' => $settings['preview_video_thumb_style'], 'path' => $default_thumbnail->uri)), -// ); - } - // Title is not necessary for each individual field. - if ($field['cardinality'] != 1) { - unset($element['#title']); - } - // add file elements by widget type - switch ($instance['widget']['type']) { - case 'video_upload': - break; - case 'video_ftp': - break; - } - // Create our thumbnails - video_thumb_process($element, $form_state); - - - // Add our extra fields if in preview mode - if (!empty($item['fid'])) { - video_widget_element_settings($element, $form_state); - } - - // Lets use the clicked_button #submit[0] value here instead and see how that works out for now... - if ($form_state['submitted'] == 1) { - video_widget_process($element, $form_state); - } - return $element; -} - -/** - * Formatters - */ - -/** - * Implementation of CCK's hook_field_formatter_info(). - */ -function video_field_formatter_info() { - $formatters = array( - 'video' => array( - 'label' => t('Video'), - 'field types' => array('video'), - 'settings' => array('video_style' => '', 'video_link' => ''), - ), - 'video_thumbnail' => array( - 'label' => t('Video thumbnail'), - 'field types' => array('video'), - 'settings' => array('video_style' => '', 'video_link' => ''), - ), - //'video_colorbox' => array( - // 'label' => t('Video Thumbnail to Colorbox'), - // 'field types' => array('filefield'), - // 'description' => t('Displays the video thumbnail and adds colorbox support.'), - //), -// 'video_media_js' => array( -// 'label' => t('Video inject with jMedia'), -// 'field types' => array('video'), -// 'description' => t('Displays the video by using jmedia javascript.'), -// ), - ); - return $formatters; -} - -/** - * Implements hook_field_formatter_settings_form(). - */ -function video_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { - $display = $instance['display'][$view_mode]; - $settings = $display['settings']; - - $image_styles = image_style_options(FALSE); - $element['video_style'] = array( - '#title' => t('Video thumbnail style'), - '#type' => 'select', - '#default_value' => $settings['video_style'], - '#empty_option' => t('None (original video thumbnail)'), - '#options' => $image_styles, - ); - - $link_types = array( - 'content' => t('Content'), - 'file' => t('File'), - ); - $element['video_link'] = array( - '#title' => t('Link video or video thumbanil to'), - '#type' => 'select', - '#default_value' => $settings['video_link'], - '#empty_option' => t('Nothing'), - '#options' => $link_types, - ); - - return $element; -} - -/** - * Implements hook_field_formatter_settings_summary(). - */ -function video_field_formatter_settings_summary($field, $instance, $view_mode) { - $display = $instance['display'][$view_mode]; - $settings = $display['settings']; - - $summary = array(); - - $image_styles = image_style_options(FALSE); - // Unset possible 'No defined styles' option. - unset($image_styles['']); - // Styles could be lost because of enabled/disabled modules that defines - // their styles in code. - if (isset($image_styles[$settings['video_style']])) { - $summary[] = t('Video thumbnail style: @style', array('@style' => $image_styles[$settings['video_style']])); - } else { - $summary[] = t('Original video thumbnail'); - } - - $link_types = array( - 'content' => t('Linked to content'), - 'file' => t('Linked to video file'), - ); - // Display this setting only if image is linked. - if (isset($link_types[$settings['video_link']])) { - $summary[] = $link_types[$settings['video_link']]; - } - - return implode('
', $summary); -} - -/** - * Implements hook_field_formatter_view(). - */ -function video_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { - $element = array(); - - // Check if the formatter involves a link. - if ($display['settings']['video_link'] == 'content') { - $uri = entity_uri($entity_type, $entity); - } elseif ($display['settings']['video_link'] == 'file') { - $link_file = TRUE; - } - - // set the display - $theme = $display['type']; - foreach ($items as $delta => $item) { - if (isset($link_file)) { - $uri = array( - 'path' => file_create_url($item['uri']), - 'options' => array(), - ); - } - $element[$delta] = array( - '#theme' => $theme, - '#item' => $item, - '#video_style' => $display['settings']['video_style'], - '#path' => isset($uri) ? $uri : '', - '#entity' => $entity, - '#field' => $field, - '#instance' => $instance - ); - } - return $element; -} \ No newline at end of file diff --git a/video.info b/video.info index 873c99d..ac24b81 100644 --- a/video.info +++ b/video.info @@ -4,6 +4,7 @@ package = Video core = 7.x configure = admin/config/media/video dependencies[] = file +dependencies[] = image files[] = video.module files[] = video.admin.inc files[] = video.drush.inc diff --git a/video.install b/video.install index 3250513..828496b 100644 --- a/video.install +++ b/video.install @@ -61,9 +61,10 @@ function video_schema() { 'default' => 0, ), 'data' => array( - 'type' => 'text', + 'type' => 'blob', 'not null' => FALSE, 'size' => 'big', + 'serialize' => TRUE, 'description' => 'A serialized array of converted files. Use of this field is discouraged and it will likely disappear in a future version of Drupal.', ), @@ -98,10 +99,11 @@ function video_schema() { 'translatable' => TRUE, ), 'settings' => array( - 'type' => 'text', - 'size' => 'medium', + 'type' => 'blob', + 'not null' => FALSE, + 'size' => 'big', 'serialize' => TRUE, - 'description' => 'Serialized player settings that do not warrant a dedicated column. + 'description' => 'Serialized preset settings that do not warrant a dedicated column. Use of this field is discouraged and it will likely disappear in a future version of Drupal.', ), ), @@ -110,6 +112,35 @@ function video_schema() { ), 'primary key' => array('pid'), ); + // video thumbnails + $schema['video_thumbnails'] = array( + 'description' => 'The video thumbnails table.', + 'fields' => array( + 'vid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'Foreign Key {video_files}.fid.', + ), + 'thumbnails' => array( + 'type' => 'blob', + 'not null' => FALSE, + 'size' => 'big', + 'serialize' => TRUE, + 'description' => 'Serialized array of thumbnails data. + Use of this field is discouraged and it will likely disappear in a future version of Drupal.', + ), + ), + 'indexes' => array( + 'thumbnail' => array('vid'), + ), + 'foreign keys' => array( + 'thumbnails' => array( + 'table' => 'video_files', + 'columns' => array('vid' => 'vid'), + ), + ), + ); return $schema; } diff --git a/video.module b/video.module index e68c66d..9c59ecf 100644 --- a/video.module +++ b/video.module @@ -6,7 +6,7 @@ * */ // include the field element -module_load_include('inc', 'video', 'video.field'); +module_load_include('inc', 'video', 'includes/video.field'); module_load_include('inc', 'video', 'includes/video.features'); /* @@ -90,7 +90,7 @@ function video_menu() { ); // Preset settings $items['admin/config/media/video/presets'] = array( - 'title' => 'Presets', + 'title' => 'Manage Preset', 'description' => 'Configure your transcoder presets to convert your videos.', 'page callback' => 'drupal_get_form', 'page arguments' => array('video_preset_admin_settings'), @@ -100,21 +100,33 @@ function video_menu() { 'weight' => 3, ); - $items['admin/structure/video'] = array( - 'title' => 'Video Presets', - 'file' => 'includes/video.preset.inc', - 'description' => 'Manage and configure the presets for Video.', - 'page callback' => 'video_presets_overview', - 'access arguments' => array('administer video presets') +// $items['admin/structure/video'] = array( +// 'title' => 'Video Presets', +// 'file' => 'includes/video.preset.inc', +// 'description' => 'Manage and configure the presets for Video.', +// 'page callback' => 'video_presets_overview', +// 'access arguments' => array('administer video presets') +// ); + $items['admin/config/media/video/presets/all'] = array( + 'title' => 'Presets', + 'description' => 'Configure your transcoder presets to convert your videos.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('video_preset_admin_settings'), + 'access arguments' => array('administer site configuration'), + 'file' => 'video.admin.inc', + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => -10, ); - $items['admin/structure/video/list'] = array( + $items['admin/config/media/video/presets/list'] = array( 'title' => 'List', 'file' => 'includes/video.preset.inc', + 'description' => 'Manage and configure the presets for Video.', + 'page callback' => 'video_presets_overview', 'access arguments' => array('administer video presets'), - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => -10, + 'type' => MENU_LOCAL_TASK, + 'weight' => -9, ); - $items['admin/structure/video/add'] = array( + $items['admin/config/media/video/presets/add'] = array( 'title' => 'Add preset', 'file' => 'includes/video.preset.inc', 'page callback' => 'drupal_get_form', @@ -122,7 +134,7 @@ function video_menu() { 'access arguments' => array('administer video presets'), 'type' => MENU_LOCAL_TASK ); - $items['admin/structure/video/import'] = array( + $items['admin/config/media/video/presets/import'] = array( 'title' => t('Import preset'), 'file' => 'includes/video.preset.inc', 'page callback' => 'drupal_get_form', @@ -131,36 +143,36 @@ function video_menu() { 'type' => MENU_LOCAL_TASK ); - $items['admin/structure/video/preset/%video_preset'] = array( + $items['admin/config/media/video/presets/preset/%video_preset'] = array( 'title' => 'Edit video preset', 'title callback' => 'video_preset_page_title', - 'title arguments' => array(4), + 'title arguments' => array(6), 'file' => 'includes/video.preset.inc', 'page callback' => 'drupal_get_form', - 'page arguments' => array('video_preset_form', 4), + 'page arguments' => array('video_preset_form', 6), 'access arguments' => array('administer video presets') ); - $items['admin/structure/video/preset/%video_preset/edit'] = array( + $items['admin/config/media/video/presets/preset/%video_preset/edit'] = array( 'title' => 'Edit', 'file' => 'includes/video.preset.inc', - 'page arguments' => array(4), + 'page arguments' => array(6), 'access arguments' => array('administer video presets'), 'type' => MENU_DEFAULT_LOCAL_TASK, ); - $items['admin/structure/video/preset/%video_preset/delete'] = array( + $items['admin/config/media/video/presets/preset/%video_preset/delete'] = array( 'title' => 'Delete', 'file' => 'includes/video.preset.inc', - 'page arguments' => array('video_preset_delete_confirm', 4), + 'page arguments' => array('video_preset_delete_confirm', 6), 'access arguments' => array('administer video presets'), 'type' => MENU_CALLBACK ); - $items['admin/structure/video/preset/%video_preset/export'] = array( + $items['admin/config/media/video/presets/preset/%video_preset/export'] = array( 'title' => t('Export'), 'file' => 'includes/video.preset.inc', 'title callback' => 'video_preset_page_title', - 'title arguments' => array(4), + 'title arguments' => array(6), 'page callback' => 'drupal_get_form', - 'page arguments' => array('video_preset_export_form', 4), + 'page arguments' => array('video_preset_export_form', 6), 'access arguments' => array('administer video presets'), 'type' => MENU_CALLBACK ); @@ -310,7 +322,6 @@ function video_theme() { function video_cron() { if (variable_get('video_cron', TRUE)) { - module_load_include('inc', 'video', '/includes/conversion'); $video_conversion = new video_conversion; $video_conversion->run_queue(); } @@ -333,7 +344,6 @@ function video_node_update_submit($form, &$form_state) { if (isset($form_state['nid']) && isset($form_state['values']['video_id']) && is_array($form_state['values']['video_id'])) { foreach ($form_state['values']['video_id'] as $fid) { // @TODO : check for enable trancoder - module_load_include('inc', 'video', '/includes/transcoder'); $transcoder = new video_transcoder; $video = array('nid' => $form_state['nid'], 'fid' => $fid); $transcoder->update_job($video); @@ -355,30 +365,25 @@ function video_thumb_process(&$element, &$form_state) { $gen_fail = FALSE; if (isset($element['preview']) && $file['fid'] != 0) { - $default_thumb = ''; + $default_thumb = array(); if (in_array($field['settings']['autothumbnail'], array('auto', 'auto_fallback'))) { - - module_load_include('inc', 'video', '/includes/transcoder'); $transcoder = new video_transcoder; if ($thumbs = $transcoder->generate_thumbnails($file)) { - $rnd_img = rand(0, variable_get('video_thumbs', 5) - 1); - $default_thumb = $thumbs[$rnd_img]->fid; - - if (is_array($thumbs)) { + $default_thumb = array_rand($thumbs); + if (!empty($thumbs)) { foreach ($thumbs as $fid => $img) { // if file object contain url then use file name to identify object - $key = $img->fid; - $thumbss[$key] = theme('image_style', array('style_name' => $field['settings']['preview_video_thumb_style'], 'path' => $img->uri)); + $thumbss[$img->fid] = theme('image_style', array('style_name' => $field['settings']['preview_video_thumb_style'], 'path' => $img->uri)); } } } if (!empty($thumbss)) { - $element['video_thumbnail'] = array( + $element['thumbanail'] = array( '#type' => 'radios', '#title' => t('Video Thumbnails'), '#options' => $thumbss, - '#default_value' => !empty($file['video_thumb']) ? $file['video_thumb'] : $default_thumb, + '#default_value' => !empty($file['thumbanail']) ? $file['thumbanail'] : $thumbs[$default_thumb]->fid, '#weight' => 10, '#attributes' => array('class' => array('video-thumbnails'), 'onchange' => 'videoftp_thumbnail_change()', 'rel' => 'video_large_thumbnail-' . $delta), ); @@ -398,26 +403,26 @@ function video_thumb_process(&$element, &$form_state) { '#description' => t('This thumbnail will be uploaded when the node is saved.'), ); - $element['video_thumb'] = array( + $element['thumbanail'] = array( '#type' => 'value', - '#value' => isset($file['video_thumb']) ? $file['video_thumb'] : false, + '#value' => isset($file['thumbanail']) ? $file['thumbanail'] : false, ); } // Setup our large thumbnail that is on the left. // @todo Add smaller video preview instead of thumbnail? - if (isset($file['video_thumb']) && !empty($file['video_thumb'])) { - $large_thumb = array('filepath' => $file['video_thumb']); + if (isset($file['thumbanail']) && !empty($file['thumbanail'])) { + $large_thumb = file_load($file['thumbanail']); } elseif (!empty($field['settings']['default_video_thumb'])) { - $large_thumb = $field['settings']['default_video_thumb']; + $large_thumb = file_load($field['settings']['default_video_thumbnail']); } else { - $large_thumb = array('filepath' => $default_thumb); + $large_thumb = file_load($default_thumb); } // print_r($field['settings']['default_video_thumbnail']); - $default_thumbnail = file_load($field['settings']['default_video_thumbnail']); +// $default_thumbnail = file_load($field['settings']['default_video_thumbnail']); // @todo Integrate the thumbnails with imagecache. - if (!empty($default_thumbnail)) - $element['preview']['#suffix'] = '
' . theme('image_style', array('style_name' => $field['settings']['preview_video_thumb_style'], 'path' => $default_thumbnail->uri)) . '
'; + if (!empty($large_thumb)) + $element['preview']['#suffix'] = '
' . theme('image_style', array('style_name' => $field['settings']['preview_video_thumb_style'], 'path' => $large_thumb->uri)) . '
'; } } @@ -496,7 +501,7 @@ function video_file_delete($file) { $transcoder->delete_job($file); //now lets delete our video thumbnails and folder. - $video_thumb_path = variable_get('video_thumb_path', 'video_thumbs'); + $video_thumb_path = variable_get('video_thumb_path', 'videos/thumbnails'); $thumb_folder = file_default_scheme() . ':/' . $video_thumb_path . '/' . $file->fid; // Recursively delete our folder and files rmdirr($thumb_folder); diff --git a/video_preset/.cvsignore b/video_preset/.cvsignore deleted file mode 100644 index e43b0f9..0000000 --- a/video_preset/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -.DS_Store -- cgit v1.2.3