Ticket #35218: 35218.patch
File 35218.patch, 6.5 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/media.php
3026 3026 $metadata['audio'] = $data['audio']; 3027 3027 } 3028 3028 3029 if ( empty( $metadata['created_timestamp'] ) ) { 3030 $metadata['created_timestamp'] = wp_get_media_creation_timestamp( $data ); 3031 } 3032 3029 3033 wp_add_id3_tag_data( $metadata, $data ); 3030 3034 3031 3035 return $metadata; … … 3077 3081 } 3078 3082 3079 3083 /** 3084 * Attempt to parse a date out of ID3 data. 3085 * 3086 * The getID3 library doesn't have a standard method for getting creation dates, 3087 * so the location of this data can vary based on the MIME type. 3088 * 3089 * @since 4.5.0 3090 * 3091 * @link https://github.com/JamesHeinrich/getID3/blob/master/structure.txt 3092 * 3093 * @param array $metadata The metadata returned by getID3::analyze(). 3094 * @return int|bool A UNIX timestamp for the media's creation date if available 3095 * or a boolean FALSE if a timestamp could not be determined. 3096 */ 3097 function wp_get_media_creation_timestamp( $metadata ) { 3098 $creation_date = false; 3099 3100 if ( empty( $metadata['fileformat'] ) ) { 3101 return $creation_date; 3102 } 3103 3104 switch ( $metadata['fileformat'] ) { 3105 case 'asf': 3106 if ( isset( $metadata['asf']['file_properties_object']['creation_date_unix'] ) ) { 3107 $creation_date = (int) $metadata['asf']['file_properties_object']['creation_date_unix']; 3108 } 3109 break; 3110 3111 case 'matroska': 3112 if ( isset( $metadata['matroska']['comments']['creation_time']['0'] ) ) { 3113 $creation_date = strtotime( $metadata['matroska']['comments']['creation_time']['0'] ); 3114 } 3115 break; 3116 3117 case 'quicktime': 3118 case 'mp4': 3119 if ( isset( $metadata['quicktime']['moov']['subatoms']['0']['creation_time'] ) ) { 3120 $creation_date = (int) $metadata['quicktime']['moov']['subatoms']['0']['creation_time']; 3121 } 3122 break; 3123 } 3124 3125 return $creation_date; 3126 } 3127 3128 /** 3080 3129 * Encapsulate logic for Attach/Detach actions 3081 3130 * 3082 3131 * @since 4.2.0 -
tests/phpunit/data/videos/mkv.mkv
Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
-
tests/phpunit/data/videos/mp4.m4v
Property changes on: tests/phpunit/data/videos/mkv.mkv ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
-
tests/phpunit/data/videos/quicktime.mov
Property changes on: tests/phpunit/data/videos/mp4.m4v ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
-
tests/phpunit/tests/media.php
Property changes on: tests/phpunit/data/videos/quicktime.mov ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property
1177 1177 // Intermediate sized GIFs should not include the full size in the srcset. 1178 1178 $this->assertFalse( strpos( wp_calculate_image_srcset( $size_array, $large_src, $image_meta ), $full_src ) ); 1179 1179 } 1180 1181 /** 1182 * @ticket 35218 1183 */ 1184 function test_wp_get_media_creation_timestamp_video_asf() { 1185 $this->markTestIncomplete( 'Need to verify ASF structure' ); 1186 1187 $metadata = array( 1188 'fileformat' => 'asf', 1189 'asf' => array( 1190 'file_properties_object' => array( 1191 'creation_date_unix' => 123, 1192 ), 1193 ), 1194 ); 1195 1196 $this->assertEquals( 123, wp_get_media_creation_timestamp( $metadata ) ); 1197 } 1198 1199 /** 1200 * @ticket 35218 1201 */ 1202 function test_wp_get_media_creation_timestamp_video_matroska() { 1203 $metadata = array( 1204 'fileformat' => 'matroska', 1205 'matroska' => array( 1206 'comments' => array( 1207 'creation_time' => array( 1208 '2015-12-24T17:40:09Z' 1209 ), 1210 ), 1211 ), 1212 ); 1213 1214 $this->assertEquals( 1450978809, wp_get_media_creation_timestamp( $metadata ) ); 1215 } 1216 1217 /** 1218 * @ticket 35218 1219 */ 1220 function test_wp_get_media_creation_timestamp_video_quicktime() { 1221 $metadata = array( 1222 'fileformat' => 'quicktime', 1223 'quicktime' => array( 1224 'moov' => array( 1225 'subatoms' => array( 1226 array( 1227 'creation_time' => 3533823605, 1228 ), 1229 ), 1230 ), 1231 ), 1232 ); 1233 1234 $this->assertEquals( 3533823605, wp_get_media_creation_timestamp( $metadata ) ); 1235 } 1236 1237 /** 1238 * @ticket 35218 1239 */ 1240 function test_wp_read_video_metadata_adds_creation_date_with_quicktime() { 1241 $video = DIR_TESTDATA . '/videos/quicktime.mov'; 1242 $metadata = wp_read_video_metadata( $video ); 1243 1244 $this->assertNotEquals( false, $metadata['created_timestamp'] ); 1245 } 1246 1247 /** 1248 * @ticket 35218 1249 */ 1250 function test_wp_read_video_metadata_adds_creation_date_with_mp4() { 1251 $video = DIR_TESTDATA . '/videos/mp4.m4v'; 1252 $metadata = wp_read_video_metadata( $video ); 1253 1254 $this->assertNotEquals( false, $metadata['created_timestamp'] ); 1255 } 1256 1257 /** 1258 * @ticket 35218 1259 */ 1260 function test_wp_read_video_metadata_adds_creation_date_with_mkv() { 1261 $video = DIR_TESTDATA . '/videos/mkv.mkv'; 1262 $metadata = wp_read_video_metadata( $video ); 1263 1264 $this->assertNotEquals( false, $metadata['created_timestamp'] ); 1265 } 1180 1266 }