我使用了getid3_write_lyrics3库。不工作

时间:2017-01-06 12:56:45

标签: php getid3

我使用了getid3_write_lyrics3库。不工作

这是我的代码:

// Enter your filename here 
$filename = 'C:\xampp\htdocs\source2\test.mp3';

//Include getID3() library (can be in a different 
                         directory if full path is specified)
require_once('getid3.php');

// Include desired writer module
require_once('write.lyrics3.php');

//Instantiate desired tag class
$tw = new getid3_write_lyrics3($filename);



// Attempt to write new tag  -- NOTE: all values must be in ISO-8859-1
try 
{
    $tw->title      = 'bhavi';
    $tw->artist     = 'asas';
    $tw->album      = 'A new album';
    $tw->author     = 'bhavi author';
    $tw->comment    = 'bhavika commment';
    $tw->images     = 'C:\xampp\htdocs\source2\image.jpg';

    $tw->synched    = true;
    $tw->lyrics     = "[00:02]Let's talk about time\r\n[00:02]tickin' away 
      every day\r\n[00:05]so wake on up before it's gone away\r\n";

    if(!$tw->write())
    {
        echo "not success";
    }else{
        print 'New tag written<br>';
    }
 }catch (Exception $e) 
 {
   print $e->message;
 }

输出

新标签

但MP#文件显示空白的MP3标签。显示我的下面的截图。

截图:

enter image description here

2 个答案:

答案 0 :(得分:1)

由于OP并没有真正提出问题,并在评论中提到他想用id3添加歌词到mp3,我就回答了。 你不必使用lyrics3,你可以使用普通的id3v2。

我有类似的问题来获取使用getID3包保存的歌词。这是因为文件中的getID3存在语法问题&#34; getID3 / getid3 / write.id3v2.php&#34; 1982年线和2057线。

我只想对@Tom回答发表评论,但我还没有发表评论。所以我使用他的代码:

$filename = 'fullpath/to/your/music.mp3' ;
$sLyrics = "the lyrics go here" ;

$TextEncoding = 'UTF-8';
require_once('./getid3/getid3/getid3.php'); 

$getID3 = new getID3;
$getID3->setOption(array('encoding'=>$TextEncoding));

require_once('./getid3/getid3/write.php');

$tagwriter = new getid3_writetags;
$tagwriter->filename = $filename ;
$tagwriter->tagformats = array('id3v2.3');
$tagwriter->overwrite_tags    = true;  
$tagwriter->remove_other_tags = false; 
$tagwriter->tag_encoding      = $TextEncoding;

$TagData = array(
    'unsychronised_lyric' => array( $sLyrics ),
);
$tagwriter->tag_data = $TagData;

$tagwriter->WriteTags();

关键是改变&#39; unsynchronized_lyrics&#39; to&#39; unsychronised_lyric&#39;他们的拼写错误。 我在JamesHeinrich getId3中为此打开了一个问题,因此如果您将更新包恢复正常,请务必小心,以免您的代码停止编写歌词。

更新---

当我收到一个立即回答时,拼写错误不是来自getID3包,而是直接来自id3 Org,因此它将保持不变。所以使用&#39; unsychronised_lyric&#39;安全。

答案 1 :(得分:0)

是的,我认为这是你正在使用的演示代码。也不适合我,即使运行它会返回true。如果它没有正确地返回错误,那么很难找到它。

使用相同的库,这就完成了工作:

$filename = 'fullpath/to/your/music.mp3' ;
$sLyrics = "the lyrics go here" ;

$TextEncoding = 'UTF-8';
require_once('./getid3/getid3/getid3.php'); 

$getID3 = new getID3;
$getID3->setOption(array('encoding'=>$TextEncoding));

require_once('./getid3/getid3/write.php');

$tagwriter = new getid3_writetags;
$tagwriter->filename = $filename ;
$tagwriter->tagformats = array('id3v2.3');
$tagwriter->overwrite_tags    = true;  
$tagwriter->remove_other_tags = false; 
$tagwriter->tag_encoding      = $TextEncoding;

$TagData = array(
    'unsynchronised_lyrics' => array( $sLyrics ),
);
$tagwriter->tag_data = $TagData;

$tagwriter->WriteTags();