Generating export for M3U8 Playlists - UTF-8 issue

Hi, I have the following 2 export actions that run one after another to create a seperate playlist for each artist based on a set of rated tracks loaded into MP3Tag (from a single playlist)

$filename(\NAS\Music\Artist Playlists$if($eql(%albumartist%,Various Artists),$regexp($cutleft(%album%,6),'^(.+?)\s.CD\d.',$1),$regexp(%_folderpath%,'^\\.+?\.+?\.+?\(.+?)\.',$1)) - Rated Tracks.m3u8)#EXTM3U

$filename(\NAS\Music\Artist Playlists$if($eql(%albumartist%,Various Artists),$regexp($cutleft(%album%,6),'^(.+?)\s.CD\d.',$1),$regexp(%_folderpath%,'^\\.+?\.+?\.+?\(.+?)\.',$1)) - Rated Tracks.m3u8)$loop(%_path%)#EXTINF:%_length_seconds%,%artist% - %title%

I am creating .m3u8 playlists as I have a number of artists that have special characters in them e.g. Blue Ă–yster Cult, QueensrĂżche.

When I look at each playlist in Notepad or Notepad++ I see that those without any special characters in them (in artist name, album title or track title) show UTF-8 as the format. However those with special characters (eg the Blue Ă–yster Cult playlist) show ANSI, but the special characters are shown correctly.
When I then try to import these into iTunes the ANSI ones fail with no tracks loaded - I have to manually convert each one to UTF-8 in Notepad++ before they will import. Those in UTF-8 format (with no special characters) load fine

I have tried this with BOM turned on and turned off (in Options). Same result

Why do some playlists get formatted as UTF8 and others as ANSI, particularly as its not the way round that I would expect. If anything, I would expect those with special characters to be formatted as UTF-8 and those without any special characters to be formatted as ANSI.
However given that the action is generating all the playlists as *.m3u8, I am expecting them all to be assigned the UTF-8 format


AFAIK the m3u8 extension is the indicator for MP3tag to generate a UTF-8 encoded file if you generate a playlist with one of the File>Playlist functions.

If you have an export script, you need to add that switch as part of the $filename() statement, see the help:

The optional second parameter sets the encoding of the export file. Possible values are ansi, utf-8 and utf-16.

$filename(test.txt) $filename(test.txt,ansi) $filename(test.txt,utf-8) $filename(test.txt,utf-16)

So I think it should read
Rated Tracks.m3u8,UTF-8)$loop ....

Thanks, that has worked now
Another minor but irritating issue is the fact that I always get a blank/empty row at the end of the playlist, which appears to be because the final $loopend() is on a new row. If I move that statement up to the row above the playlist i.e.


the last blank row disappears BUT the output playlist is not formatted correctly with the next #EXTINF row being appended to the previous row with the filename. Is there a way I can prevent the final empty row being generated when it reaches the end of the $loop(%_path%) loop? without impacting the format of the output for the rows above it


MP3tag takes the text in the script literally in respect to output lines.
It could also be that you have an extra line following the $loopend() ...

There is no extra line following loopend().
Have tried adding $char(08) after the loopend() to see whether it would generate a backspace to get rid of the extra line but all it does is generate character which I guess means backspace. :frowning:

An extra line is encoded by 2 characters: Char(13) and Char(10)

I don't want to generate another line I want to remove the one that has already been generated at the end of the playlist.

I know.
But if a new line consists of 2 characters and you use only 1 backspace character, then you delete only half of what is needed.
Yet, I don't know if this works at all.
It is still much easier to modify the export script.

Ah yes - sorry I misunderstood. My method still does not work though with 2 $char(08)'s. Somehow I need to check whether the track is the last one in the loop and if so jump straight out of the script, but I'm not sure how to do this. I'll have another go tomorrow I think

this thread features an export script that deletes a trailing comma.
So perhaps a double somersault where you first insert a unique character after each track, then remove the trailing one and finally replace the unique characters with carriage return and line feed characters.

Hi thanks for the suggestion. I have managed to get this to work with the code below.

$filename(%_folderpath%$trimright($replace($if($or($eql(%albumartist%,Various Artists),$eql(%album artist%,Various Artists)),$cutleft(%album%,6),%albumartist% - $cutleft(%album%,6)),/,-,:, -,",''),.).xxx,utf-8)#EXTM3U
$loop(%track%)$puts(totaltracks,%_counter%)$loopend()$loop(%track%)$loop(%_filename_ext%)#EXTINF:%_length_seconds%,%artist% - %title%

I loop round the tracks twice. First time allows me to set the totaltracks. Then I compare that number with the counter in the second loop. If they are equal I don't do anything if they are not I put in the CRLF


1 Like