Encoding problems with Perl and iTunes on macOS
Hello everyone,
I am new to the communities, as I rarely have to ask for help. But I have a problem I don't know how to solve with Perl and iTunes on macOS.
My computer have macOS 10.9.5, iTunes 11.4 and Perl 5.16.2, but I had have the same problems with my previous computers.
As a record collector, I manage my collection with a php/mysql app I developed by myself.
When I buy a CD, a vinyl, a tape or files, I usually rip them then add them to iTunes, and add a few other files to the corresponding folders in the iTunes folder structure : a log file (with the information of the CD rip by XLD, or the lineage of the tape or vinyl rip, or where I bought the files), a md5 file, and for the downloaded mp3s, an jpg file of the cover.
My php/mysql app have informations about the existence of these files, so I am able to know if there is something missing for a record or another, like the cover, the kind of encoding of the file, etc.
To make the connection between the files in the iTunes folders and my app, I have a perl script that run every night, and that check the new files I added, so it is able to complete my list automatically. Everything works quite fine except that... I have problems with the different encodings used by macOS and iTunes, when there are accented characters.
An example should help to understand
I have a record by a band called "A Hawk And A Hacksaw" : "A Hawk And A Hacksaw And The Hun Hangár Ensemble". Tracks titles contain a few different accented characters.
As I read on internet, macOS seems to utf8 encoded, so in my perl script, I have these both instructions :
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");
It gives me with one the track of this album the above informations.
From macOS :
filename = ~/Music/iTunes/Music/A Hawk And A Hacksaw And The Hun Hangár Ensemble Test/A Hawk And A Hacksaw And The Hun Hangár Ensemble Test/01 Kiraly Siratás.m4a
From iTunes files, using MP4::Infos :
band = A Hawk And A Hacksaw
album = A Hawk And A Hacksaw And The Hun Hang?r Ensemble
track title = Kiraly Sirat?s
cover = NO COVER
encoding = alac
Which is incorrect.
If I only keep the first line :
binmode(STDIN, ":utf8");
I still have the same problem.
But if I only keep the second line :
binmode(STDOUT, ":utf8");
It gives me the above informations for the same track :
From macOS :
filename = ~/Music/iTunes/Music/A Hawk And A Hacksaw And The Hun HangaÌr Ensemble Test/A Hawk And A Hacksaw And The Hun HangaÌr Ensemble Test/01 Kiraly SirataÌs.m4a
From iTunes file with MP4::Infos :
band = A Hawk And A Hacksaw
album = A Hawk And A Hacksaw And The Hun Hangár Ensemble
track title = Kiraly Siratás
cover = NO COVER
encoding =alac
Which is not better but this time the filename is incorrect, and the infos are correct.
When I deactivate both binmode lines, the problem remains the same as the second example.
I tried a lot of things, with different Perl modules, different methods, but I am still unable to have things correct.
Is there anyone around here that could know what to do to have both the macOS and iTunes infos correct ?
Maybe I am doing the things wrong, but I don't how to do it right.
Thanks for your help.
Pascal