Strip out part of album title to create a playlist file


#1

Hi, I have several album titles that could have a (CD1), (CD2) or even (CD1 - Bonus) at the end of them, whenever they consist of more than 1 CD. For example:

The Best Rock Album In The World (CD1)
The Best Rock Album In The World (CD2)
Deep Purple - Made In Japan (25th Anniversary Edition) (CD1 - Remastered)
Deep Purple - Made In Japan (25th Anniversary Edition) (CD2 - The Encores)
Most album titles of course don't have that at the end of them as they are single albums

I am trying to write a playlist export function for these and I want to strip off the part at the end

When I have the following syntax I successfully create the m3u8 file with #EXTM3U as the first line

$filename(M:\Playlists\%album%.m3u8,utf-8)#EXTM3U

A second script then successfully creates the rest of the playlist

$filename(M:\Playlists\%album%.m3u8,utf-8)$loop(%counter%)#EXTINF:%_length_seconds%,%artist% - %title%
%_path%
$loopend()

But when I try to strip out the (CD1) etc using the following I get the output file correctly named but its blank

$filename(M:\Playlists\$regexp(%album%,'^(.+?)\s\(CD.*',$1).m3u8,utf-8)#EXTM3U
$filename(M:\Playlists\%album%,'^(.+?)\s(CD.*',$1).m3u8,utf-)$loop(%counter%)#EXTINF:%_length_seconds%,%artist% - %title%
%_path%
$loopend()

The regex appears to be stripping out the part at the end of the album title but for some reason I get no data in the file. Any ideas
Thanks


#2

I think that should be
$regexp(%album%,'^(.+?)\s\(CD.*',$1).m3u8
and then I do not know why you repeat the $filename() statement. One should be enough.


#3

Ah typo in my original post. Sorry. I have the following but I get a blank file (but with the correct file name)

$filename(M:\Artist Playlists\$regexp(%album%,'^(.+?)\s\(CD.*',$1).m3u8,utf-8)#EXTM3U
$loop(%counter%)#EXTINF:%_length_seconds%,%artist% - %title%
%_path%
$loopend()

#4

I think that the counting variable is called %_counter%.
I am not sure that this is valid: $loop(%_counter%) as it either would count to infinite or not at all as %_counter% gets initialized inside the $loop()
If you want to use the sequence of the files in MP3tag's file list, use $loop(A).


#5

$loop(%_counter%) is a valid statement. It has a different value for each of the files, effectively creating one entry per file while keeping the order of the files in the file list.


#6

Interesting. I have been running this action successfully for over 5 years and had mispelt %_counter% as %counter%. But it worked! So I figured that maybe I could just use $loop() but the action then fails. So I am a bit confused as to why the following has worked as part of creating the playlist.

$loop(%counter%)#EXTINF:%_length_seconds%,%artist% - %title%
%_path%
$loopend()

G


#7

It worked because Mp3tag sorted on a non-existent field. I'm using a stable sort algorithm, i.e., the original order is preserved in case there is no difference in the comparison. It's the same as using

However, all of this is a side-effect of Mp3tag's implementation. Using $loop(%_counter%) is defined behavior here.


#8

OK that makes sense thanks. Have now updated the action to correct this.

My next challenge whilst I was updating these actions was whether I could get the 2 actions merged into 1

Currently I have 2 actions:

Action1 (One file per directory)
$filename(M:\Playlists\$regexp(%album%,'^(.+?)\s\.CD.*',$1).m3u8,utf-8)#EXTM3U

Action2 (Append and one file per directory)

$filename(M:\Playlists\$regexp(%album%,'^(.+?)\s\.CD.*',$1).m3u8,utf-8)$loop(%_counter%)#EXTINF:%_length_seconds%,%artist% - %title%
%_path%
$loopend()

The above works
But if I merge them into 1 action (1 file per directory) as follows it does not!

$filename(M:\Playlists\$regexp(%album%,'^(.+?)\s\.CD.*',$1).m3u8,utf-8)#EXTM3U
$loop(%_counter%)#EXTINF:%_length_seconds%,%artist% - %title%
%_path%
$loopend()

