pyrex-fwi / id3
v1.0.0
2016-07-18 17:26 UTC
Requires
- symfony/process: ^3.1
Requires (Dev)
- phpunit/phpunit: 5.1.3
This package is not auto-updated.
Last update: 2022-02-01 12:53:52 UTC
README
该包为基础提供简单的ID3标签操作。
您可以定义读取器和写入器来操作读或写时的元数据。
| 二进制读取器 | 可用 | MP3读取 | MP3写入 | MP4读取 | MP4写入 | FLAC读取 | FLAC写入 |
|---|---|---|---|---|---|---|---|
| MediaInfo | ✓ | ✓ | 否 | ✓ | - | ✓ | 否 |
| EyeD3 | ✓ | ✓ | ✓ | - | - | - | 否 |
| Id3v2 | ✓ | ✓ | ✓ | - | - | - | 否 |
| metaflac | ✓ | 否 | ✓ | - | - | - | ✓ |
用法
读取ID3标签
<?php class MyClass { public function readId3() { $mp3OrFlacFile = '/path/to/file'; /** @var Sapar\Id3\Metadata\Id3MetadataInterface */ $id3Metadata = new Sapar\Metadata\Id3Metadata($mp3OrFlacFile); /** @var Sapar\Wrapper\BinWrapper\BinWrapperInterface */ $mediaInfoWrapper = new Sapar\Wrapper\BinWrapper\MediainfoWrapper(); $mediaInfoWrapper->setBin('/usr/local/bin/mediainfo'); if ($mediaInfoWrapper->read($metaDataFile)) { $metaDataFile->getTitle(); $metaDataFile->getArtist(); $metaDataFile->getAlbum(); $metaDataFile->getGenre(); $metaDataFile->getYear(); $metaDataFile->getBpm(); $metaDataFile->getTimeDuration(); } } }
写入ID3标签
<?php class MyClass { public function writeId3() { $mp3OrFlacFile = '/path/to/file'; /** @var Sapar\Id3\Metadata\Id3MetadataInterface */ $id3Metadata = new Sapar\Metadata\Id3Metadata($mp3OrFlacFile); $id3Metadata->setAlbum('album'); $id3Metadata->setTitle('title'); $id3Metadata->setGenre('genre'); $id3Metadata->setYear(2016); $id3Metadata->setComment('comment'); $id3Metadata->setBpm(120); /** @var Sapar\Wrapper\BinWrapper\BinWrapperInterface */ $id3v2wrapper = new Sapar\Wrapper\BinWrapper\Id3v2Wrapper(); $id3v2wrapper->setBin('/usr/local/bin/id3v2'); if ($mediaInfoReader->write($metaDataFile)) { //it's done! } }
创建自定义包装器
<?php class MyClass { }
测试
确保MediaInfo在位置/usr/bin/mediainfo处可用。
确保eyeD3在位置/usr/local/bin/eyeD3处可用。
基准:phpunit --group eyed3-read --repeat 100 phpunit --group mediainfo-read --repeat 100