function powerpress_get_media_info_local($media_file, $content_type = '', $file_size = 0, $duration = '', $return_warnings = false) { $error_msg = ''; $warning_msg = ''; if ($content_type == '') { $content_type = powerpress_get_contenttype($media_file); } if (isset($GLOBALS['objWPOSFLV']) && is_object($GLOBALS['objWPOSFLV'])) { return array('error' => __('The WP OS FLV plugin is not compatible with Blubrry PowerPress.', 'powerpress')); } $get_duration_info = ($content_type == 'audio/mpeg' || $content_type == 'audio/x-m4a' || $content_type == 'video/x-m4v' || $content_type == 'video/mp4' || $content_type == 'audio/ogg') && $duration === ''; // Lets use the mp3info class: require_once POWERPRESS_ABSPATH . '/mp3info.class.php'; $Mp3Info = new Mp3Info(); if ($get_duration_info) { if (preg_match('/video/i', $content_type)) { if (defined('POWERPRESS_DOWNLOAD_BYTE_LIMIT_VIDEO')) { $Mp3Info->SetDownloadBytesLimit(POWERPRESS_DOWNLOAD_BYTE_LIMIT_VIDEO); } } else { if (defined('POWERPRESS_DOWNLOAD_BYTE_LIMIT')) { $Mp3Info->SetDownloadBytesLimit(POWERPRESS_DOWNLOAD_BYTE_LIMIT); } } } $Mp3Data = $Mp3Info->GetMp3Info($media_file, !$get_duration_info); if ($Mp3Data) { if ($Mp3Info->GetRedirectCount() > 5) { // Add a warning that the redirect count exceeded 5, which may prevent some podcatchers from downloading the media. $warning = sprintf(__('Warning, the Media URL %s contains %d redirects.', 'powerpress'), $media_file, $Mp3Info->GetRedirectCount()); $warning .= ' [<a href="http://create.blubrry.com/resources/powerpress/using-powerpress/warning-messages-explained/" title="' . __('PowerPress Warnings Explained', 'powerpress') . '" target="_blank">' . __('PowerPress Warnings Explained') . '</a>]'; if ($return_warnings) { $warning_msg .= $warning; } else { powerpress_add_error($warning); } } if ($file_size == 0) { $file_size = $Mp3Info->GetContentLength(); } if ($get_duration_info) { $playtime_string = !empty($Mp3Data['playtime_string']) ? $Mp3Data['playtime_string'] : ''; $duration = powerpress_readable_duration($playtime_string, true); // Fix so it looks better when viewed for editing } $GeneralSettings = get_option('powerpress_general'); if (empty($GeneralSettings['hide_warnings']) && count($Mp3Info->GetWarnings()) > 0) { $Warnings = $Mp3Info->GetWarnings(); while (list($null, $warning) = each($Warnings)) { $warning = sprintf(__('Warning, Media URL %s', 'powerpress'), $media_file) . ': ' . $warning . ' [<a href="http://create.blubrry.com/resources/powerpress/using-powerpress/warning-messages-explained/" target="_blank">' . __('PowerPress Warnings Explained', 'powerpress') . '</a>]'; if ($return_warnings) { $warning_msg .= $warning; } else { powerpress_add_error($warning); } } } } else { if ($Mp3Info->GetError() != '') { return array('error' => $Mp3Info->GetError()); } else { return array('error' => __('Error occurred obtaining media information.', 'powerpress')); } } if ($file_size == 0) { return array('error' => __('Error occurred obtaining media file size.', 'powerpress')); } if ($return_warnings && $warning_msg != '') { return array('content-type' => $content_type, 'length' => $file_size, 'duration' => $duration, 'warnings' => $warning_msg); } return array('content-type' => $content_type, 'length' => $file_size, 'duration' => $duration); // OLD CODE FOLLOWS: if ($content_type == 'audio/mpeg' && $duration === '') { // Lets use the mp3info class: require_once POWERPRESS_ABSPATH . '/mp3info.class.php'; $Mp3Info = new Mp3Info(); if (defined('POWERPRESS_DOWNLOAD_BYTE_LIMIT')) { $Mp3Info->SetDownloadBytesLimit(POWERPRESS_DOWNLOAD_BYTE_LIMIT); } $Mp3Data = $Mp3Info->GetMp3Info($media_file); if ($Mp3Data) { if ($Mp3Info->GetRedirectCount() > 5) { // Add a warning that the redirect count exceeded 5, which may prevent some podcatchers from downloading the media. powerpress_add_error(sprintf(__('Warning, the Media URL %s contains %d redirects.', 'powerpress'), $media_file, $Mp3Info->GetRedirectCount()) . ' [<a href="http://create.blubrry.com/resources/powerpress/using-powerpress/warning-messages-explained/" target="_blank">' . __('PowerPress Warnings Explained', 'powerpress') . '</a>]'); } if ($file_size == 0) { $file_size = $Mp3Info->GetContentLength(); } $playtime_string = !empty($Mp3Data['playtime_string']) ? $Mp3Data['playtime_string'] : ''; $duration = powerpress_readable_duration($playtime_string, true); // Fix so it looks better when viewed for editing if (count($Mp3Info->GetWarnings()) > 0) { $Warnings = $Mp3Info->GetWarnings(); while (list($null, $warning) = each($Warnings)) { powerpress_add_error(sprintf(__('Warning, Media URL %s', 'powerpress'), $media_file) . ': ' . $warning . ' [<a href="http://create.blubrry.com/resources/powerpress/using-powerpress/warning-messages-explained/" target="_blank">' . __('PowerPress Warnings Explained', 'powerpress') . '</a>]'); } } } else { if ($Mp3Info->GetError()) { return array('error' => $Mp3Info->GetError()); } else { return array('error' => __('Error occurred obtaining media information.', 'powerpress')); } } } $wp_remote_options = array(); $wp_remote_options['user-agent'] = 'Blubrry PowerPress/' . POWERPRESS_VERSION; $wp_remote_options['httpversion'] = '1.1'; if ($content_type != '' && $file_size == 0) { $response = wp_remote_head($media_file, array('httpversion' => 1.1)); // Redirect 1 if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) { $headers = wp_remote_retrieve_headers($response); $response = wp_remote_head($headers['location'], $wp_remote_options); } // Redirect 2 if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) { $headers = wp_remote_retrieve_headers($response); $response = wp_remote_head($headers['location'], $wp_remote_options); } // Redirect 3 if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) { $headers = wp_remote_retrieve_headers($response); $response = wp_remote_head($headers['location'], $wp_remote_options); } // Redirect 4 if (!is_wp_error($response) && ($response['response']['code'] == 301 || $response['response']['code'] == 302)) { $headers = wp_remote_retrieve_headers($response); $response = wp_remote_head($headers['location'], $wp_remote_options); } if (is_wp_error($response)) { return array('error' => $response->get_error_message()); } if (isset($response['response']['code']) && $response['response']['code'] < 200 || $response['response']['code'] > 290) { return array('error' => __('Error, HTTP', 'powerpress') . ' ' . $response['response']['code']); } $headers = wp_remote_retrieve_headers($response); if ($headers && $headers['content-length']) { $file_size = (int) $headers['content-length']; } else { return array('error' => __('Unable to obtain file size of media file.', 'powerpress')); } } if ($file_size == 0) { return array('error' => __('Error occurred obtaining media file size.', 'powerpress')); } return array('content-type' => $content_type, 'length' => $file_size, 'duration' => $duration); }