# Strip out part of album title to create a playlist file

**URL:** https://community.mp3tag.de/t/strip-out-part-of-album-title-to-create-a-playlist-file/43826
**Category:** Support
**Created:** [December 9, 2018, 6:55pm UTC](https://community.mp3tag.de/t/strip-out-part-of-album-title-to-create-a-playlist-file/43826 "2018-12-09T18:55:37Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![gsa999](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/c6cbf5/32.png) [@gsa999](https://community.mp3tag.de/u/gsa999)
#### Post date: [December 9, 2018, 6:55pm UTC](https://community.mp3tag.de/t/strip-out-part-of-album-title-to-create-a-playlist-file/43826/1 "2018-12-09T18:55:37Z")

</div>

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

```auto
$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

```auto
$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

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [December 9, 2018, 7:01pm UTC](https://community.mp3tag.de/t/strip-out-part-of-album-title-to-create-a-playlist-file/43826/2 "2018-12-09T19:01:35Z")

</div>

> [@gsa999](#):
>
> $regexp(%album%,'^(.+?)\s(CD. _',$1).m3u8_

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.

---

<div class="post-metadata">

### Author: ![gsa999](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/c6cbf5/32.png) [@gsa999](https://community.mp3tag.de/u/gsa999)
#### Post date: [December 9, 2018, 7:49pm UTC](https://community.mp3tag.de/t/strip-out-part-of-album-title-to-create-a-playlist-file/43826/3 "2018-12-09T19:49:29Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![ohrenkino](https://community.mp3tag.de/user_avatar/community.mp3tag.de/ohrenkino/32/4843_2.png) [@ohrenkino](https://community.mp3tag.de/u/ohrenkino)
#### Post date: [December 9, 2018, 8:01pm UTC](https://community.mp3tag.de/t/strip-out-part-of-album-title-to-create-a-playlist-file/43826/4 "2018-12-09T20:01:27Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [December 9, 2018, 8:48pm UTC](https://community.mp3tag.de/t/strip-out-part-of-album-title-to-create-a-playlist-file/43826/5 "2018-12-09T20:48:35Z")

</div>

> [@ohrenkino](#):
>
> I am not sure that this is valid: $loop(%\_counter%) as it either would count to infinite or not at all as

`$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.

---

<div class="post-metadata">

### Author: ![gsa999](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/c6cbf5/32.png) [@gsa999](https://community.mp3tag.de/u/gsa999)
#### Post date: [December 10, 2018, 10:51am UTC](https://community.mp3tag.de/t/strip-out-part-of-album-title-to-create-a-playlist-file/43826/6 "2018-12-10T10:51:36Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [December 10, 2018, 12:17pm UTC](https://community.mp3tag.de/t/strip-out-part-of-album-title-to-create-a-playlist-file/43826/7 "2018-12-10T12:17:55Z")

</div>

> [@gsa999](#):
>
> So I am a bit confused as to why the following has worked as part of creating the playlist.

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

> [@ohrenkino](#):
>
> $loop(A)

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

---

<div class="post-metadata">

### Author: ![gsa999](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/c6cbf5/32.png) [@gsa999](https://community.mp3tag.de/u/gsa999)
#### Post date: [December 10, 2018, 1:12pm UTC](https://community.mp3tag.de/t/strip-out-part-of-album-title-to-create-a-playlist-file/43826/8 "2018-12-10T13:12:56Z")

</div>

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)

```auto
$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!

```auto
$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

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [December 10, 2018, 2:51pm UTC](https://community.mp3tag.de/t/strip-out-part-of-album-title-to-create-a-playlist-file/43826/10 "2018-12-10T14:51:21Z")

</div>

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

---

<div class="post-metadata">

### Author: ![gsa999](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/c6cbf5/32.png) [@gsa999](https://community.mp3tag.de/u/gsa999)
#### Post date: [December 10, 2018, 7:18pm UTC](https://community.mp3tag.de/t/strip-out-part-of-album-title-to-create-a-playlist-file/43826/11 "2018-12-10T19:18:38Z")

</div>

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

```auto
$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.

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [December 10, 2018, 8:19pm UTC](https://community.mp3tag.de/t/strip-out-part-of-album-title-to-create-a-playlist-file/43826/12 "2018-12-10T20:19:01Z")

</div>

> [@gsa999](#):
>
> 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.

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

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [December 16, 2018, 12:45pm UTC](https://community.mp3tag.de/t/strip-out-part-of-album-title-to-create-a-playlist-file/43826/13 "2018-12-16T12:45:16Z")

</div>

I've fixed the issue at parsing the filename with [Mp3tag v2.91a](https://community.mp3tag.de/t/455). Thanks again for pointing!

---

<div class="post-metadata">

### Author: ![gsa999](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/g/c6cbf5/32.png) [@gsa999](https://community.mp3tag.de/u/gsa999)
#### Post date: [December 28, 2018, 11:01am UTC](https://community.mp3tag.de/t/strip-out-part-of-album-title-to-create-a-playlist-file/43826/14 "2018-12-28T11:01:10Z")

</div>

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)

```auto
$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)

```auto
$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

```auto
$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:

```auto
﻿#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

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [December 28, 2018, 11:30am UTC](https://community.mp3tag.de/t/strip-out-part-of-album-title-to-create-a-playlist-file/43826/15 "2018-12-28T11:30:51Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://community.mp3tag.de/uploads/default/original/2X/c/ce7035d426cb755a7916793326d23b465222a407.png) [@system](https://community.mp3tag.de/u/system)
#### Post date: [January 27, 2019, 11:30am UTC](https://community.mp3tag.de/t/strip-out-part-of-album-title-to-create-a-playlist-file/43826/16 "2019-01-27T11:30:52Z")

</div>

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