From 25e9a6d2493fe0de23e9ba0ed4e7e2f270c9b60a Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Thu, 10 Jan 2019 01:31:52 +0000 Subject: [PATCH] Media: Store audio creation date in meta. In [41746], `wp_get_media_creation_timestamp()` was introduced to read the created timestamp for videos from `getID3` in meta whenever possible. This information is useful separately from the dates on the file itself. This adds the same support audio files by utilizing `wp_get_media_creation_timestamp()` in `wp_read_audio_metadata()`. Props blob folio, desrosj. Fixes #42017. git-svn-id: https://develop.svn.wordpress.org/trunk@44528 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/media.php | 10 +++++++++- tests/phpunit/tests/media.php | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/media.php b/src/wp-admin/includes/media.php index 93eceeca3a..f44f01559f 100644 --- a/src/wp-admin/includes/media.php +++ b/src/wp-admin/includes/media.php @@ -3340,7 +3340,7 @@ function wp_read_video_metadata( $file ) { } /** - * Retrieve metadata from a audio file's ID3 tags + * Retrieve metadata from an audio file's ID3 tags. * * @since 3.6.0 * @@ -3384,6 +3384,14 @@ function wp_read_audio_metadata( $file ) { $metadata['length_formatted'] = $data['playtime_string']; } + if ( empty( $metadata['created_timestamp'] ) ) { + $created_timestamp = wp_get_media_creation_timestamp( $data ); + + if ( false !== $created_timestamp ) { + $metadata['created_timestamp'] = $created_timestamp; + } + } + wp_add_id3_tag_data( $metadata, $data ); return $metadata; diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index eea6f24a90..d9c34e5b9d 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -2343,6 +2343,21 @@ EOF; $this->assertEquals( 1265680539, wp_get_media_creation_timestamp( $metadata ) ); } + /** + * Test created timestamp is properly read from an MP4 file. + * + * This MP4 video file has an AAC audio track, so it can be used to test + *`wp_read_audio_metadata()`. + * + * @ticket 42017 + */ + function test_wp_read_audio_metadata_adds_creation_date_with_mp4() { + $video = DIR_TESTDATA . '/uploads/small-video.mp4'; + $metadata = wp_read_audio_metadata( $video ); + + $this->assertEquals( 1269120551, $metadata['created_timestamp'] ); + } + /** * @ticket 35218 */