JamesHeinrich / getID3

http://www.getid3.org/
Other
1.15k stars 245 forks source link

$tagwriter->WriteTags() not working for temporary file? #307

Closed q2apro closed 3 years ago

q2apro commented 3 years ago

I have an issue with webm/ogg audio recordings in the browser that get saved without metadata. See details at https://stackoverflow.com/q/67041475/1066234

I would like to use getID3 to store the metadata with the ogg-file. I tried the the following:

$file_locationtmp = $_FILES['recfile']['tmp_name'];

// get metdata from filecontent
require_once '../getid3/getid3.php';
$getID3 = new getID3;
$TextEncoding = 'UTF-8';
$getID3->setOption(array('encoding'=>$TextEncoding));

$fileinfo = $getID3->analyze($file_locationtmp);

require_once('../getid3/write.php');
$tagwriter = new getid3_writetags;
$tagwriter->filename = $file_locationtmp;

$tagwriter->tagformats = array('vorbiscomment'); // 'id3v1', 'id3v2.2', 'id2v2.3', 'id3v2.4', 'ape', 'vorbiscomment', 'metaflac', 'real'

// set various options
$tagwriter->overwrite_tags    = true;  // if true will erase existing tag data and write only passed data; if false will merge passed data with existing tag data (experimental)
$tagwriter->remove_other_tags = false; // if true removes other tag formats (e.g. ID3v1, ID3v2, APE, Lyrics3, etc) that may be present in the file and only write the specified tag format(s). If false leaves any unspecified tag formats as-is.
$tagwriter->tag_encoding      = $TextEncoding;

// populate data array
$tagdata = array(
    'title'                  => array('My Song'),
    'artist'                 => array('The Artist'),
    // 'album'                  => array('Greatest Hits'),
    'year'                   => array('2004'),
    // 'genre'                  => array('Rock'),
    // 'comment'                => array('excellent!'),
    // 'track_number'           => array('04/16'),
    // 'popularimeter'          => array('email'=>'user@example.net', 'rating'=>128, 'data'=>0),
    'unique_file_identifier' => array('ownerid'=> $userid.'@edumaps.de', 'data'=>md5(time())),
);
$tagwriter->tag_data = $tagdata;

// write tags
if($tagwriter->WriteTags()) 
{
    error_log('Successfully wrote tags');
    if(!empty($tagwriter->warnings)) 
    {
        error_log('There were some warnings:');
        error_log(printr($tagwriter->warnings, true));
    }
}
else 
{
    error_log('Failed to write tags!');
    error_log($tagwriter->errors);
}

However, I always get "Failed to write tags!".

How can I solve the problem?

JamesHeinrich commented 3 years ago

Check both $tagwriter->errors and $tagwriter->warnings for useful pointers, if any.

VorbisComment writing is dependent on vorbiscomment being available to the system: https://github.com/JamesHeinrich/getID3/blob/master/getid3/write.vorbiscomment.php#L105

q2apro commented 3 years ago

$tagwriter->errors and $tagwriter->warnings are both empty.

I assume vorbiscomment is the one used for webm/audio and ogg/audio? Thanks.

And yes, this might be the problem. I still need to install the package (apt-get install -y vorbis-tools).

JamesHeinrich commented 3 years ago

That is the problem then, Vorbis Tools needs to be available to the system for writing vorbiscomment tags. However getID3 should have given you a better warning that that.

q2apro commented 3 years ago

I have installed "vorbis-tools" on my server. Trying the getID3 script again, I still only get:

[14-Apr-2021 04:12:27 UTC] Failed to write tags!

in the logs.

What can I do to find the problem?

q2apro commented 3 years ago

If I output the $tagwriter object after init I get:

[14-Apr-2021 04:19:22 UTC] getid3_writetags Object
(
    [filename] => /srv/phpIkYGQW
    [tagformats] => Array
        (
            [0] => vorbiscomment
        )

    [tag_data] => Array
        (
            [year] => Array
                (
                    [0] => 2021
                )

            [unique_file_identifier] => Array
                (
                    [ownerid] => user34946@test.de
                    [data] => e28ea7d088aeff93bb8xxxsdfsfsdfsdxx
                )

        )

    [tag_encoding] => UTF-8
    [overwrite_tags] => 1
    [remove_other_tags] => 
    [id3v2_tag_language] => eng
    [id3v2_paddedlength] => 4096
    [warnings] => Array
        (
        )

    [errors] => Array
        (
        )

    [ThisFileInfo:getid3_writetags:private] => 
)

Note: As I wrote in the very beginning, the file is posted and thus a temporary file on the filesystem. Might this be related to the issue?


Update:

I did a complete log and can see the error message now!

⚠️ Tag format "vorbiscomment" is not allowed on "webm.A_OPUS" files

I have tried $tagwriter->tagformats = array('id3v2.4'); instead of vorbiscomment. Then I get:

[error] => Array
    (
        [0] => EBML parser: ran out of file at offset 15173
    )

[warning] => Array
    (
        [0] => Unhandled audio type "A_OPUS"
    )
JamesHeinrich commented 3 years ago

If it's in a WebM (subset of Matroska) container then I don't think vorbiscomment is appropriate (that is for ogg container). getID3 doesn't support writing to Matroska files. Offhand I'm not sure if there's a standalone commandline tool to write comments to WebM/MKV, but I haven't really looked.