The following code allows you to set the metadata: track, title and artist from the file name in format: ##. Title - Artist
When I select a single file everything works fine; but when I select several files, the data from the first file is applied to all the other files, could you help me so that each file receives its own data?
function OnClick(clickData) {
var cmd = clickData.func.command;
var tab = clickData.func.sourcetab;
cmd.deselect = false;
if (!tab.selected_files) return;
var item = tab.selected_files(0);
var name = item.name_stem;
var name_track = name.replace(/(^[0-9]*)(.*)/, "$1");
var name_title = name.replace(/(^[0-9\.\s]*)(.*)(\s-\s)(.*)/, "$2");
var name_artist = name.replace(/(^[0-9\.\s]*)(.*)(\s-\s)(.*)/, "$4");
if (tab.selected_files.count >= 2) {
cmd.RunCommand('SetAttr META="track:' + name_track + '"');
cmd.RunCommand('SetAttr META="title:' + name_title + '"');
cmd.RunCommand('SetAttr META="artist:' + name_artist + '"');
} else {
cmd.RunCommand('SetAttr' +
' FILE="' + item + '"' +
' META "track:{dlgstring|Pista:|' + name_track + '}"');
cmd.RunCommand('SetAttr' +
' FILE="' + item + '"' +
' META "title:{dlgstring|Título:|' + name_title + '}"');
cmd.RunCommand('SetAttr' +
' FILE="' + item + '"' +
' META "artist:{dlgstring|Artista:|' + name_artist + '}"');
}
}
Correct, but the ideal would be that when several files are selected none of the windows are shown, that is, the metadata is established directly, showing the windows only when a single file is selected