Jared Smith Jared Smith - 1 year ago 70
Javascript Question

Having trouble converting itunes XML playlist in node.js

Some time ago I wrote a quick little node command-line utility to convert itunes playlists in XML format to m3u, xspf, etc. so I could use them on my linux box at work, android phone*, etc.

* I have a 25+ gigabyte music collection, doubletwist et al just keel over and die trying to sync with my mac

At first this was fine, but as my music collection has grown I've hit a snag: no media player can seem to find any files with non-English unicode characters such as ñ, í, and pretty much any Japanese kanji. Its not every single character that causes this problem, but for the most part its a thing.

Since the itunes file paths are partially url-encoded (and need to not be to match the constraints of the target formats), and need to be partially replaced to the correct path on the target machine, I have the following code to deal with the file paths (stripped of irrelevant stuff):

let location;

// need try/catch because some track names contain unescaped '%' that
// cause the decode function to throw.
try {
location = decodeURIComponent(x.location.slice(7));
} catch (e) {

// function references a hash of about 200 url encodings and
// replaces occurences of them in the path, poor man's (slow)
// replacement for the built-in
location = replaceURLEscapes(x.location.slice(7));

I've tried
decodeURIComponent, decodeURI
, and my own custom function referenced above. Here is an example from the XML file:


Which is converted to:

/home/username/Music/Compilations/Chronicles of Time/3-05 Melodía de la montaña (feat. Doug Perry & Matheus S. Garcia Souza).m4a

Which seems fine, but VLC, clementine, etc. can't find. Here's the file name straight from Nautilus:

3-05 Melodía de la montaña (feat. Doug Perry & Matheus S. Garcia Souza).m4a

Which is in the directory referenced in the path. Note that the inflection as interpreted by
is on the 'a' rather than the 'n' (my function doesn't make that error, so that's not the problem per se).
How can I modify this such that media players can find the tracks?

Answer Source

So the problem ended up being the combining characters. Decoding, normalizing, and re-encoding fixes it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download