| 1545 | |
| 1546 | /** |
| 1547 | * Retrieve metadata from a video file's ID3 tags |
| 1548 | * |
| 1549 | * @since 3.6.0 |
| 1550 | * |
| 1551 | * @param string $file Path to file. |
| 1552 | * @return array|boolean Returns array of metadata, if found. |
| 1553 | */ |
| 1554 | function wp_read_video_metadata( $file ) { |
| 1555 | if ( ! file_exists( $file ) ) |
| 1556 | return false; |
| 1557 | |
| 1558 | $metadata = array(); |
| 1559 | |
| 1560 | if ( ! class_exists( 'getID3' ) ) |
| 1561 | require( ABSPATH . WPINC . '/ID3/class-getid3.php' ); |
| 1562 | $id3 = new getID3(); |
| 1563 | $data = $id3->analyze( $file ); |
| 1564 | |
| 1565 | if ( isset( $data['video']['lossless'] ) ) |
| 1566 | $metadata['lossless'] = $data['video']['lossless']; |
| 1567 | if ( ! empty( $data['video']['bitrate'] ) ) |
| 1568 | $metadata['bitrate'] = (int) $data['video']['bitrate']; |
| 1569 | if ( ! empty( $data['video']['bitrate_mode'] ) ) |
| 1570 | $metadata['bitrate_mode'] = $data['video']['bitrate_mode']; |
| 1571 | if ( ! empty( $data['filesize'] ) ) |
| 1572 | $metadata['filesize'] = (int) $data['filesize']; |
| 1573 | if ( ! empty( $data['mime_type'] ) ) |
| 1574 | $metadata['mime_type'] = $data['mime_type']; |
| 1575 | if ( ! empty( $data['playtime_seconds'] ) ) |
| 1576 | $metadata['length'] = (int) ceil( $data['playtime_seconds'] ); |
| 1577 | if ( ! empty( $data['playtime_string'] ) ) |
| 1578 | $metadata['length_formatted'] = $data['playtime_string']; |
| 1579 | if ( ! empty( $data['video']['resolution_x'] ) ) |
| 1580 | $metadata['width'] = (int) $data['video']['resolution_x']; |
| 1581 | if ( ! empty( $data['video']['resolution_y'] ) ) |
| 1582 | $metadata['height'] = (int) $data['video']['resolution_y']; |
| 1583 | if ( ! empty( $data['video']['dataformat'] ) ) |
| 1584 | $metadata['format'] = $data['video']['dataformat']; |
| 1585 | if ( ! empty( $data['video']['encoder'] ) ) |
| 1586 | $metadata['encoder'] = $data['video']['encoder']; |
| 1587 | if ( ! empty( $data['video']['codec'] ) ) |
| 1588 | $metadata['codec'] = $data['video']['codec']; |
| 1589 | |
| 1590 | unset( $data['audio']['streams'] ); |
| 1591 | $metadata['audio'] = $data['audio']; |
| 1592 | |
| 1593 | return $metadata; |
| 1594 | } |
| 1595 | |
| 1596 | /** |
| 1597 | * Retrieve metadata from a audio file's ID3 tags |
| 1598 | * |
| 1599 | * @since 3.6.0 |
| 1600 | * |
| 1601 | * @param string $file Path to file. |
| 1602 | * @return array|boolean Returns array of metadata, if found. |
| 1603 | */ |
| 1604 | function wp_read_audio_metadata( $file ) { |
| 1605 | if ( ! file_exists( $file ) ) |
| 1606 | return false; |
| 1607 | $metadata = array(); |
| 1608 | |
| 1609 | if ( ! class_exists( 'getID3' ) ) |
| 1610 | require( ABSPATH . WPINC . '/ID3/class-getid3.php' ); |
| 1611 | $id3 = new getID3(); |
| 1612 | $data = $id3->analyze( $file ); |
| 1613 | |
| 1614 | if ( ! empty( $data['audio'] ) ) { |
| 1615 | unset( $data['audio']['streams'] ); |
| 1616 | $metadata = $data['audio']; |
| 1617 | if ( ! empty( $data['filesize'] ) ) |
| 1618 | $metadata['filesize'] = (int) $data['filesize']; |
| 1619 | if ( ! empty( $data['mime_type'] ) ) |
| 1620 | $metadata['mime_type'] = $data['mime_type']; |
| 1621 | if ( ! empty( $data['playtime_seconds'] ) ) |
| 1622 | $metadata['length'] = (int) ceil( $data['playtime_seconds'] ); |
| 1623 | if ( ! empty( $data['playtime_string'] ) ) |
| 1624 | $metadata['length_formatted'] = $data['playtime_string']; |
| 1625 | } |
| 1626 | return $metadata; |
| 1627 | } |
| 1628 | No newline at end of file |