# Determining whether condition applies to multiple files

**URL:** https://community.metabrainz.org/t/determining-whether-condition-applies-to-multiple-files/505506
**Category:** MusicBrainz Picard
**Tags:** scripting
**Created:** [November 25, 2020, 12:22am UTC](https://community.metabrainz.org/t/determining-whether-condition-applies-to-multiple-files/505506 "2020-11-25T00:22:03Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![outsidecontext](https://community.metabrainz.org/user_avatar/community.metabrainz.org/outsidecontext/32/90_2.png) [@outsidecontext](https://community.metabrainz.org/u/outsidecontext)
#### Post date: [April 8, 2021, 2:34pm UTC](https://community.metabrainz.org/t/determining-whether-condition-applies-to-multiple-files/505506/5 "2021-04-08T14:34:52Z")

</div>

I gave this a go with a slightly different approach:

[https://raw.githubusercontent.com/phw/picard-plugins/releasetag\_aggregations/plugins/releasetag\_aggregations/releasetag\_aggregations.py](https://raw.githubusercontent.com/phw/picard-plugins/releasetag_aggregations/plugins/releasetag_aggregations/releasetag_aggregations.py)

> **Note:** The functions names starting with `$album_` were previously called `$releasetag_`. I changed this with an update to version 0.4 and have updated this post accordingly.

This plugin provides a couple of functions that can be used to get aggregated values from all files on the release. Note: Due to technical limitations these functions work only when used in a naming script.

E.g. one can use the following to get a common media (note: variable names must be passed by name, e.g. `media`, not with value, e.g. `%media%`):

```auto
$album_all(media)

```

If all files have the same value for `media` (e.g. “CD”) that value will be returned, otherwise it will be empty. You can use this to just check whether all files have the same type or not:

```taggerscript
$if($album_all(media),all same media type,different media type)

```

For handling numeric values e.g. for including the bitrate in a folder name there are `$album_min()`, `$album_max()` and `$album_avg()`. E.g. you could do a bitrate range:

```taggerscript
$album_min(_bitrate)-$album_max(_bitrate)

```

Or to have it use only a single value if all files are identical combine it with `$album_all`:

```taggerscript
$if2($album_all(_bitrate),$album_min(_bitrate)-$album_max(_bitrate))

```

Another option is to use an average bitrate:

```taggerscript
$album_avg(_bitrate)

```

For something like genres you might want to use the most common value. There is `$album_mode()` for this:

```taggerscript
$album_mode(genre)

```

If you have 4 files tagged with a genre of “rock” and 3 with genre “metal” this will use “rock”. Now often there are multiple genres in a file (that means a genre tag is a multi-value tag). Let’s assume we have a release with individual tags tagged with the following genres:

1. rock; metal
2. rock; blues
3. blues
4. rock; metal
5. blues; alternative
6. blues; jazz

Using `$album_mode(genre)` would pick “rock; metal” as the genre, because this is the most common combination. But maybe you want the most common single value? There is `$album_multi_mode()` for this:

```taggerscript
$album_multi_mode(genre)

```

This looks at all the values individually and hence will give “blues” (which is used 4 times, followed by rock 3 times).

There are also multi tag variations of min, max and average (`$album_multi_min()`, `$album_multi_max()`, `$album_multi_avg()`).

To install the script the easiest is to download the file releasetag\_aggregations.py from [https://raw.githubusercontent.com/phw/picard-plugins/releasetag\_aggregations/plugins/releasetag\_aggregations/releasetag\_aggregations.py](https://raw.githubusercontent.com/phw/picard-plugins/releasetag_aggregations/plugins/releasetag_aggregations/releasetag_aggregations.py) and install it from inside Picard via Options \> Plugins \> Install plugin…

---

_[View the full topic](https://community.metabrainz.org/t/determining-whether-condition-applies-to-multiple-files/505506)._
