# Title Tagger script unexpectedly repeating values - why?

**URL:** <https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950>\
**Category:** MusicBrainz Picard\
**Tags:** taggerscript, picard\
**Created:** [April 21, 2022, 4:51pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950 "2022-04-21T16:51:35Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![xhiris](https://community.metabrainz.org/letter_avatar_proxy/v4/letter/x/9e8a1a/32.png) [@xhiris](https://community.metabrainz.org/u/xhiris)\
**Post date:** [April 21, 2022, 4:51pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/1 "2022-04-21T16:51:36Z")

</div>

I’m trying to tag live tracks with the recording disambiguation comment if it has one, e.g.

[https://musicbrainz.org/recording/9efa7d1f-0688-4d65-b623-f6b2cfa6f172?tport=8000](https://musicbrainz.org/recording/9efa7d1f-0688-4d65-b623-f6b2cfa6f172?tport=8000)

It has the title “I Need You” and I want it to be “I Need You (live, 2005-10-23: XM Performance Theater, Washington, DC, USA)”. in my file.

I’m using this tagger script:

`$set(title,%title%$if(%_recordingcomment%, \(%_recordingcomment%\)))`

But what I get is

I Need You (live, 2005-10-23: XM Performance Theater, Washington, DC, USA) (live, 2005-10-23: XM Performance Theater, Washington, DC, USA) (live, 2005-10-23: XM Performance Theater, Washington, DC, USA) (live, 2005-10-23: XM Performance Theater, Washington, DC, USA) (live, 2005-10-23: XM Performance Theater, Washington, DC, USA) [… repeated MANY more times]

A few things I noticed:

- It only happens with tracks that have a file.
- The title is normal in the treeview on the right, but not in in the tag list below or in a file naming script.
- The “Move disambiguation to album title” script from [https://picard-docs.musicbrainz.org/en/extending/scripts.html](https://picard-docs.musicbrainz.org/en/extending/scripts.html) works fine.

I’ve tried restarting Picard, refreshing the album and removing all plugins, naming scripts and other tagging scripts to no avail.

I’m about to try a clean install with default settings.

What’s going on here?

Thanks,

Xhiris

 ![Capture](https://community.metabrainz.org/uploads/default/original/3X/c/a/ca4840597daec0da56daa2a50baa22f820572dbd.png)

---

<div class="post-metadata">

**Author:** ![ernstlx](https://community.metabrainz.org/user_avatar/community.metabrainz.org/ernstlx/32/27258_2.png) [@ernstlx](https://community.metabrainz.org/u/ernstlx)\
**Post date:** [April 21, 2022, 6:40pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/2 "2022-04-21T18:40:39Z")

</div>

> [@xhiris](#):
>
> I’m using this tagger script:
> 
> `$set(title,%title%$if(%_recordingcomment%, \(%_recordingcomment%\)))`

This script has a flaw: if you add the \_recordingcomment to the title it becomes part of the title. If you execute it again it adds the \_recordingcomment to the already complete title. I suppose you executed it more than once. For the first time it should work.

---

<div class="post-metadata">

**Author:** ![ernstlx](https://community.metabrainz.org/user_avatar/community.metabrainz.org/ernstlx/32/27258_2.png) [@ernstlx](https://community.metabrainz.org/u/ernstlx)\
**Post date:** [April 21, 2022, 10:42pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/3 "2022-04-21T22:42:01Z")

</div>

Because it’s a bit destructive to point out what’s wrong, not saying what will work, here my suggestion:

```auto
$if(%_recordingcomment%,
  $if($rsearch(%title%,%_recordingcomment%),,$set(title,%title% \(%_recordingcomment%\))))

```

Only IF there’s a \_recordingcomment do anything, then IF the \_recordingcomment is already part of the title, found/returned by rsearch(), do also nothing (after the first comma nothing), IF NOT (after the second comma), only then, SET the new value for title.  
But it would fail, if the text was changed on MB, so it’s probably better to only search for the first characters:

```auto
$if(%_recordingcomment%,
  $if($rsearch(%title%,$substr(%_recordingcomment%,0,4)),,$set(title,%title% \(%_recordingcomment%\))))

```

---

<div class="post-metadata">

**Author:** ![xhiris](https://community.metabrainz.org/letter_avatar_proxy/v4/letter/x/9e8a1a/32.png) [@xhiris](https://community.metabrainz.org/u/xhiris)\
**Post date:** [April 21, 2022, 10:53pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/4 "2022-04-21T22:53:09Z")

</div>

Yes, I’m tweaking and testing naming and tagging scripts and refreshing after each change.

What was confusing me is it was adding 30 or more duplicates at the end, like something’s stuck in a loop. I can see it adding a duplicate on each refresh (or doubling each time), but even if I only set a tag once it was still blowing up.

I like your suggestion of putting processing in $if blocks, I find that much easier to follow and it feels more reliable than many nested `$set(foo$if(bar),baz,wibble)`.

In any case, thank you!

---

<div class="post-metadata">

**Author:** ![ernstlx](https://community.metabrainz.org/user_avatar/community.metabrainz.org/ernstlx/32/27258_2.png) [@ernstlx](https://community.metabrainz.org/u/ernstlx)\
**Post date:** [April 21, 2022, 11:14pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/5 "2022-04-21T23:14:45Z")

</div>

My pleasure!  
But you should not use the second version. It’s probably not necessary or makes it worse.

1. If you don’t keep “title” (Preserve these tags…), there should be no problem anyway. It will always be built anew with new data.
2. But even if you keep “title”, it’s better for the script to fail in case of changes, because otherwise you will not notice and miss them completely.

---

<div class="post-metadata">

**Author:** ![ernstlx](https://community.metabrainz.org/user_avatar/community.metabrainz.org/ernstlx/32/27258_2.png) [@ernstlx](https://community.metabrainz.org/u/ernstlx)\
**Post date:** [April 22, 2022, 9:47am UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/6 "2022-04-22T09:47:32Z")

</div>

I have to thank you for this idea!

I found out, I really like the idea of adding the recording disambiguation to the track titles, because it’s information otherwise not available at all. But (for me) it should be added in case of live recordings only, to avoid comments like “this is the short version without telephone ringing” being added to the track title. Therefore I made a little change:

```auto
$if($startswith(%_recordingcomment%,live),
  $if($rsearch(%title%,%_recordingcomment%),,$set(title,%title% \(%_recordingcomment%\))))

```

… if there is no \_recordingcomment or it does not start with “live”, an empty string will be returned and nothing will be done.

EDIT: substr() removed from script

---

<div class="post-metadata">

**Author:** ![rdswift](https://community.metabrainz.org/user_avatar/community.metabrainz.org/rdswift/32/7032_2.png) [@rdswift](https://community.metabrainz.org/u/rdswift)\
**Post date:** [April 22, 2022, 2:28pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/7 "2022-04-22T14:28:51Z")

</div>

That would miss comments like “Recorded live at…” so you might consider changing your `$startswith()` check to use `$find()` instead.

---

<div class="post-metadata">

**Author:** ![ernstlx](https://community.metabrainz.org/user_avatar/community.metabrainz.org/ernstlx/32/27258_2.png) [@ernstlx](https://community.metabrainz.org/u/ernstlx)\
**Post date:** [April 22, 2022, 3:10pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/8 "2022-04-22T15:10:59Z")

</div>

> [@rdswift](#):
>
> That would miss comments like “Recorded live at…”

Thanks, yes! But disambiguations like that should be corrected as they are not conform with the GL for live recordings 😉

(And I thought about missing (by purpose) some with “partially recorded live…” from my collection which I like to treat as studio recordings)

---

<div class="post-metadata">

**Author:** ![rdswift](https://community.metabrainz.org/user_avatar/community.metabrainz.org/rdswift/32/7032_2.png) [@rdswift](https://community.metabrainz.org/u/rdswift)\
**Post date:** [April 22, 2022, 3:13pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/9 "2022-04-22T15:13:40Z")

</div>

In that case, perhaps a regular expression search something like `/.*([Rr]ecorded )?[Ll]ive/`

**EDIT:** Sorry, I was thinking of disambiguation rather than track comment. You’re right, that doesn’t match the guideline.

---

<div class="post-metadata">

**Author:** ![ernstlx](https://community.metabrainz.org/user_avatar/community.metabrainz.org/ernstlx/32/27258_2.png) [@ernstlx](https://community.metabrainz.org/u/ernstlx)\
**Post date:** [April 22, 2022, 3:52pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/10 "2022-04-22T15:52:43Z")

</div>

No reason, your input is always welcome!  
But in this case I chose startswith() to make sure that only real live recordings will have this comment added to the track title.

---

<div class="post-metadata">

**Author:** ![IvanDobsky](https://community.metabrainz.org/user_avatar/community.metabrainz.org/ivandobsky/32/11785_2.png) [@IvanDobsky](https://community.metabrainz.org/u/IvanDobsky)\
**Post date:** [April 22, 2022, 4:13pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/11 "2022-04-22T16:13:34Z")

</div>

> [@rdswift](#):
>
> search something like `/.*([Rr]ecorded )?[Ll]ive/`

Breaks on **(version with Clive on bongos)**? (Sorry - I can break any algorithm… 🤣 🔨 )

@ernstlx - Think I am going to borrow that script of yours. Fits my needs well. How would one add **(demo, 1999-09-08: blah)**? How to tweak **startswith live** to **startswith live or demo**?

---

<div class="post-metadata">

**Author:** ![ernstlx](https://community.metabrainz.org/user_avatar/community.metabrainz.org/ernstlx/32/27258_2.png) [@ernstlx](https://community.metabrainz.org/u/ernstlx)\
**Post date:** [April 22, 2022, 4:23pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/12 "2022-04-22T16:23:20Z")

</div>

Should work with $or($startswith(…),$startswith(…))  
but I have not tested something. If one or the other condition matches, do it. $or() is always a bit tricky

---

<div class="post-metadata">

**Author:** ![IvanDobsky](https://community.metabrainz.org/user_avatar/community.metabrainz.org/ivandobsky/32/11785_2.png) [@IvanDobsky](https://community.metabrainz.org/u/IvanDobsky)\
**Post date:** [April 22, 2022, 4:27pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/13 "2022-04-22T16:27:19Z")

</div>

Sounds good to me. As it would be impossible to start with both demo and live, OR seems perfect here.

I’ll see if I can find the example that uses (demo, like that and test it.

Thanks.

---

<div class="post-metadata">

**Author:** ![ernstlx](https://community.metabrainz.org/user_avatar/community.metabrainz.org/ernstlx/32/27258_2.png) [@ernstlx](https://community.metabrainz.org/u/ernstlx)\
**Post date:** [April 22, 2022, 4:31pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/14 "2022-04-22T16:31:11Z")

</div>

But you have to consider that demo is often included in the track title anyway.  
(and I have to consider that the same is true for “live” 😉)

---

<div class="post-metadata">

**Author:** ![rdswift](https://community.metabrainz.org/user_avatar/community.metabrainz.org/rdswift/32/7032_2.png) [@rdswift](https://community.metabrainz.org/u/rdswift)\
**Post date:** [April 22, 2022, 5:56pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/15 "2022-04-22T17:56:19Z")

</div>

> [@IvanDobsky](#):
>
> Breaks on **(version with Clive on bongos)**

That’s it. I’m done with trying to help people in this forum if all I get is smart ass responses.

I mean, really, what value does that comment add to the conversation?

---

<div class="post-metadata">

**Author:** ![ernstlx](https://community.metabrainz.org/user_avatar/community.metabrainz.org/ernstlx/32/27258_2.png) [@ernstlx](https://community.metabrainz.org/u/ernstlx)\
**Post date:** [April 22, 2022, 6:13pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/16 "2022-04-22T18:13:39Z")

</div>

Probably you have to deal with this kind of humor.  
And you have helped me a lot!!! 🙂

---

<div class="post-metadata">

**Author:** ![IvanDobsky](https://community.metabrainz.org/user_avatar/community.metabrainz.org/ivandobsky/32/11785_2.png) [@IvanDobsky](https://community.metabrainz.org/u/IvanDobsky)\
**Post date:** [April 22, 2022, 6:21pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/17 "2022-04-22T18:21:48Z")

</div>

> [@rdswift](#):
>
> That’s it. I’m done with trying to help people in this forum if all I get is smart ass responses.

Really deeply sorry. I am used to testing software and often spot odd cases where something acts in an unexpected way. I was genuinely trying to help by showing a loop hole. The letters “live” are in that phrase

I am sorry that I am at fault here for my jokey response. It was not a criticism of your or your work. I have learnt a lot from you and really appreciate your input.

I am just really bad at communicating some days. Very sorry.

---

<div class="post-metadata">

**Author:** ![outsidecontext](https://community.metabrainz.org/user_avatar/community.metabrainz.org/outsidecontext/32/90_2.png) [@outsidecontext](https://community.metabrainz.org/u/outsidecontext)\
**Post date:** [April 23, 2022, 3:15pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/18 "2022-04-23T15:15:58Z")

</div>

This is all a bit odd. Have you been executing this script manually on the file (via context menu “Scripts…”)?

Because if you have this as a tagger script that runs automatically when the release is loaded this should not happen. And I also can’t reproduce any behavior like that. It would apply the script to the data loaded from MB. But of course if you execute this script manually on the files which already have been manipulated the disambiguation would be added every time you run the script.

---

<div class="post-metadata">

**Author:** ![ernstlx](https://community.metabrainz.org/user_avatar/community.metabrainz.org/ernstlx/32/27258_2.png) [@ernstlx](https://community.metabrainz.org/u/ernstlx)\
**Post date:** [April 23, 2022, 6:55pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/19 "2022-04-23T18:55:47Z")

</div>

> [@outsidecontext](#):
>
> But of course if you execute this script manually on the files which already have been manipulated the disambiguation would be added every time you run the script.

I suppose, that’s what has happened. 🙂

@xhiris ← Also, I assume you want the script to run automatically. Otherwise you would have to make sure to run the script again every time you reload the files into Picard.  
I tried to make the script usable for automatic execution on all releases:

```auto
$if($rsearch(%_recordingcomment%,^live[\,:]),
  $if($rsearch(%title%,%_recordingcomment%),,
    $set(title,$rreplace(%title%,\\s\\\(live.*\\\),) \(%_recordingcomment%\))
  )
)

```

Compared to the [above version](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/6) I used **$rsearch()** which accepts “regular expressions” to extend the search string by either _comma_ OR _colon_ (that’s what [\,:] means). To avoid regular expressions you could look for both variants and connect them with $or():

```auto
$or($startswith(%_recordingcomment%,live\,),$startswith(%_recordingcomment%,live:))

```

The script should make changes only in cases with additional information in \_recordingcomment, not if it’s only (live)  
That’s necessary because I remove track title disambiguation if it starts with “live”, and I’m trying to make sure there’s more information in \_recordingcomment than in the track title disambiguation which will be removed, e.g. “Title (live & unplugged version)” should not be replaced by “Title (live)”.

I remove the disambiguating comment from the title with **$rreplace** - regular expressions are unavoidable in this case - which cuts away something like **" (live at …)"** from the track title ← $rreplace(text,pattern,replace) where “replace” is empty. If “pattern” is not found in “text”, it remains unchanged.  
This happens inside the $set() function and the return value from $rreplace() is extended with " (%\_recordingcomment%)" and written to the title tag.

For @IvanDobsky I got an extended version including “demo”:

```auto
$if($or($rsearch(%_recordingcomment%,^live[\,:]),$rsearch(%_recordingcomment%,^demo[\,:])),
  $if($rsearch(%title%,%_recordingcomment%),,
    $set(title,$rreplace($rreplace(%title%,\\s\\\(live.*\\\),),\\s\\\(demo.*\\\),) \(%_recordingcomment%\))
  )
)

```

---

<div class="post-metadata">

**Author:** ![xhiris](https://community.metabrainz.org/letter_avatar_proxy/v4/letter/x/9e8a1a/32.png) [@xhiris](https://community.metabrainz.org/u/xhiris)\
**Post date:** [April 25, 2022, 5:17pm UTC](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950/20 "2022-04-25T17:17:11Z")

</div>

I’ve been getting some very strange results that I can’t reproduce consistently, or I’m missing something.

TL;DR I’ve been running most of these scripts automatically, but I’m not sure I understand when/how Picard updates the data. I expect it would only run when data gets loaded from MusicBrainz, and that only happens if you add stuff to the treeview on the right or hit “Refresh”.

In a few cases, when I’m running these scripts automatically, the duplicate (live …) stuff gets added not just when refreshing the album, but as I move from track to track in the treeview on the right. I’ve been trying to find steps to reproduce this consistently but I’m not having much luck.

Album title will be something like “Foo bar baz song (live at whatever stadium)” in the album node, and “Foo bar baz song (live at whatever stadium) (live at whatever stadium)” in the tracklist. If I click on another track then click back again (without refreshing or changing anything), it doubles up again “Foo bar baz song (live at whatever stadium) (live at whatever stadium) (live at whatever stadium) (live at whatever stadium)” and again each time I click a different track in the list. It doesn’t ever change the value in the “album” node, just the track.

Could this be a bug, or am I misunderstanding when the automatic scripts run? I’ve been messing with code in plugins, but I think I’ve reinstalled Picard after wiping out all my local files and settings and it’s happening on a fresh install.

[Next page](https://community.metabrainz.org/t/title-tagger-script-unexpectedly-repeating-values-why/581950.md?page=2)
