# Script to create an album genre from its various recording genres

**URL:** https://community.metabrainz.org/t/script-to-create-an-album-genre-from-its-various-recording-genres/670548
**Category:** MusicBrainz Picard
**Tags:** scripting, genres
**Created:** [December 17, 2023, 6:03pm UTC](https://community.metabrainz.org/t/script-to-create-an-album-genre-from-its-various-recording-genres/670548 "2023-12-17T18:03:32Z")
**Posts on this page:** 1
**Showing post:** 21

<div class="post-metadata">

### Author: ![ecomaniac](https://community.metabrainz.org/user_avatar/community.metabrainz.org/ecomaniac/32/57169_2.png) [@ecomaniac](https://community.metabrainz.org/u/ecomaniac)
#### Post date: [December 20, 2023, 8:29pm UTC](https://community.metabrainz.org/t/script-to-create-an-album-genre-from-its-various-recording-genres/670548/21 "2023-12-20T20:29:58Z")

</div>

Around holiday tasks, I’ve created an ‘album genre’ script. It’s based on the idea that if a recording genre appears in half or more of the tracks, it gets added to the ‘album genre’. It’s based on the clever routine that @rdswift provided.

```auto
$noop( ___Create album genre from genre counts___ )
$if(%_album_genre_processed%,,
  $foreach($get(aggregate_genre),
    $if($gte($mul($get(Genre '%_loop_value%' count),2),%totaltracks%),
      $if($not(%album_genre%),$setmulti(album_genre,%_loop_value%),
      $copymerge(album_genre,_loop_value))
    )
  )
)
$set(_album_genre_processed,1)

```

After this script, the album\_genre result for “Suave Suave” is “Electronic; New Age”.

Next, I will be creating a genre prioritization routine to set the order of genres within the multivariable from high to low (like Rock before Folk-Rock, Electronic before Techno, Jazz before Hard Bop, etc.). It will likely be similar to @hiccup’s [approach](https://community.metabrainz.org/t/picard-genre-scripts-wikidata-genre-plugin/529895/27).

Once they’re prioritized & sorted, I’ll truncate a potential long list to 5 or so genres maximum.

---

_[View the full topic](https://community.metabrainz.org/t/script-to-create-an-album-genre-from-its-various-recording-genres/670548)._
