wp_read_audio_metadata

Retrieve metadata from a audio file's ID3 tags.

Description

(array|bool) wp_read_audio_metadata( (string) $file ); 

Returns (array|bool)

Returns array of metadata, if found.

Parameters (1)

0. $file (string)
Path to file.

Usage

  1. if ( !function_exists( 'wp_read_audio_metadata' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/media.php'; 
  3.  
  4. // Path to file. 
  5. $file = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_read_audio_metadata($file); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/media.php  
  1. function wp_read_audio_metadata( $file ) { 
  2. if ( ! file_exists( $file ) ) { 
  3. return false; 
  4. $metadata = array(); 
  5.  
  6. if ( ! defined( 'GETID3_TEMP_DIR' ) ) { 
  7. define( 'GETID3_TEMP_DIR', get_temp_dir() ); 
  8.  
  9. if ( ! class_exists( 'getID3', false ) ) { 
  10. require( ABSPATH . WPINC . '/ID3/getid3.php' ); 
  11. $id3 = new getID3(); 
  12. $data = $id3->analyze( $file ); 
  13.  
  14. if ( ! empty( $data['audio'] ) ) { 
  15. unset( $data['audio']['streams'] ); 
  16. $metadata = $data['audio']; 
  17.  
  18. if ( ! empty( $data['fileformat'] ) ) 
  19. $metadata['fileformat'] = $data['fileformat']; 
  20. if ( ! empty( $data['filesize'] ) ) 
  21. $metadata['filesize'] = (int) $data['filesize']; 
  22. if ( ! empty( $data['mime_type'] ) ) 
  23. $metadata['mime_type'] = $data['mime_type']; 
  24. if ( ! empty( $data['playtime_seconds'] ) ) 
  25. $metadata['length'] = (int) round( $data['playtime_seconds'] ); 
  26. if ( ! empty( $data['playtime_string'] ) ) 
  27. $metadata['length_formatted'] = $data['playtime_string']; 
  28.  
  29. wp_add_id3_tag_data( $metadata, $data ); 
  30.  
  31. return $metadata;