从音频文件的ID3标签中检索元数据

原型

wp_read_audio_metadata( string $file )

参数

$file (string) (Required) 文件路径。

返回值

(array|bool)  返回元数据数组(如果找到)。

源文件

路径:wp-admin/includes/media.php

<?php
...
function wp_read_audio_metadata( $file ) {
	if ( ! file_exists( $file ) ) {
		return false;
	}
	$metadata = array();
	if ( ! defined( 'GETID3_TEMP_DIR' ) ) {
		define( 'GETID3_TEMP_DIR', get_temp_dir() );
	}
	if ( ! class_exists( 'getID3', false ) ) {
		require( ABSPATH . WPINC . '/ID3/getid3.php' );
	}
	$id3 = new getID3();
	$data = $id3->analyze( $file );
	if ( ! empty( $data['audio'] ) ) {
		unset( $data['audio']['streams'] );
		$metadata = $data['audio'];
	}
	if ( ! empty( $data['fileformat'] ) )
		$metadata['fileformat'] = $data['fileformat'];
	if ( ! empty( $data['filesize'] ) )
		$metadata['filesize'] = (int) $data['filesize'];
	if ( ! empty( $data['mime_type'] ) )
		$metadata['mime_type'] = $data['mime_type'];
	if ( ! empty( $data['playtime_seconds'] ) )
		$metadata['length'] = (int) round( $data['playtime_seconds'] );
	if ( ! empty( $data['playtime_string'] ) )
		$metadata['length_formatted'] = $data['playtime_string'];
	wp_add_id3_tag_data( $metadata, $data );
	return $metadata;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/wp_read_audio_metadata/