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

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:

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

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

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

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?

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.

That is a pity.

Good to know, thank you for looking into it!

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

Since I only started treating audiobooks separately a bit over a week ago when I set up 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.

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.

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.

Test without [] yields both authors.

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


Test with [] only yields the first author.

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

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:

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

I've just released audible-api v0.6.4, 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.