# Aunique usage

**URL:** <https://discourse.beets.io/t/aunique-usage/173>\
**Category:** Help\
**Created:** [August 28, 2017, 8:08pm UTC](https://discourse.beets.io/t/aunique-usage/173 "2017-08-28T20:08:15Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![devster](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/devster/32/68_2.png) [@devster](https://discourse.beets.io/u/devster)\
**Post date:** [August 28, 2017, 8:08pm UTC](https://discourse.beets.io/t/aunique-usage/173/1 "2017-08-28T20:08:15Z")

</div>

I’m trying to add braces to the `%aunique` binding, but I’m kind of struggling.

```auto
paths:
    default: $albumartist/$albumartist - $album%aunique{albumartist album year, label catalognum, {}} [$format]/%if{$multidisc,$disc-}$track. $title

```

The above config produces this:

```nohighlight
Franz Ferdinand - Franz Ferdinand (2004) 679{} [$format]/%if{$multidisc,$disc-}$track. $title.6.flac

```

When trying to escape them for example like `'{}'` or `"'{}'"` or even with `''{}''` the result is a variation of the above.  
I’m not escaping these things correctly, what’s the proper way?

---

<div class="post-metadata">

**Author:** ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)\
**Post date:** [August 28, 2017, 9:04pm UTC](https://discourse.beets.io/t/aunique-usage/173/2 "2017-08-28T21:04:41Z")

</div>

Hi! The docs have details on the syntax for writing template strings:  
[http://beets.readthedocs.io/en/v1.4.5/reference/pathformat.html?highlight=escape#syntax-details](http://beets.readthedocs.io/en/v1.4.5/reference/pathformat.html?highlight=escape#syntax-details)

Namely, it shouldn’t be necessary to escape {} characters. I’m actually a little confused about how that output got generated—it really seems like the template parser got very confused.

Maybe it’s worth experimenting a little more to see if you can pare down the template to the bare minimum, which will help you get a clearer picture of the problem. Using `beet ls -f` to specify a template string is a good way to do this kind of experiment:

```auto
$ beet ls -f '$albumartist/$albumartist - $album%aunique{albumartist album year, label catalognum, {} } [$format]/%if{$multidisc,$disc-}$track. $title'

```

---

<div class="post-metadata">

**Author:** ![devster](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/devster/32/68_2.png) [@devster](https://discourse.beets.io/u/devster)\
**Post date:** [August 29, 2017, 12:18am UTC](https://discourse.beets.io/t/aunique-usage/173/3 "2017-08-29T00:18:42Z")

</div>

After a few experiments here are the results. I used your exact line and only changed the `%aunique{}` field, I left single quotes.

- With: `%aunique{albumartist album year, label catalognum}`

```nohighlight
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand [237] [MP3]/01-01. Jacqueline
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand [678] [MP3]/01. Jacqueline

```

- With `%aunique{albumartist album year, label catalognum, "{}"}`

```nohighlight
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand 237"} [$format]%if{$multidisc,$disc-}$track. $title
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand 678"} [$format]%if{$multidisc,$disc-}$track. $title

```

- With: `%aunique{albumartist album year, label catalognum, [] }`

```nohighlight
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand 237 [MP3]/01-01. Jacqueline
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand 678 [MP3]/01. Jacqueline

```

- With `%aunique{albumartist album year, label catalognum, () }`

```nohighlight
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand 237 [MP3]/01-01. Jacqueline
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand 678 [MP3]/01. Jacqueline

```

- With `%aunique{albumartist album year, label catalognum, {} }`

```nohighlight
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand 237{ } [$format]/%if{$multidisc,$disc-}$track. $title
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand 678{ } [$format]/%if{$multidisc,$disc-}$track. $title

```

I also tried using this line:

```auto
$ beet ls -f '$albumartist/$albumartist - $album%aunique{albumartist album year, label catalognum, {} } - $track'

```

but the result isn’t encouraging:

```nohighlight
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand 237{} - $track
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand 678{} - $track

```

Moreover it seems in some cases the unique isn’t necessary at all, for example I do have also a FLAC version of this album, but

```nohighlight
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand 237 [MP3]/01-01. Jacqueline
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand 678 [MP3]/01. Jacqueline
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand 679 [FLAC]/01-01. Jacqueline

```

The field still gets populated (with `679` in this case). I’m guessing that this happens because the `$format` is used after `%aunique{}`?

To try and solve it I also tried using something `%aunique{albumartist album year format}` but I got:

```nohighlight
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand<no such column: format> [MP3]/01-01. Jacqueline

```

* * *

As a second side note, all formats with `%aunique{}` and using `beet ls -a` results in something like:

```nohighlight
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand<no such field 'album_id'> [$format]$disc-$track. $title

```

---

<div class="post-metadata">

**Author:** ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)\
**Post date:** [August 29, 2017, 1:15am UTC](https://discourse.beets.io/t/aunique-usage/173/4 "2017-08-29T01:15:54Z")

</div>

Indeed, format isn’t an album-level field, and aunique can only be used in an item context. The former was just being discussed on the issue tracker: [https://github.com/beetbox/beets/issues/2610#issuecomment-325514673](https://github.com/beetbox/beets/issues/2610#issuecomment-325514673)

Anyway, I’m still not certain what’s going on with the parser. Maybe it would be helpful to try other, simpler functions (such as %left) with curly braces as arguments to see if it’s a more general problem?

---

<div class="post-metadata">

**Author:** ![devster](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/devster/32/68_2.png) [@devster](https://discourse.beets.io/u/devster)\
**Post date:** [August 29, 2017, 8:01am UTC](https://discourse.beets.io/t/aunique-usage/173/5 "2017-08-29T08:01:04Z")

</div>

> [@adrian](#):
>
> Anyway, I’m still not certain what’s going on with the parser. Maybe it would be helpful to try other, simpler functions (such as %left) with curly braces as arguments to see if it’s a more general problem?

```sh
$ beet ls -f '%left{beets, 1}' album:do you want to
b
$ beet ls -f '%left{{}, 1}, %right{{},1}' album:do you want to
<tmpl_left() missing 1 required positional argument: 'chars'>, 1}, %right{{},1}
$ beet ls -f '%upper{beet {} rocks}, %left{{}, 1}, %right{{}, 1}' album:do you want to
BEET { rocks}, %left{{}, 1}, %right{{}, 1}

```

---

<div class="post-metadata">

**Author:** ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)\
**Post date:** [August 29, 2017, 1:40pm UTC](https://discourse.beets.io/t/aunique-usage/173/6 "2017-08-29T13:40:02Z")

</div>

OK; that certainly narrows it down! This should definitely not be an error:

```auto
$ beet ls -f '%left{foo{}bar,1}'

```

Would you mind filing a bug on GitHub with that example and other details?

---

<div class="post-metadata">

**Author:** ![devster](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/devster/32/68_2.png) [@devster](https://discourse.beets.io/u/devster)\
**Post date:** [August 29, 2017, 5:11pm UTC](https://discourse.beets.io/t/aunique-usage/173/7 "2017-08-29T17:11:57Z")

</div>

I filled the bug, but even the latest one still reports an error for me.

```auto
$ beet ls -f '%left{foo{}bar,1}'
<tmpl_left() missing 1 required positional argument: 'chars'>bar,1}

```

I don’t think it’s just the spaces.

I’m still a bit confused by the fact that `%aunique` tries to deduplicate these 2 paths:

```nohighlight
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand [678] [MP3]/
Franz Ferdinand/Franz Ferdinand - Franz Ferdinand [679] [FLAC]/

```

which are already different.

---

<div class="post-metadata">

**Author:** ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)\
**Post date:** [August 29, 2017, 5:51pm UTC](https://discourse.beets.io/t/aunique-usage/173/8 "2017-08-29T17:51:11Z")

</div>

Thanks! Yes, sorry; I meant to say that even my tiny example triggered the problem.

About the format thing: to tell aunique that formats should “tell albums apart,” you will need to add it to the arguments to indicate that it’s a dusambiguator.

---

<div class="post-metadata">

**Author:** ![DjSlash](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/djslash/32/351_2.png) [@DjSlash](https://discourse.beets.io/u/DjSlash)\
**Post date:** [April 29, 2020, 12:40pm UTC](https://discourse.beets.io/t/aunique-usage/173/9 "2020-04-29T12:40:29Z")

</div>

Sorry to bump up this old topic.

I experienced the same issue and started searching. I found this topic, but failed to find the mentioned bug issue on github.

But I digged further and found that in recent beets versions `aunique` became a configuration option. When using `bracket: '{}'` it does work as expected. But anything inline with curly brackets and attempting to escape them ends up in weird placements.

So somehow the inline part is being parsed differently.

---

<div class="post-metadata">

**Author:** ![JeezOPete](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@JeezOPete](https://discourse.beets.io/u/JeezOPete)\
**Post date:** [May 31, 2020, 12:23pm UTC](https://discourse.beets.io/t/aunique-usage/173/10 "2020-05-31T12:23:55Z")

</div>

> [@DjSlash](#):
>
> But anything inline with curly brackets and attempting to escape them ends up in weird placements.

I have the same issue with the braces when used inline. I did fine that parentheses `()` do work when used inline and don’t cause the same issue as braces. For example:

`%aunique{albumartist album, albumtype year label catalognum albumdisambig releasegroupdisambig,()}`
