How to write to mp3 tags with a Button

This script button could work, you need the SelectEx script addin to be installed for the button to work in some way at all. Find it here: Command: SelectEx (extended Select command)

var doCommand = 'SetAttr META "contentgroup:Compilation Album"';

function OnClick(data){
	var cmd = data.func.command, srctab = data.func.sourcetab;
	var cmdTmp = DOpus.Create.Command();
	srctab.Vars.Set("SexRes") = "";
	for(var d=0;d<srctab.selected_dirs.count;d++) {
		var folderItem = srctab.selected_dirs(d);
		DOpus.Output("Scanning folder ["+folderItem.name+"]..");
		cmd.RunCommand(	'SelectEx LINEAR FILES NAME=".+\.mp3$" PATH="'+folderItem.realpath+'" '+
						'ITEMCOUNTPERC=100 RECURSE SETVAR="SexRes" ECHO');
		var strItems = srctab.Vars.Get("SexRes"); if (strItems=="") continue;
		var arrItems = strItems.split("\r\n"); 
		for(var i=0;i<arrItems.length;i++)
			cmdTmp.AddFile(arrItems[i]);
	}
	if (cmdTmp.filecount) cmdTmp.RunCommand(doCommand);
	DOpus.Output("Done.");
}
1 Like

Don’t you want the RunCommand outside the for loop?

Yes we do! Fixed it, thank you. o)

1 Like

i tried the script button but it gives me an error

i have SelectEx script installed
an error occurred setting metadata

metadata parsing error

What is the error?

an error occurred setting metadata

metadata parsing error

Sorry wobbly, I did this very quickly by copying and pasting together some older button parts aaand.. I had no mp3-file around for testing (being at work.. o).

I now managed to test it with actual mp3 files in some folders and it works. I've fixed the code above once more, so please re-copy&paste into your button and try again. o)

great that worked this time ... and iam happy you got it wrong now i can have a look and try and work out why the old one did not work :slight_smile:

thank you very much everyone :heart_eyes:

No, it's not worth looking into it! o) It was the call to .split("\n") causing issues, because I had changed the separator to be "\r\n" at some point in SelectEx. Sorry for the mess, could think of various ways to enhance this, but for now you probably have something to work with.

You could also just use DOs FSUtils.ReadDir() in recursive mode to get your items. Using SelectEx might not be the most straightforward attempt here. So in case you experience performance- or other kind of issues, you still have some options. o)

great it worked in the end like this SetAttr META "contentgroup:Studio Album";Christmas Album

so now the same album shows in Studio Album and in Christmas Album
[/quote]

is there a way to have a list a say ALBUM types eg Christmas 80's Rock and so on ...and them pick from a list
the album types you want to set you might want one or many thanks

say with a check box for options for album type(s) ?