Export M3U script to ignore sub folders

I have 500 folders i need to batch create M3U file for each folder (album), currently i use export script that looks like this

$filename(m3u,ansi)#EXTM3U
$loop(%_filename_ext%)#EXTINF:%_length_seconds%,%artist% - %title%
%_path%
$loopend()

It works great, however if folder (Album) has sub folders CD1, CD2, CD3 it creates three M3U files for each sub folder

MyMusic\Album\CD1 
MyMusic\Album\CD2 
MyMusic\Album\CD3

Need to modify export script to create single M3U file for whole Album that will point to mp3 files inside sub folders (CD1, CD2, CD3) and NOT 3 separate M3U files for each folder.

The easiest way would be to use the function File>Create Playlist (for selected files).
This will save the playlist in the current working directory.
Or see e.g. here:

This does not solve my main problem, it still creates separate playlists for each individual sub folder within album.

I just loaded the folder "Music" with several subfolders "Album1", "Album2" etc.
Now "Music" is the working folder.
I selected files from 2 subfolders and called the function File>Playlist (for selected files).
The resulting, single playlist looks like this:
#EXTM3U
#EXTINF:552,Babel - Jerry Sprunger - Lemi Vice & Action Jackson Remix (Dirty)
Ambient Diary.One - 1997\ambient Diary.One _ 001 _ Babel _ The Return - of Babel''.mp3
...
#EXTINF:309,Index ID - Federflug
Ambient Diary.Three - 2000\Ambient Diary.Three _ 105 _ Index ID _ Federflug.mp3
...

Here is the result of Ctrl + Shft + P that as description say Playlist (all files) with one playlist for each subfolder

Here is example of Album that has sub folders (total 500 loaded in Mp3Tag)
1

It creates playlist for each sub folder of album.
2

I need one M3U file for each sub folder of Album.

see File>Options>Playlist and find out if "Create playlist relative to workdir" helps

Don't have this option, unless you mean Entries relative from work directory - Enable this option, if you don't want full file paths in your playlist, it made no difference checked or unchecked.

I tried your script and the result is just one file (i have not ticked the option "One file per folder").
So what is different?

There is no way to handle how Mp3Tag creating M3U files within export script other than specify file name and encoding.

Still weather to create one file or file for each sub folder is determined by Mp3Tag option "One file per directory" if checked it creates M3U file for each sub folder, if unchecked creates one M3U file with MP3 files from all directories, no other option.

This is limiting factor to doing what i intended.

I think only solution to my original question is workaround - create single M3U file trough export script then break it up using 3rd party program, any idea how to do it?

See $put() and $get() to handle user-defined variables.
Exporting Tag and File Information – Mp3tag Documentation

Also, you can define a playlist name with string constants and viariable parts where the variable part could be %album% so that you get all the files from one album into one file.

1 Like

This variable cannot be used within nested loop, following does not work.

$filename(m3u,ansi)
$loop(%_folderpath%,1)

	$puts(grant_parent_folder_name,%_parent_directory%)
	$puts(parent_folder_name,%_directory%)

	$get(grant_parent_folder_name)
	$get(parent_folder_name)
	%_path%

	$loop(%_filename_ext%)

		getting $get(grant_parent_folder_name) 
		$get(parent_folder_name) 
		%_path%

	$loopend()

$loopend()

I'll try this however only works when you have ID3 tag set for mp3 files.

Use the Export function.
Create two configurations:

Playlist Discs A Header.mte:
$filename($regexp(%_folderpath%,'\\(CD|Disc)\s*\d+\\$','\')---$regexp($regexp(%_folderpath%,'\\(CD|Disc)\s*\d+\\$','\'),'^.+\\([^\\]+)\\',$1).m3u,ansi)#EXTM3U$char(13)$char(10)

Playlist Discs B Body.mte:
$filename($regexp(%_folderpath%,'\\(CD|Disc)\s*\d+\\$','\')---$regexp($regexp(%_folderpath%,'\\(CD|Disc)\s*\d+\\$','\'),'^.+\\([^\\]+)\\',$1).m3u,ansi)$loop(%_filename_ext%)#EXTINF:%_length_seconds%,%artist% - %title%
%_filename_rel%
$loopend()

Select all files and run the first config with the option
[X] One file per directory

Then run the second config with the options
[X] Append data
[X] One file per directory

You can also save this as action group.

2 Likes

That worked, with one minor bug, sometimes sub folders within album folder have different name from CD and Disk (or have greater depth than one sub folder) in this case your script still creates M3U within albums sub-folder.

Edit: Here is my regex-less tweak to fix folder issues.

Export Script 1.mte:
$filename($left(%_folderpath%,$add($len(%_workingpath%),$strchr($right(%_folderpath%,$distance(%_folderpath%,%_workingpath%)),\)))$left($right(%_folderpath%,$distance(%_folderpath%,%_workingpath%)),$sub($strchr($right(%_folderpath%,$distance(%_folderpath%,%_workingpath%)),\),1)).m3u,ansi)#EXTM3U

Export Script 2.mte:
$filename($left(%_folderpath%,$add($len(%_workingpath%),$strchr($right(%_folderpath%,$distance(%_folderpath%,%_workingpath%)),\)))$left($right(%_folderpath%,$distance(%_folderpath%,%_workingpath%)),$sub($strchr($right(%_folderpath%,$distance(%_folderpath%,%_workingpath%)),\),1)).m3u,ansi)$loop(%_filename_ext%)#EXTINF:%_length_seconds%,%artist% - %title%
%_path%
$loopend()
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.