WriteMetaFLAC failed on utf8 filenames

The place for "I can't figure out how to..." questions.
Post Reply
harrynak
User
Posts: 3
Joined: Thu Sep 14, 2017 9:16 am
Are you a spambot?: no

WriteMetaFLAC failed on utf8 filenames

Post by harrynak » Thu Sep 14, 2017 9:36 am

Hi,

I'm using getID3 for years without issues on my mp3 collection. Now i'm starting to use it on flac files also and maybe i've found a bug.
When i try to write tags to a file with special characters in it the writing failes.

I always troubleshoot with the demo files so i can find my own errors but this time it also doesn't work with the demo.write file.

This is the error:
WriteMetaFLAC() failed with message(s):
System call to metaflac failed with this message returned:
/var/www/html/getID3-1.9.14/demos/101 - Django Reinhardt - Ma Rgulire.flac: ERROR: reading metadata, status = "FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE"
The FLAC file could not be opened. Most likely the file does not exist
or is not readable.

The real filename is: 101 - Django Reinhardt - Ma Réguliére.flac
As you can see in the errors the 2 'é' chars are missing that's why it cannot find the file.

Gr,
Harry

James Heinrich
getID3() v1 developer
Posts: 1476
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: WriteMetaFLAC failed on utf8 filenames

Post by James Heinrich » Thu Sep 14, 2017 1:39 pm

It looks like the filename is not being passed correctly to metaflac.
Can you please trace through write.metaflac.php and see if you can find where the filename is being mangled? I believe you're running under *nix (ie not-Windows), so you're probably looking at the command line on line 84.

harrynak
User
Posts: 3
Joined: Thu Sep 14, 2017 9:16 am
Are you a spambot?: no

Re: WriteMetaFLAC failed on utf8 filenames

Post by harrynak » Thu Sep 14, 2017 3:46 pm

Yep, running under linux.

I changed it to this:
// It's simpler on *nix
echo $tempcommentsfilename . " HIERO<br>";
echo $this->filename . "<br>";
exit;
$commandline = 'metaflac --no-utf8-convert --remove-all-tags --import-tags-from='.escapeshellarg($tempcommentsfilename).' '.escapeshellarg($this->filename).' 2>&1';
$metaflacError = `$commandline`;

Output is:
starting to write tag(s)
/tmp/getID3P6j380 HIERO
/var/www/html/movie/getID3-1.9.14/demos/101 - Django Reinhardt - Ma Réguliére.flac

I'm not sure if this is what you ment? but the filename still seems ok....

Gr,
Harry

James Heinrich
getID3() v1 developer
Posts: 1476
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: WriteMetaFLAC failed on utf8 filenames

Post by James Heinrich » Thu Sep 14, 2017 7:27 pm

That's the right section of code.
If you check what $commandline has been set to you may find that while $this->filename is correct, it ends up in the command line incorrectly due to escapeshellarg. I see this as the top comment on the PHP documentation page for escapeshellarg:
When escapeshellarg() was stripping my non-ASCII characters from a UTF-8 string, adding the following fixed the problem:

Code: Select all

setlocale(LC_CTYPE, "en_US.UTF-8");
Can you try adding that line somewhere (just before the $commandline= line is fine for testing) and see if that fixes your problem?

harrynak
User
Posts: 3
Joined: Thu Sep 14, 2017 9:16 am
Are you a spambot?: no

Re: WriteMetaFLAC failed on utf8 filenames

Post by harrynak » Fri Sep 15, 2017 11:32 am

Thank you James, it was exactly like that, commandline not ok, this array ok.
I added the setlocale line and now it works fine.

Gr,
Harry

James Heinrich
getID3() v1 developer
Posts: 1476
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: WriteMetaFLAC failed on utf8 filenames

Post by James Heinrich » Fri Sep 15, 2017 1:52 pm

I have added the line of code to getid3.php but left it commented out for now:
https://github.com/JamesHeinrich/getID3 ... 816d1d9e27
I have not heard anyone else report this problem yet, and I don't want to risk breaking working installations by pushing this change on everyone.

Thanks for the bug report and your testing.

Post Reply