Populate missing "album artist" fields from track 01 "artist" data?

My library is a bit of a mess (since it came from my old, huge, iTunes library, which I didn’t have the time/energy to have beets fully clean up). I’m absolutely loving beets.

When I import a new album, it’s great to have all the correct tags! One annoyance (which I assume is common) is that a lot of my files don’t have “album artist” populated, so I still browse by “artist”, which means that e.g. when there’s an album that’s mostly by “Artist X”, but has various tracks by “Artist X feat. lil’ Y”, things don’t show up as I expect.

So, is there a way to instruct beets to do something like “For everything in the library, if no album artist is defined, use the artist from track 01 to populate it”?

Inline plugin could set the paths accordingly. You could perhaps adapt this into a standalone plugin that actually updates the tags, but it’s beyond my skills.

Here’s what I do with inline - you would have to customize the “else” case to just take the first item.artist as the album artist. A more advanced option would be to add all the item.artists to a list (not sure what Python object to use here) and take the most frequent one. This is an album field I use:

def alb_artist(albumartist, items):
	# TODO get this from beets config itself?
	va_str = "Various Artists"
	if albumartist:
		return albumartist
	else:
		# the album probably has no MBid
		# return va_str if multiple artists are found on the album
		my_artists = set()
		for item in items:
			my_artists.add(item.artist)
			if len(my_artists) > 1:
				return va_str
		# every artist is the same
		return my_artists.pop()