GP SoftwareTwitter
Opus FAQsManualCommandsObjects

How to write to mp3 tags with a Button


#21

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.");
}

#22

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


#23

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


#24

i tried the script button but it gives me an error

i have SelectEx script installed
an error occurred setting metadata

metadata parsing error


#25

What is the error?


#26

an error occurred setting metadata

metadata parsing error


#27

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)


#28

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:


#29

thank you very much everyone :heart_eyes:


#30

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)