我最近发现了一个网站,允许您上传文件并更改其ID3标签(图片,标题,所有其他内容 )目前我在将文件从外部推送之前从另一个网站解析后将文件存储在目录中。
我想知道是否有人知道一个库,我可以在其中阅读如何更改 PHP 中的默认ID3标签?这是 PHP 的现有功能吗?
答案 0 :(得分:4)
if( writeTags($row['title'],$new) ) {
$fileName = rand(000000000,999999999).'_'.rand(0000000000,9999999999).'_'.rand(000000000,999999999).'.mp3';
$imageName = rand(000000000,999999999).'_'.rand(0000000000,9999999999).'_'.rand(000000000,999999999).'.jpg';
rename($new, $DPATH.'uploads/tracks/'.$fileName);
save_image($row['image'],$DPATH.'uploads/media/'.$imageName);
$track['uid'] = 151;
$track['title'] = $row['title'];
$track['description'] = '';
# fileName
$track['name'] = $fileName;
# make tag
$track['tag'] = $tag.',';
# download image
$track['art'] = $imageName;
# today date
$track['release'] = date("Y-m-d");
$track['size'] = filesize($DPATH.'uploads/tracks/'.$fileName);
$row['slippery_id'] = add_to_slippery($track);
}
function writeTags($title,$file) {
$TextEncoding = 'UTF-8';
require_once($DPATH.'cron/getid3/getid3.php');
$getID3 = new getID3;
$getID3->setOption(array('encoding'=>$TextEncoding));
require_once($DPATH.'cron/getid3/write.php');
$tagwriter = new getid3_writetags;
$tagwriter->filename = $file;
$tagwriter->tagformats = array('id3v1','id3v2.3');
$tagwriter->overwrite_tags = true;
$tagwriter->tag_encoding = $TextEncoding;
$tagwriter->remove_other_tags = true;
$TagData = array(
'album' => array($MP3TAG),
'comment' => array($MP3TAG),
);
$fd = fopen($DPATH.'cron/mp3image.png', 'rb');
$APICdata = fread($fd, filesize($DPATH.'cron/mp3image.png'));
fclose($fd);
$TagData['attached_picture'][0]['data'] = $APICdata;
$TagData['attached_picture'][0]['picturetypeid'] = 2;
$TagData['attached_picture'][0]['description'] = $MP3TAG;
$TagData['attached_picture'][0]['mime'] = 'image/jpeg';
$tagwriter->tag_data = $TagData;
if ($tagwriter->WriteTags()) {
return true;
} else {
return false;
}
}
我最近做了类似的事情,您可以编辑上面的代码以符合您的要求,如果您希望我更有帮助您应该在您的问题中提供自己的代码。
请注意,提出这样的问题往往是你的问题如何被关闭,将来好运,我希望这会对你有所帮助。
编辑:使用此GitHub获取ID3标记。
答案 1 :(得分:0)
我最近为eyeD3制作了一个PHP包装器,这是一个用于读取和更新ID3元数据的优秀python模块。看看here
如果您熟悉Composer,则使用非常简单。但是,您需要install eyed3才能使用它。然后:
使用composer:
安装php包装器composer require stormiix/php-eyed3 dev-master
将库添加到您的代码中:
require __DIR__ . '/vendor/autoload.php';
使用以下代码阅读&更新标签。
use Stormiix\EyeD3\EyeD3;
$eyed3 = new EyeD3("mp3 file path");
$tags = $eyed3->readMeta();
// $tags is an array that contains the following keys:
// artist, title, album, comment(s), lyrics ..etc
$meta = [
"artist" => "MyArtist",
"title" => "MyTitle",
"album" => "MyAlbum",
"comment" => "MyComment",
"lyrics" => "MyLyrics",
"album_art" => "cover.png"
];
// Update the mp3 file with the new meta tags
$eyed3->updateMeta($meta);