1

I have .m3u files generated in Linux which can't be read by Windows programs due to different way to treat special characters in paths.

For example, how can I convert this Linux path:

Music/Timo%20Rautiainen%20&%20Trio%20Niskalaukaus/07%20H%C3%A4mmennys%20ja%20viha.mp3

into this path readable in Windows:

Music/Timo Rautiainen & Trio Niskalaukaus/07 Hämmennys ja viha.mp3

in a text file?

It would be easy if I could just replace all instances of %20 with spaces, but as you can see above there are special characters (äöñ etc.) in the paths and filenames which need to be converted, also. These are too varied to be done with regex, and I don't even have a list of all special characters in use in my files.

edit: as mentioned in comments, the above is a result of URL/URI encoding, rather than reasons I postulated.

Easy fix was to use an online URL encoder/decoder, which fixed the paths very quickly. This is the URL decoder I used. Accepted answer below with a native Linux Python method.

1 Answers1

3

If you don't like Perl, use Python! ;-] Seriously, this or an equivalent Perl one-liner is the easiest way, if you can't use a different application to generate M3U lists.

from sys import stdin
from urllib.parse import unquote

print(*map(unquote, stdin), sep='', end='')

Run with:

python3 [script file] < [quoted m3u file] > [unquoted m3u8 file]

Note that the .m3u8 extension gives the reading application a hint, that the file is UTF-8 encoded. On Linux that may not matter, because most of the time it's the default encoding anyway, but many Windows applications might assume windows-1250 encoding or whatever your locale is.

David Foerster
  • 36,890
  • 56
  • 97
  • 151