Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用php设置mp3的相册艺术_Php_Id3 - Fatal编程技术网

用php设置mp3的相册艺术

用php设置mp3的相册艺术,php,id3,Php,Id3,我正在寻找最好的或任何方式来设置专辑艺术的MP3使用PHP 建议?我认为使用PHP真的不可能。我的意思是,我认为任何事情都是可能的,但它可能不是一个本机PHP解决方案。从中,我认为唯一可以更新的项目是: 头衔 艺术家 相册 年 体裁 评论 跟踪 对不起,伙计。也许Perl、Python或Ruby有一些解决方案 我不确定您是否熟悉Perl(我个人不喜欢它,但是,它擅长这样的事情……)。这里有一个脚本,似乎可以在MP3中插入和编辑相册艺术:您可以查看。我不能保证它可以处理图像,但它确实声称能够为

我正在寻找最好的或任何方式来设置专辑艺术的MP3使用PHP


建议?

我认为使用PHP真的不可能。我的意思是,我认为任何事情都是可能的,但它可能不是一个本机PHP解决方案。从中,我认为唯一可以更新的项目是:

  • 头衔
  • 艺术家
  • 相册
  • 体裁
  • 评论
  • 跟踪
对不起,伙计。也许Perl、Python或Ruby有一些解决方案


我不确定您是否熟悉Perl(我个人不喜欢它,但是,它擅长这样的事情……)。这里有一个脚本,似乎可以在MP3中插入和编辑相册艺术:

您可以查看。我不能保证它可以处理图像,但它确实声称能够为MP3编写ID3标签,因此我认为这将是您的最佳选择。

相册艺术是一个数据帧,根据ID3v2规范,被标识为“附加图片”,并且 getID3()现在是使用纯PHP在ID3v2中写入所有可能数据帧的唯一方法

看看这个来源:

在源中搜索此文本:

// 4.14  APIC Attached picture
有一段代码负责编写专辑艺术


另一种方式,似乎没有纯PHP那么慢,就是使用一些外部应用程序,这些应用程序将由PHP脚本启动。如果您的服务设计为在高负载下工作,二进制编译工具将是一个更好的解决方案。

不确定这是否仍然是一个问题,但:


完成得惊人的getid3()()项目将解决您的所有问题。查看论坛帖子了解更多信息。

更好(更快)的方法是通过外部应用程序和PHP exec()函数来调用命令。我推荐。

与其只分享专辑艺术更新的代码,不如在这里发布我的整个MP3包装类getID3,这样你就可以随心所欲地使用了

用法 等级
以下是使用getID3添加图像和ID3数据的基本代码。(@frostymarvelous”包装器包含等效的代码,但我认为展示基本内容会有所帮助。)


使用PHP的内置函数

<?php
    $tag = id3_get_tag( "path/to/example.mp3" );
    print_r($tag);
?>

使用composer安装getId3
composer需要james heinrich/getId3
然后使用此代码更新id3标记

// Initialize getID3 engine
$getID3 = new getID3;

// Initialize getID3 tag-writing module
$tagwriter = new getid3_writetags;
$tagwriter->filename = 'path/to/file.mp3';
$tagwriter->tagformats = array('id3v2.4');
$tagwriter->overwrite_tags    = true;
$tagwriter->remove_other_tags = true;
$tagwriter->tag_encoding      = 'UTF-8';

$pictureFile = file_get_contents("path/to/image.jpg");

$TagData = array(
    'title' => array('My Title'),
    'artist' => array('My Artist'),
    'album' => array('This Album'),
    'comment' => array('My comment'),
    'year' => array(2018),
    'attached_picture' => array(
        array (
            'data'=> $pictureFile,
            'picturetypeid'=> 3,
            'mime'=> 'image/jpeg',
            'description' => 'My Picture'
        )
    )
);

$tagwriter->tag_data = $TagData;

// write tags
if ($tagwriter->WriteTags()){
    return true;
}else{
    throw new \Exception(implode(' : ', $tagwriter->errors));
}

我不知道我现在使用的共享服务器是否可以做到这一点,但当我使用自己的服务器时,它会很有用。谢谢。什么是
\GetId3\GetId3Core
?你能验证一下,你用的是哪个软件包吗?@Riosant已经很久了,但这是我用的
<?php
    // Initialize getID3 engine
    $getID3 = new getID3;

    // Initialize getID3 tag-writing module
    $tagwriter = new getid3_writetags;
    $tagwriter->filename = 'audiofile.mp3';
    $tagwriter->tagformats = array('id3v2.3');
    $tagwriter->overwrite_tags    = true;
    $tagwriter->remove_other_tags = true;
    $tagwriter->tag_encoding      = $TextEncoding;

    $pictureFile=file_get_contents("image.jpg");

    $TagData = array(
        'title' => 'My Title',
        'artist' => 'My Artist',        
        'attached_picture' => array(   
            array (
                'data'=> $pictureFile,
                'picturetypeid'=> 3,
                'mime'=> 'image/jpeg',
                'description' => 'My Picture'
            )
        )
    );
?>
<?php
    $tag = id3_get_tag( "path/to/example.mp3" );
    print_r($tag);
?>
// Initialize getID3 engine
$getID3 = new getID3;

// Initialize getID3 tag-writing module
$tagwriter = new getid3_writetags;
$tagwriter->filename = 'path/to/file.mp3';
$tagwriter->tagformats = array('id3v2.4');
$tagwriter->overwrite_tags    = true;
$tagwriter->remove_other_tags = true;
$tagwriter->tag_encoding      = 'UTF-8';

$pictureFile = file_get_contents("path/to/image.jpg");

$TagData = array(
    'title' => array('My Title'),
    'artist' => array('My Artist'),
    'album' => array('This Album'),
    'comment' => array('My comment'),
    'year' => array(2018),
    'attached_picture' => array(
        array (
            'data'=> $pictureFile,
            'picturetypeid'=> 3,
            'mime'=> 'image/jpeg',
            'description' => 'My Picture'
        )
    )
);

$tagwriter->tag_data = $TagData;

// write tags
if ($tagwriter->WriteTags()){
    return true;
}else{
    throw new \Exception(implode(' : ', $tagwriter->errors));
}