Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add artist to filename only if artist != albumartist #664

Open
bernd-wechner opened this issue Jan 13, 2022 · 2 comments
Open

Add artist to filename only if artist != albumartist #664

bernd-wechner opened this issue Jan 13, 2022 · 2 comments

Comments

@bernd-wechner
Copy link
Contributor

I thought this pattern might do the trick:

$if(%discnumber%, %discnumber% - ,)$num(%track%,2) - %title%$if(NOT %artist% EQUAL %albumartist%,  - %artist%,)

But alas when artist and albumartist are equal this is appending "- %artist" albeit without a space in front of the "-".

So clearly I have some syntax to learn here ;-). But I've read the docs and haven't progressed. So I hope an issue is the right way to go.

@bernd-wechner
Copy link
Contributor Author

Well, well, well ... drilled into it and the reason is that the if function is a little dumb ;-). As in it check's for the truth condition with:

def check_truth(text):

which does not do any logical operator parsing. It's a simple Python truthy test. So another strategy is required or a smarter check_truth.

@bernd-wechner
Copy link
Contributor Author

bernd-wechner commented Jan 22, 2022

And voila an alternative approach that does work:

$if(%discnumber%, %discnumber% - ,)$num(%track%,2) - %title%$if($replace(%artist%, %albumartist%,),\ - %artist%,)

Key things to observe and document better:

  1. The $if function's first argument is false only if it's an empty string of the string '0' it handles no fancy boolean logic.
  2. If you put quotes around %tagname% then it is not expanded, you get a literal "%tagname"
    • I would suggest that the parser would be easily made better by respecting a shell like difference with single quotes functioning this way but double quotes supporting replacement of %tagname% with it's value.
    • I'm happy to loook into fixing it thusly if a PR is welcome and time permits.
  3. The backslash is honoured to insert a literal space, though oddly seems not needed for the trailing space in $if(%discnumber%, %discnumber% - ,) but needed in the leading space of %$if($replace(%artist%, %albumartist%,),\ - %artist%,)
    • I'd recommend consistency here.
    • Am again happy to consider fixing it to be consistent if a PR is welcome and time permits.

For now I am content that I have a pattern that does what I want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant