Bookmarklet for bulk-editing track titles

Just in case it’s useful to other editors, I’ve been using this bookmarklet to bulk-edit track titles from the tracklist tab in the release editor, usually when I need to fix a bunch of ETI:

javascript:(()=>{const t=document.querySelectorAll("input.track-name");if(!t.length){alert("No track inputs found");return}const n=prompt("Track title regexp");if(n===null)return;const r=prompt("Replacement");if(r===null)return;const c=new RegExp(n);for(const e of[...t]){const o=e.value.replace(c,r);o!==e.value&&(e.value=o,e.dispatchEvent(new Event("change")))}})();

(Non-minified version is at https://codeberg.org/derat/mb-bookmarklets/src/branch/main/rename_tracks.js.)

It prompts for a regular expression to search for in each track title and then for a replacement pattern.

It can be handy for correcting non-parenthesized ETI. For this edit, I entered - ([^-]+)$ in the first prompt (to match space-dash-space-ETI at the ends of titles, capturing the ETI part) and ($1) in the second prompt (to replace with a space and then the original ETI in parentheses).

I’ve also used it to quickly remove repetitive ETI from the ends of track titles in live releases. For this edit, I entered - Live 1995$ in the first prompt (to match that string at the ends of titles) and then left the second prompt blank (to replace with nothing).

7 Likes

Hah, I’ve been doing something similar, but using the track parser and Notepad++ to mass fix titles with bad ETI (particularly from spotify)
Lately though the track parser isn’t splitting artists correctly, and I don’t know if it’s something i’m doing or if it’s a MB bug. I’ll be checking out your script and try and learn how to write my own version as well :smiley:

2 Likes

Nice!
For info, for SUPER TURBO userscript users, its TRACKLIST_TOOLSSearch→replace button also supports regular expressions and replacement groups. But only for track titles, not for artist credits (which could be cool).

1 Like

I’ve been using this a ton for years on live & Spotify ETI for years. Is there a way to also have this for the artist join fields? That’d be awesome addition for search & replace.

That’s a good idea – I see a lot of “Artist 1, Artist 2” track credits on imported releases that ought to be “Artist 1 & Artist 2” or “Artist 1 feat. Artist 2”. One challenge would be determining what to do when there are more than two artists credited (and hence more than one join phrase). Updating them all probably usually isn’t what’s desired. Just update the final one, maybe? That wouldn’t work for switching “Artist 1, Artist 2, Artist 3” to “Artist 1 & Artist 2 feat. Artist 3”, though.

I took a shot at writing another bookmarklet to update join phrases in the tracklist editor:

javascript:(()=>{const n=document.querySelectorAll("tr.track .artist-credit-editor button.open-ac");if(!n.length){alert("No artist credit buttons found");return}let e=prompt("Join phrase regexp (blank matches all)");if(e===null)return;e!==""&&(e=new RegExp(e));const o=prompt("Replacement");if(o===null)return;let t=prompt("Join phrase position (blank for all, 0 for first, 1 for second, -1 for last, etc.)");if(t===null)return;t!==""&&(t=parseInt(t));const u=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,"value").set,a=new RegExp("^ac-.+-join-phrase-\\d+$"),i=l=>{n[l].click(),window.setTimeout(()=>{const c=[...document.querySelectorAll("#artist-credit-bubble input")].filter(r=>r.id?.match(a)).slice(0,-1);c.forEach((r,s)=>{t!==""&&(t>=0&&s!==t||t<0&&s-c.length!==t)||(e===""||r.value.match(e))&&(u.call(r,e===""?o:r.value.replace(e,o)),r.dispatchEvent(new Event("input",{bubbles:!0})))}),document.querySelector("#artist-credit-bubble .buttons .positive").click(),l<n.length-1&&i(l+1)})};i(0)})();

It’s more complicated (and fragile) since it needs to open each credit bubble sequentially. The non-minified version is at https://codeberg.org/derat/mb-bookmarklets/src/branch/main/edit_join_phrases.js.

To lowercase the join phrases in Edit #119506902 - MusicBrainz, I entered " Feat\. " in the first prompt, " feat. " in the second, and left the third blank. Then I did the same thing with " Vs\. " and " vs. ".

To just replace the final commas with ampersands for Edit #119506712 - MusicBrainz, I entered ", " in the first prompt, " & " in the second, and “-1” in the third.

5 Likes