What I found was that if the artist tag ends in a space, the resulting image filename will still have only a single space before the dash in the filename.
I'm not trying to reverse-engineer it the other way, I'm trying to do the same thing Poweramp does to find the appropriate images for a given song file.
What I've managed to find right now is this, and while it seems to work, I'd like to know if this is actually equivalent to what Poweramp does internally.
SPECIAL_CHARS =
# windows disallowed
'<>:"/\\|?*' +
# found myself
'()[]&\''
special_chars_rx = f'[{re.escape(SPECIAL_CHARS)}]'
aa_fname_single = f'{re.sub(special_chars_rx, '_', artist_tag).strip()} - {re.sub(special_chars_rx, '_', title_tag).strip()}.jpg'
aa_fname_album = f'{re.sub(special_chars_rx, '_', artist_tag).strip()} - {re.sub(special_chars_rx, '_', album_tag).strip()}.jpg'
if os.path.isfile(aa_fname_album):
# embed aa_fname_album into the song file
elif os.path.isfile(aa_fname_single):
# embed aa_fname_single into the song file