Find & replace composers & artist metadata in FLAC files?

While discussing you could have done all just using free and portable MP3tag.

I also like solving everything with DO, but sometimes there are better and quicker solutions instead wasting hours in scripting for a "oneshot-solution".

if oneshot-solution works for life time then I don't think it's wasting time by the way. I like this oneshot-solution also. when the DOpus has full ability for done this job then why not a user expect a oneshot-solution like that. but I am sorry I have no ability write a script for this new user. But I believe this forum has lots of person who can write a script for this new users even leo can also help this new user I think.

Happy find-and-replace :slight_smile:

2023-07-06 - 13.49.23

// https://resource.dopus.com/t/how-to-find-and-replace-in-composers-and-artist-column-meta-data-in-selected-flac-files/41265/23

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;
    var dlg = clickData.func.Dlg();
    cmd.deselect = false; // Prevent automatic deselection

    if (tab.selected_files.count == 0) return;

    dlg.template = 'Advanced Find and Replace';
    dlg.Show();
    
    if (!dlg.result) return;
    
    var keyword = dlg.Control('keyword').value.name;
    var findWhat = dlg.Control('findWhat').value;
    var replaceWith = dlg.Control('replaceWith').value;
    
    if (findWhat == '') return;
    
    for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {
        var item = e.item();
        if (item.metadata == 'none') continue;
        var itemKey = item.metadata.audio[keyword];
        if (typeof itemKey != 'string') continue;
        var cmdLine = 'SetAttr' +
        ' FILE="' + item + '"' +
        ' META' +
        ' "' + keyword.replace('mp3', '') + ':' + itemKey.replace(new RegExp(findWhat, 'g'), replaceWith) + '"';
        
        DOpus.Output(cmdLine);
        cmd.RunCommand(cmdLine);
    }
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>41265</label>
	<tip>how-to-find-and-replace-in-composers-and-artist-column-meta-data-in-selected-flac-files</tip>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>// https://resource.dopus.com/t/how-to-find-and-replace-in-composers-and-artist-column-meta-data-in-selected-flac-files/41265/23</instruction>
		<instruction />
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var cmd = clickData.func.command;</instruction>
		<instruction>    var tab = clickData.func.sourcetab;</instruction>
		<instruction>    var dlg = clickData.func.Dlg();</instruction>
		<instruction>    cmd.deselect = false; // Prevent automatic deselection</instruction>
		<instruction />
		<instruction>    if (tab.selected_files.count == 0) return;</instruction>
		<instruction />
		<instruction>    dlg.template = &apos;Advanced Find and Replace&apos;;</instruction>
		<instruction>    dlg.Show();</instruction>
		<instruction>    </instruction>
		<instruction>    if (!dlg.result) return;</instruction>
		<instruction>    </instruction>
		<instruction>    var keyword = dlg.Control(&apos;keyword&apos;).value.name;</instruction>
		<instruction>    var findWhat = dlg.Control(&apos;findWhat&apos;).value;</instruction>
		<instruction>    var replaceWith = dlg.Control(&apos;replaceWith&apos;).value;</instruction>
		<instruction>    </instruction>
		<instruction>    if (findWhat == &apos;&apos;) return;</instruction>
		<instruction>    </instruction>
		<instruction>    for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {</instruction>
		<instruction>        var item = e.item();</instruction>
		<instruction>        if (item.metadata == &apos;none&apos;) continue;</instruction>
		<instruction>        var itemKey = item.metadata.audio[keyword];</instruction>
		<instruction>        if (typeof itemKey != &apos;string&apos;) continue;</instruction>
		<instruction>        var cmdLine = &apos;SetAttr&apos; +</instruction>
		<instruction>        &apos; FILE=&quot;&apos; + item + &apos;&quot;&apos; +</instruction>
		<instruction>        &apos; META&apos; +</instruction>
		<instruction>        &apos; &quot;&apos; + keyword.replace(&apos;mp3&apos;, &apos;&apos;) + &apos;:&apos; + itemKey.replace(new RegExp(findWhat, &apos;g&apos;), replaceWith) + &apos;&quot;&apos;;</instruction>
		<instruction>        </instruction>
		<instruction>        DOpus.Output(cmdLine);</instruction>
		<instruction>        cmd.RunCommand(cmdLine);</instruction>
		<instruction>    }</instruction>
		<instruction>}</instruction>
		<instruction>==SCRIPT RESOURCES</instruction>
		<instruction>&lt;resources&gt;</instruction>
		<instruction>	&lt;resource name=&quot;Advanced Find and Replace&quot; type=&quot;dialog&quot;&gt;</instruction>
		<instruction>		&lt;dialog fontsize=&quot;8&quot; height=&quot;100&quot; lang=&quot;english&quot; resize=&quot;yes&quot; standard_buttons=&quot;ok,cancel&quot; title=&quot;Advanced Find and Replace&quot; width=&quot;160&quot;&gt;</instruction>
		<instruction>			&lt;control height=&quot;40&quot; name=&quot;keyword&quot; type=&quot;combo&quot; width=&quot;130&quot; x=&quot;12&quot; y=&quot;11&quot;&gt;</instruction>
		<instruction>				&lt;contents&gt;</instruction>
		<instruction>					&lt;item text=&quot;mp3artist&quot; /&gt;</instruction>
		<instruction>					&lt;item text=&quot;mp3album&quot; /&gt;</instruction>
		<instruction>					&lt;item text=&quot;mp3albumartist&quot; /&gt;</instruction>
		<instruction>					&lt;item text=&quot;mp3genre&quot; /&gt;</instruction>
		<instruction>					&lt;item text=&quot;composers&quot; /&gt;</instruction>
		<instruction>					&lt;item text=&quot;publisher&quot; /&gt;</instruction>
		<instruction>				&lt;/contents&gt;</instruction>
		<instruction>			&lt;/control&gt;</instruction>
		<instruction>			&lt;control halign=&quot;left&quot; height=&quot;12&quot; name=&quot;findWhat&quot; title=&quot;Find what&quot; type=&quot;edit&quot; width=&quot;130&quot; x=&quot;12&quot; y=&quot;35&quot; /&gt;</instruction>
		<instruction>			&lt;control halign=&quot;left&quot; height=&quot;12&quot; name=&quot;replaceWith&quot; title=&quot;Replace with&quot; type=&quot;edit&quot; width=&quot;130&quot; x=&quot;12&quot; y=&quot;59&quot; /&gt;</instruction>
		<instruction>		&lt;/dialog&gt;</instruction>
		<instruction>	&lt;/resource&gt;</instruction>
		<instruction>&lt;/resources&gt;</instruction>
	</function>
</button>
2 Likes

Thank you lxp!
I looked at the script, and it seems one can use any SetAttr Keywords. is that correct?

Currently, only the six you'll find in the dropdown list, but you can edit the dialog in the button's "Resources" tab and add/remove keywords. However, they need to be from the audio category. Disappointing, I know!

in my search this is the one and only script which can search and replace in metadata instead of file name only. So I can called the best script I have been ever found in this forum. in my case this script have been completely replace a software in my setup. because this script gives the ability to Dopus which can replace the software. I have no language for thanks the grate lxp

khalihosain, I'm glad that works so well for you. lxp is so helpful!
I work mostly with photos, and I depend on Photo Mechanic (by Camera Bits) for Find & Replace.


It has any option I could ever want for photo metadata.
I used to use Photo Mechanic for many tasks, but have figured out how to do most of those tasks with DOpus - except Find & Replace for anything but filenames and folder names.

is there any way to displayArtist instead of mp3artist
as I marked in this photo
image

Yes. Just not very easily. Same reason why adding fields that are not from the audio category is not possible with the current version.

1 Like

It's OK not a big deal. I hope this will can be done easily if the developer of DOpus want in future update.

This script support regular expression. But every time I don't need to use the regular expression I need Just Normal Find and replace. Could you please help with little bit of modification of this script. where may be a check box will be appear for regular expression active or not.
image
I mean If user check that box then regular expression will works if uncheck that box then regular expression will not works

There is no big difference. You just need to escape a few JScript characters. Do you really have so many in your mp3 metadata?

To remove regex, clone your button and replace

new RegExp(findWhat, 'g')

with

findWhat

I leave it to somebody else to insert a checkbox and merge the two scripts :slight_smile:

1 Like

Yes My dear lxp. you don't know this script just save my soul really. I have no language to thank you. This is the best useable script for me I get from this forum.

Yes I just follow your instruction and clone the button and replace the code as you say. the clone button works fine for me. Thank you once again. Now I have 2 button which is fine for me. But I have a request to all who able to modified this script if you have time then please modify the script with the check box option for regular expression ON or OFF. here is the resource you can use for start.

<resources>
	<resource name="Find and Replace Music Metadata" type="dialog">
		<dialog fontsize="10" height="140" lang="english" resize="yes" standard_buttons="ok,cancel" title="Find &amp; Replace in Music Metadata" width="168">
			<control height="40" name="keyword" type="combo" width="133" x="14" y="21">
				<contents>
					<item text="mp3artist" />
					<item text="mp3album" />
					<item text="mp3albumartist" />
					<item text="mp3genre" />
					<item text="composers" />
					<item text="copyright" />
					<item text="Publisher" />
					<item text="mp3year" />
				</contents>
			</control>
			<control halign="left" height="12" name="findWhat" tip="find what" type="edit" width="133" x="14" y="70" />
			<control halign="left" height="12" name="replaceWith" tip="Replace with" type="edit" width="133" x="14" y="98" />
			<control halign="left" height="12" name="static1" title="Find Where [Select Metadata field]" type="static" valign="top" width="133" x="14" y="7" />
			<control halign="left" height="12" name="static2" title="Find What" type="static" valign="top" width="105" x="14" y="56" />
			<control halign="left" height="12" name="static3" title="Replace with" type="static" valign="top" width="126" x="14" y="84" />
			<control height="10" name="Regular expression" title="Regular expression" type="check" width="84" x="14" y="42" />
		</dialog>
	</resource>
</resources>