i used getid3_write_lyrics3 library. not working

549 views Asked by At

I used getid3_write_lyrics3 library. not working

This my code:

// 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;
 }

OUTPUT

New tag written

but MP# file show blank MP3 Tags. show my below screenshot.

Screenshot:

enter image description here

2

There are 2 answers

2
KeitelDOG On

Since the OP hasn't really ask for a question, and mention in a comment that he wanted to add lyrics to mp3 with id3, then I'm answering. You don't have to use lyrics3, you can just use normal id3v2.

I had similar problem to get the lyrics saved with getID3 package. It is because of a grammar issue in getID3 in file "getID3/getid3/write.id3v2.php" Line 1982 and Line 2057.

I would simply comment in of @Tom answer, but I can't comment yet. So I'm using his codes:

$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();

The key is to change 'unsynchronised_lyrics' to 'unsychronised_lyric' with their misspelling error. I opened an issue for this in JamesHeinrich getId3, so be careful when you update the package if they change it back to normal in the future so that your codes don't stop writing the lyrics.

UPDATE ---

As I received an immediate answer, the typo error was not from getID3 package, but from id3 Org directly, so it will stay as is. So use 'unsychronised_lyric' safely.

0
Tom On

Yeah, i think that's the demo code you're using. Didn't work for me either, even though running it would return true. It's hard to bug hunt if it doesn't return errors right.

Using the same library, this did the job:

$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();