WordPress at a glance

wp_read_audio_metadata() WP 1.0

Retrieve metadata from a audio file's ID3 tags

✈ 1 time = 0.014777s = extremely slow | 50000 times = 1538.81s = extremely slow | PHP 7.0.5, WP 4.5

No Hooks.

Return

Array/true/false. Returns array of metadata, if found.

Usage

wp_read_audio_metadata( $file );
$file(string) (required)
Path to file.

Code of wp read audio metadata: wp-admin/includes/media.php VER 5.1.1

<?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'];
	}

	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;
}

Related Functions

From category: Metadata (postmeta)

No comments
    Hello, !     Log In . Register