# How do you do an else with inline?

**URL:** <https://discourse.beets.io/t/how-do-you-do-an-else-with-inline/2542>\
**Category:** Help\
**Created:** [April 28, 2024, 3:44am UTC](https://discourse.beets.io/t/how-do-you-do-an-else-with-inline/2542 "2024-04-28T03:44:58Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![swills](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@swills](https://discourse.beets.io/u/swills)\
**Post date:** [April 28, 2024, 3:44am UTC](https://discourse.beets.io/t/how-do-you-do-an-else-with-inline/2542/1 "2024-04-28T03:44:58Z")

</div>

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;

```auto
inline:
  album_fields:
      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’.

---

<div class="post-metadata">

**Author:** ![alucardmage](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@alucardmage](https://discourse.beets.io/u/alucardmage)\
**Post date:** [April 28, 2024, 4:50am UTC](https://discourse.beets.io/t/how-do-you-do-an-else-with-inline/2542/2 "2024-04-28T04:50:33Z")

</div>

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

```auto
album_fields:
    digital: |
      if $media == 'Digital Media':
        return '1'
      else:
        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!

---

<div class="post-metadata">

**Author:** ![swills](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@swills](https://discourse.beets.io/u/swills)\
**Post date:** [April 28, 2024, 5:25am UTC](https://discourse.beets.io/t/how-do-you-do-an-else-with-inline/2542/3 "2024-04-28T05:25:23Z")

</div>

No go. Tried it several ways. Thank you!

---

<div class="post-metadata">

**Author:** ![alucardmage](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@alucardmage](https://discourse.beets.io/u/alucardmage)\
**Post date:** [April 28, 2024, 8:51am UTC](https://discourse.beets.io/t/how-do-you-do-an-else-with-inline/2542/4 "2024-04-28T08:51:56Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![swills](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@swills](https://discourse.beets.io/u/swills)\
**Post date:** [April 28, 2024, 1:51pm UTC](https://discourse.beets.io/t/how-do-you-do-an-else-with-inline/2542/5 "2024-04-28T13:51:58Z")

</div>

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

```

The above always produces ‘web’.

---

<div class="post-metadata">

**Author:** ![swills](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@swills](https://discourse.beets.io/u/swills)\
**Post date:** [April 28, 2024, 3:28pm UTC](https://discourse.beets.io/t/how-do-you-do-an-else-with-inline/2542/6 "2024-04-28T15:28:47Z")

</div>

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

[https://beets.readthedocs.io/en/stable/plugins/rewrite.html](https://beets.readthedocs.io/en/stable/plugins/rewrite.html)

```auto
# rewrite
rewrite:
  media Digital Media: Web

```

---

<div class="post-metadata">

**Author:** ![alucardmage](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@alucardmage](https://discourse.beets.io/u/alucardmage)\
**Post date:** [April 29, 2024, 1:05am UTC](https://discourse.beets.io/t/how-do-you-do-an-else-with-inline/2542/7 "2024-04-29T01:05:34Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![arogl](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/arogl/32/455_2.png) [@arogl](https://discourse.beets.io/u/arogl)\
**Post date:** [April 29, 2024, 1:25am UTC](https://discourse.beets.io/t/how-do-you-do-an-else-with-inline/2542/8 "2024-04-29T01:25:49Z")

</div>

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

Change to:

```py
inline:
  album_fields:
      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

---

<div class="post-metadata">

**Author:** ![swills](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@swills](https://discourse.beets.io/u/swills)\
**Post date:** [April 29, 2024, 3:11pm UTC](https://discourse.beets.io/t/how-do-you-do-an-else-with-inline/2542/9 "2024-04-29T15:11:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![swills](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@swills](https://discourse.beets.io/u/swills)\
**Post date:** [April 29, 2024, 3:18pm UTC](https://discourse.beets.io/t/how-do-you-do-an-else-with-inline/2542/10 "2024-04-29T15:18:57Z")

</div>

Never heard of substitute until now though so thanks.

[https://beets.readthedocs.io/en/latest/plugins/substitute.html](https://beets.readthedocs.io/en/latest/plugins/substitute.html)
