I'm using this module on a server that functions only as an intranet, with protection in place to prevent any outside contact. Although the videos will save, the function that attempts to go out and get a thumbnail of the video to then write it to the local Drupal files directory means that users have to wait up to 1 minute or longer until the server times out and finally the page saves.
I've found the function
video_embed_field_field_presave()
on line 209 of the file video_embed_field.field.inc, and I'm wondering, what is the most graceful way of preventing the attempt to get the thumbnail and save it? Perhaps a time-out of 1 second, or something to abort the drupal_http_request?
Any help would be greatly appreciated. Thanks. Here's the full code for reference:
function video_embed_field_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
foreach ($items as $delta => $item) {
//Trim whitespace from the video URL.
$items[$delta]['video_url'] = trim($item['video_url']);
// Try to load thumbnail URL
$info = video_embed_field_thumbnail_url($item['video_url']);
if (isset($info['url']) && $info['url']) {
$thumb_url = $info['url'];
$local_path = 'public://video_embed_field_thumbnails/' . $info['handler'] . '/' . $info['id'] . '.jpg';
$dirname = drupal_dirname($local_path);
file_prepare_directory($dirname, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
$response = drupal_http_request($thumb_url);
if (!isset($response->error)) {
file_save_data($response->data, $local_path, TRUE);
}
else {
@copy($thumb_url, $local_path);
}
$items[$delta]['thumbnail_path'] = $local_path;
} //couldn't get the thumbnail for whatever reason
else {
$items[$delta]['thumbnail_path'] = '';
}
// Try to load video data
$data = video_embed_field_get_video_data($item['video_url']);
if (is_array($data) && !empty($data)) {
$items[$delta]['video_data'] = serialize($data);
}
else {
$items[$delta]['video_data'] = NULL;
}
}
}