Aunique usage


#1

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

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

The above config produces this:

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?


#2

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

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:

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

#3

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}
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, "{}"}
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, [] }
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, () }
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, {} }
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:

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

but the result isn’t encouraging:

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

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:

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:

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

#4

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

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?


#5
$ 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}

#6

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

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

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


#7

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

$ 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:

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

which are already different.


#8

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.