Ticket #35218: 35218.7.diff
File 35218.7.diff, 6.5 KB (added by , 7 years ago) |
---|
-
src/wp-admin/includes/media.php
diff --git src/wp-admin/includes/media.php src/wp-admin/includes/media.php index 6bb541dd35..f60fd6bd82 100644
function wp_read_video_metadata( $file ) { 3082 3082 $metadata['audio'] = $data['audio']; 3083 3083 } 3084 3084 3085 if ( empty( $metadata['created_timestamp'] ) ) { 3086 $created_timestamp = wp_get_media_creation_timestamp( $data ); 3087 3088 if ( $created_timestamp !== false ) { 3089 $metadata['created_timestamp'] = $created_timestamp; 3090 } 3091 } 3092 3085 3093 wp_add_id3_tag_data( $metadata, $data ); 3086 3094 3087 return $metadata; 3095 $file_format = isset( $metadata['fileformat'] ) ? $metadata['fileformat'] : null; 3096 3097 /** 3098 * Filters the array of metadata retrieved from a video. 3099 * 3100 * In core, usually this selection is what is stored. 3101 * More complete data can be parsed from the `$data` parameter. 3102 * 3103 * @since 4.9.0 3104 * 3105 * @param array $metadata Filtered Video metadata. 3106 * @param string $file Path to video file. 3107 * @param string $file_format File format of video, as analyzed by getID3. 3108 * @param string $data Raw metadata from getID3. 3109 */ 3110 return apply_filters( 'wp_read_video_metadata', $metadata, $file, $file_format, $data ); 3088 3111 } 3089 3112 3090 3113 /** … … function wp_read_audio_metadata( $file ) { 3133 3156 } 3134 3157 3135 3158 /** 3159 * Parse creation date from media metadata. 3160 * 3161 * The getID3 library doesn't have a standard method for getting creation dates, 3162 * so the location of this data can vary based on the MIME type. 3163 * 3164 * @since 4.9.0 3165 * 3166 * @link https://github.com/JamesHeinrich/getID3/blob/master/structure.txt 3167 * 3168 * @param array $metadata The metadata returned by getID3::analyze(). 3169 * @return int|bool A UNIX timestamp for the media's creation date if available 3170 * or a boolean FALSE if a timestamp could not be determined. 3171 */ 3172 function wp_get_media_creation_timestamp( $metadata ) { 3173 $creation_date = false; 3174 3175 if ( empty( $metadata['fileformat'] ) ) { 3176 return $creation_date; 3177 } 3178 3179 switch ( $metadata['fileformat'] ) { 3180 case 'asf': 3181 if ( isset( $metadata['asf']['file_properties_object']['creation_date_unix'] ) ) { 3182 $creation_date = (int) $metadata['asf']['file_properties_object']['creation_date_unix']; 3183 } 3184 break; 3185 3186 case 'matroska': 3187 case 'webm': 3188 if ( isset( $metadata['matroska']['comments']['creation_time']['0'] ) ) { 3189 $creation_date = strtotime( $metadata['matroska']['comments']['creation_time']['0'] ); 3190 } 3191 elseif ( isset( $metadata['matroska']['info']['0']['DateUTC_unix'] ) ) { 3192 $creation_date = (int) $metadata['matroska']['info']['0']['DateUTC_unix']; 3193 } 3194 break; 3195 3196 case 'quicktime': 3197 case 'mp4': 3198 if ( isset( $metadata['quicktime']['moov']['subatoms']['0']['creation_time_unix'] ) ) { 3199 $creation_date = (int) $metadata['quicktime']['moov']['subatoms']['0']['creation_time_unix']; 3200 } 3201 break; 3202 } 3203 3204 return $creation_date; 3205 } 3206 3207 /** 3136 3208 * Encapsulate logic for Attach/Detach actions 3137 3209 * 3138 3210 * @since 4.2.0 -
tests/phpunit/tests/media.php
diff --git tests/phpunit/data/uploads/small-video.mkv tests/phpunit/data/uploads/small-video.mkv new file mode 100644 index 0000000000..2b3308441f Binary files /dev/null and tests/phpunit/data/uploads/small-video.mkv differ diff --git tests/phpunit/data/uploads/small-video.mov tests/phpunit/data/uploads/small-video.mov new file mode 100644 index 0000000000..2cfbb86464 Binary files /dev/null and tests/phpunit/data/uploads/small-video.mov differ diff --git tests/phpunit/data/uploads/small-video.webm tests/phpunit/data/uploads/small-video.webm new file mode 100644 index 0000000000..63a974986b Binary files /dev/null and tests/phpunit/data/uploads/small-video.webm differ diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php index 8fb3cc09d7..6ef721b02c 100644
EOF; 2067 2067 $attachment_id = wp_insert_attachment( $data, '', 0 ); 2068 2068 $this->assertSame( 0, $attachment_id ); 2069 2069 } 2070 2071 /** 2072 * @ticket 35218 2073 */ 2074 function test_wp_get_media_creation_timestamp_video_asf() { 2075 $metadata = array( 2076 'fileformat' => 'asf', 2077 'asf' => array( 2078 'file_properties_object' => array( 2079 'creation_date_unix' => 123, 2080 ), 2081 ), 2082 ); 2083 2084 $this->assertEquals( 123, wp_get_media_creation_timestamp( $metadata ) ); 2085 } 2086 2087 /** 2088 * @ticket 35218 2089 */ 2090 function test_wp_get_media_creation_timestamp_video_matroska() { 2091 $metadata = array( 2092 'fileformat' => 'matroska', 2093 'matroska' => array( 2094 'comments' => array( 2095 'creation_time' => array( 2096 '2015-12-24T17:40:09Z' 2097 ), 2098 ), 2099 ), 2100 ); 2101 2102 $this->assertEquals( 1450978809, wp_get_media_creation_timestamp( $metadata ) ); 2103 } 2104 2105 /** 2106 * @ticket 35218 2107 */ 2108 function test_wp_get_media_creation_timestamp_video_quicktime() { 2109 $metadata = array( 2110 'fileformat' => 'quicktime', 2111 'quicktime' => array( 2112 'moov' => array( 2113 'subatoms' => array( 2114 array( 2115 'creation_time_unix' => 1450978805, 2116 ), 2117 ), 2118 ), 2119 ), 2120 ); 2121 2122 $this->assertEquals( 1450978805, wp_get_media_creation_timestamp( $metadata ) ); 2123 } 2124 2125 /** 2126 * @ticket 35218 2127 */ 2128 function test_wp_get_media_creation_timestamp_video_webm() { 2129 $metadata = array( 2130 'fileformat' => 'webm', 2131 'matroska' => array( 2132 'info' => array( 2133 array( 2134 'DateUTC_unix' => 1265680539, 2135 ), 2136 ), 2137 ), 2138 ); 2139 2140 $this->assertEquals( 1265680539, wp_get_media_creation_timestamp( $metadata ) ); 2141 } 2142 2143 /** 2144 * @ticket 35218 2145 */ 2146 function test_wp_read_video_metadata_adds_creation_date_with_quicktime() { 2147 $video = DIR_TESTDATA . '/uploads/small-video.mov'; 2148 $metadata = wp_read_video_metadata( $video ); 2149 2150 $this->assertEquals( 1269120551, $metadata['created_timestamp'] ); 2151 } 2152 2153 /** 2154 * @ticket 35218 2155 */ 2156 function test_wp_read_video_metadata_adds_creation_date_with_mp4() { 2157 $video = DIR_TESTDATA . '/uploads/small-video.mp4'; 2158 $metadata = wp_read_video_metadata( $video ); 2159 2160 $this->assertEquals( 1269120551, $metadata['created_timestamp'] ); 2161 } 2162 2163 /** 2164 * @ticket 35218 2165 */ 2166 function test_wp_read_video_metadata_adds_creation_date_with_mkv() { 2167 $video = DIR_TESTDATA . '/uploads/small-video.mkv'; 2168 $metadata = wp_read_video_metadata( $video ); 2169 2170 $this->assertEquals( 1269120551, $metadata['created_timestamp'] ); 2171 } 2172 2173 /** 2174 * @ticket 35218 2175 */ 2176 function test_wp_read_video_metadata_adds_creation_date_with_webm() { 2177 $video = DIR_TESTDATA . '/uploads/small-video.webm'; 2178 $metadata = wp_read_video_metadata( $video ); 2179 2180 $this->assertEquals( 1269120551, $metadata['created_timestamp'] ); 2181 } 2070 2182 } 2071 2183 2072 2184 /**