Am I stuck with 2 actions on this or can they be merged?
Thanks
G


#10

It looks good to me. Can you describe what doesn't work with your merged action?


#11

Just found cause of error but not sure why it is doing it, The code I had in the combined action was not quite the same as what I have pasted here

$filename(M:\Playlists\$regexp(%album%,'^(.+?)\s\(CD.*',$1).m3u8,utf-8)#EXTM3U
$loop(%_counter%)#EXTINF:%_length_seconds%,%artist% - %title%
%_path%
$loopend()

In the $regexp, instead of the dot before CD I had previously used ( in order to trap the opening bracket as in (CD1) after the blank space. but if I do that I get no output file at all. If I change it to a . it works. It seems to be getting confused with the extra opening bracket but I had escaped it so don't really understand why that did not work.


#12

Good catch. This is a bug in the filename parser which I'll fix to the next release.


#13

I've fixed the issue at parsing the filename with Mp3tag v2.91a. Thanks again for pointing!


#14

Hi. Thanks for the information
Currently I have 2 actions as per below and this is working in creating multiple playlists for different artists in a single playlists folder

Action 1 (1 file per directory)

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

Action 2 (1 file by directory and Append Data)

$filename(\\NAS\Music\Artist Playlists\$if($or($eql(%albumartist%,Various Artists),$eql(%album artist%,Various Artists)),$regexp($cutleft(%album%,6),'^(.+?)\s.CD\d.*',$1),$if($or($eql(%_parent_directory%,1Pop),$eql(%_parent_directory%,Music)),Miscellaneous Artists,$regexp(%_folderpath%,'^\\\\.+?\\.+?\\.+?\\(.+?)\\.*',$1))) - Rated Tracks.m3u8,utf-8)
$loop(%_path%)#EXTINF:%_length_seconds%,%artist% - %title%
$replace(%_path%,'\\NAS\Music\MP3\','M:\MP3\')
$loopend()

However if I merge them into a single action (with 1 file per directory and append data) as per below

$filename(\\NAS\Music\Artist Playlists\$if($or($eql(%albumartist%,Various Artists),$eql(%album artist%,Various Artists)),$regexp($cutleft(%album%,6),'^(.+?)\s.CD\d.*',$1),$if($or($eql(%_parent_directory%,1Pop),$eql(%_parent_directory%,Music)),Miscellaneous Artists,$regexp(%_folderpath%,'^\\\\.+?\\.+?\\.+?\\(.+?)\\.*',$1))) - Rated Tracks.m3u8,utf-8)#EXTM3U
$loop(%_path%)#EXTINF:%_length_seconds%,%artist% - %title%
$replace(%_path%,'\\NAS\Music\MP3\','M:\MP3\')
$loopend()

I am getting additional #EXTM3U at each path/folder change of the original files throughout the playlist file. Using the 2 actions above I correctly only get this row appearing on the first line of the playlist.
Is there any way to get this working with a single action or am I stuck with using 2 actions?
Example output below:

#EXTM3U
#EXTINF:226,Dire Straits - Lady Writer
M:\MP3\Dire Straits\1979 - Communiqué\05 - Lady Writer.mp3
#EXTINF:277,Dire Straits - Angel Of Mercy
M:\MP3\Dire Straits\1979 - Communiqué\06 - Angel Of Mercy.mp3
#EXTM3U
#EXTINF:313,Dire Straits - Expresso Love
M:\MP3\Dire Straits\1980 - Making Movies\04 - Expresso Love.mp3
#EXTINF:207,Dire Straits - Solid Rock
M:\MP3\Dire Straits\1980 - Making Movies\06 - Solid Rock.mp3

Thanks
G


#15

The problem relies in having the M3U playlist header #EXTM3U in the configuration and appending data. Each time you perform the export, it would evaluate the complete export configuration and also write the #EXTM3U part.

If you really want to have a playlist that you append new entries to, a combination of both exports is not possible. Except if you would make the playlist a simple list of filenames, without any #EXTM3U and #EXTINF— most players also support those.