How do you do an else with inline?

I am Googling my heart out and can’t find an example. Is it possible to do an else with inline?

If I had inline set up like this;

      rerelease: 1 if $year > $original_year else 0
      digital: 1 if $media == 'Digital Media' else 0

I can do this;
%if{$rerelease, [RE-$year]}

But what if I wanted to do an else? How would I do that?

I would assume I would just separate by a comma and put at end but didn’t seem to work. May have been a fluke. Will try again.

Trying to do %if{$digital,Web,$media} but it labels everything ‘Web’.

I think I see what you’re doing… This may help, as it’s very similar to something I use in mine.

    digital: |
      if $media == 'Digital Media':
        return '1'
        return None

I think your command is not working correctly because “0” is still a “value” to the script and the %if{A,B,C} essentially says Does A have any value? If so, do B. Hopefully this helps!

No go. Tried it several ways. Thank you!

No problem. One thing that has gotten me a few times is the paths: settings when having various albumtypes so to speak. (admittedly I’m still a beginner at beets). But make sure whatever path(s) you have set up either all match your format, or that your album is being correctly categorized to the right path setting. (I’ve definitely run into that problem before) Hopefully you figure it our, or someone else has more insight on it!

    rerelease: 1 if $year > $original_year else 0
    web: |
        if "Digital" in $media:
          return 'Web'
          return $media

The above always produces ‘web’.

The rewrite plugin made this much easier and is suited for exactly this goal.

# rewrite
  media Digital Media: Web

Nice. Glad you found something that works. Just something to keep an eye out for, if my memory serves, I stopped using rewrite and switched to substitute. The documentation says it doesn’t rewrite the tag, but I believe upon using any commands on already imported files will actually write the “Web” tag as opposed to “Digital Media” in your media tag. If that’s fine with you, then disregard and enjoy!

From your original block of code you ahave left out the return values

Change to:

      rerelease: return 1 if $year > $original_year else return 0
      digital: return 1 if $media == 'Digital Media' else return 0

note the 4 extra return statements

You don’t actually need the returns. rerelease works fine without them and there are examples in the docs without them.

Never heard of substitute until now though so thanks.