# Audible via API to prevent use of empty fields when composing fields

**URL:** https://community.mp3tag.de/t/audible-via-api-to-prevent-use-of-empty-fields-when-composing-fields/71175
**Category:** Web Sources Discussion
**Created:** [March 20, 2026, 1:34pm UTC](https://community.mp3tag.de/t/audible-via-api-to-prevent-use-of-empty-fields-when-composing-fields/71175 "2026-03-20T13:34:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Casual\_Tea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/casual_tea/32/18886_2.png) [@Casual\_Tea](https://community.mp3tag.de/u/Casual_Tea)
#### Post date: [March 20, 2026, 1:34pm UTC](https://community.mp3tag.de/t/audible-via-api-to-prevent-use-of-empty-fields-when-composing-fields/71175/1 "2026-03-20T13:34:48Z")

</div>

Something that might be worth fixing:  
When an audiobook returns only the narrator but no author, the ARTIST starts with a `, `, trying to concatenate something that's absent.

Example Audiobook The Lost Colony by Eoin Colfer: ASIN `B002VACJKG` looked up on .com:

 ![mp3tag fetched info](https://community.mp3tag.de/uploads/default/original/3X/5/3/5307438b5481496dab657a3652f43e7699499e21.png)

General question:  
Would it be possible to populate ALBUMARTISTSORT with `last name, first name middle name`?

I'm trying to match the naming options in [this tool](https://getlibation.com/docs/features/naming-templates#name-formatters) in Mp3tag to manually conform old audiobooks to the new naming style I've selected.

ALBUMARTISTSSORT and ARTISTSORT could be populated in this manner as well, but that's beyond my personal needs. I just want audiobooks sorted into folders by author's last name, first name middle name.  
Currently I have to transform the ALBUMARTIST via regex in an action. If the audible API delivers the needed information (which the ability of the other tool to freely arrange first, middle and last name suggests), that would be preferable in my opinion.

---

<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: [March 27, 2026, 5:39pm UTC](https://community.mp3tag.de/t/audible-via-api-to-prevent-use-of-empty-fields-when-composing-fields/71175/2 "2026-03-27T17:39:17Z")

</div>

> [@Casual\_Tea](#):
>
> When an audiobook returns only the narrator but no author, the ARTIST starts with a `, `, trying to concatenate something that's absent.

Thanks! I've already fixed it locally and will release a new version soon.

> [@Casual\_Tea](#):
>
> Would it be possible to populate ALBUMARTISTSORT with `last name, first name middle name`?

I've looked at the API results and it provides the author names as one string, i.e., not separated in any way, e.g., as

```auto
James S. A. Corey
George R.R. Martin
Fjodor Michailowitsch Dostojewski

```

The tool you've referenced uses a dedicated external library (`NameParserSharp`) for name parsing.

So to answer your question: I think it's not possible to do this in a reliable way from the Tag Source. If I would add any code for that, I'm sure that there is always another edge case waiting around the corner for me to address.

Would you mind sharing the regular expressions you're currently using for that?

---

<div class="post-metadata">

### Author: ![Casual\_Tea](https://community.mp3tag.de/user_avatar/community.mp3tag.de/casual_tea/32/18886_2.png) [@Casual\_Tea](https://community.mp3tag.de/u/Casual_Tea)
#### Post date: [March 28, 2026, 6:57pm UTC](https://community.mp3tag.de/t/audible-via-api-to-prevent-use-of-empty-fields-when-composing-fields/71175/3 "2026-03-28T18:57:29Z")

</div>

> [@Florian](#):
>
> Thanks! I've already fixed it locally and will release a new version soon.

Lovely. Another thing I noticed that might be unwanted is that when there is a `Series`, but no `Series-Part`, `CONTENTGROUP` and `ALBUMSORT` get formatted as if there was a `Series-Part`.

Example: Weihnachten auf der Lindwurmfeste by Walter Moers  
ASIN: `3844530843` looked up on .com yields:

`ALBUMSORT`:  
`Zamonien - Weihnachten auf der Lindwurmfeste`  
1 superflous space after the series name.

`CONTENTGROUP`:  
`Zamonien, Book #`  
`, Book #` is not needed without a series number imho.

> [@Florian](#):
>
> I've looked at the API results and it provides the author names as one string, i.e., not separated in any way

That is a pity.

> [@Florian](#):
>
> The tool you've referenced uses a dedicated external library (`NameParserSharp`) for name parsing.

Good to know, thank you for looking into it!

> [@Florian](#):
>
> So to answer your question: I think it's not possible to do this in a reliable way from the Tag Source. If I would add any code for that, I'm sure that there is always another edge case waiting around the corner for me to address.

I agree, there would always be outliers that yield wrong results.

> [@Florian](#):
>
> Would you mind sharing the regular expressions you're currently using for that?

Since I only started treating audiobooks separately a bit over a week ago when I set up [audiobookshelf](https://github.com/advplyr/audiobookshelf), I was using a fairly primitve regex that works for single authors but instantly breaks when there's more than one since I was hoping that the Audible API yields the required information.

 ![primitive](https://community.mp3tag.de/uploads/default/original/3X/e/9/e9ca774cb3773df9c4cd368f1429c3d94c33c9a9.png)

Now that you told me that it does not, I tried to refine my regex to account for single and multiple authors, but I've hit a snag.

 ![WIP Regex](https://community.mp3tag.de/uploads/default/original/3X/5/e/5e8c3c9135b7c4238b0ae7b5d9ce5d45d6d48b54.png)

This regex works well for 2 or more authors (I decided to truncate more than 2 authors down to 2 for the sorting field to avoid too long folder names), but leaves extra `; , ` when there's only one author.  
I had hoped to use `[]` to only add those parts when the `last1` and `first1` capturing groups are not empty, but it seems that named capturing groups do not count as [placeholders](https://docs.mp3tag.de/format/#characters-with-special-functionality).

Test without `[]` yields both authors.

```auto
$regexp(%albumartist%,^(?<first>'['^','']'+) (?<last>'['^','']'+)(?:(?:',' )(?<first1>'['^','']'+) (?<last1>'['^','']'+))?.*$,$+{last}',' $+{first}; $+{last1}',' $+{first1})

```

 ![no square brackets](https://community.mp3tag.de/uploads/default/original/3X/9/2/9285782fbdae55a4201a31a8f7ff51289eee36b6.png)  
Test with `[]` only yields the first author.

```auto
$regexp(%albumartist%,^(?<first>'['^','']'+) (?<last>'['^','']'+)(?:(?:',' )(?<first1>'['^','']'+) (?<last1>'['^','']'+))?.*$,$+{last}',' $+{first}[; $+{last1}',' $+{first1}])

```

 ![square brackets](https://community.mp3tag.de/uploads/default/original/3X/6/3/63b29ef26dc1021b39628b9fda73cce8a91d9fb2.png)

Personally I'll work around this limitation by using a secondary action to clean up. Here is the current state of what I'm using to fill `ALBUMARTISTSORT` based on `ALBUMARTIST`.

Action 1: `Format value`  
Field: `ALBUMARTISTSORT`  
Format String:

```auto
$if2(%albumartistsort%,$regexp(%albumartist%,^(?<first>'['^','']'+) (?<last>'['^','']'+)(?:(?:',' )(?<first1>'['^','']'+) (?<last1>'['^','']'+))?.*$,$+{last}',' $+{first}; $+{last1}',' $+{first1}))

```

This doesn't change existing `ALBUMARTISTSORT` fields and tries to swap first name and last name of the first 2 authors in `ALBUMARTIST`, separated by `; `.

Action 2: `Replace with regular expression`  
Regular expression: `^(.+); , $`  
Replace matches with: `$1`

This cleans up `; , ` when there was only a single author.

However since I have so far only added 55 authors, these actions are not widely tested and should only be used if the user understands them and their limitations. I'm sure that there are author names that break them or yield nonsensical results. I'll try to account for them as I encounter them.

---

<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: [May 5, 2026, 8:09am UTC](https://community.mp3tag.de/t/audible-via-api-to-prevent-use-of-empty-fields-when-composing-fields/71175/4 "2026-05-05T08:09:34Z")

</div>

I've just released [audible-api v0.6.4](https://community.mp3tag.de/t/ws-audible-via-api/64347), which fixes the two issues you've reported:

- Prevent use of empty `SERIES-PART` in `ALBUMSORT` and `CONTENTGROUP`.
- Prevent `ARTIST` to start with comma if only `NARRATOR` is provided.

* * *

Thank you for sharing the regular expressions. I've not incorporated any of those mainly based on your words of caution from above.
