Hi dear community
I want to update multiple selected flac files artisttracktitle from the file name. my example files name is:
Michael Jackson - 01 - just beat it.flac
Celine Dion - 02 - My Heart Will Go On.flac
Jennifer Lopez - 03 - Waiting For Tonight (Remix).flac
So the pattern is artist - track - title
I have found a code in this forum & customize that. the code is
@script jscript
function OnClick(data){
var files = data.func.sourcetab.selected_files;
var cmd = data.func.command; cmd.ClearFiles();
var re = new RegExp("(.*) - ([0-9]*) - (.*)(\.mp3|\.flac)");
for(var i=0;i<files.count;i++){
DOpus.Output("File: [" + files(i).name+"]");
var matches = String(files(i).name).match(re);
if (!matches){ DOpus.Output(" skipped"); continue; }
var artist = matches[1]; //var title = matches[2];
var cmdli = 'SetAttr META="artist:'+artist+'" FILE="'+files(i).realpath+'"';
DOpus.Output(" cmd: " + cmdli);
cmd.RunCommand(cmdli);
}
for(var i=0;i<files.count;i++){
DOpus.Output("File: [" + files(i).name+"]");
var matches = String(files(i).name).match(re);
if (!matches){ DOpus.Output(" skipped"); continue; }
var track = matches[2];
var cmdli = 'SetAttr META="track:'+track+'" FILE="'+files(i).realpath+'"';
DOpus.Output(" cmd: " + cmdli);
cmd.RunCommand(cmdli);
}
for(var i=0;i<files.count;i++){
DOpus.Output("File: [" + files(i).name+"]");
var matches = String(files(i).name).match(re);
if (!matches){ DOpus.Output(" skipped"); continue; }
var title = matches[3];
var cmdli = 'SetAttr META="title:'+title+'" FILE="'+files(i).realpath+'"';
DOpus.Output(" cmd: " + cmdli);
cmd.RunCommand(cmdli);
}
}
The code works fine, but I have repeat the for loop three time for updating the three ( artisttracktitle) field. Is it Ok or is there any easy way to write the field updater command in a single loop?
Hi dear Sasa thanks for your nice comment. The Original codes I found that's cancommand was adds only the track no. I have been add other two fields ( artisttitle ) this code in JavaScript, I just peak the Regex from your code. Now Please tell me is that there any way to combined them in a single Loop?
No, it adds ALL - artist, title and number - tags from filename as you could also see in my screenshot posted today after you asked me to check the command.
By the way, the title of the song is "Beat It", not "Just Beat It". (He does sing "just beat it" in the song, but the title is only two of those words.)
ok thanks everyone for commenting. Here is what I want:
function OnClick(data){
var files = data.func.sourcetab.selected_files;
var cmd = data.func.command; cmd.ClearFiles();
var re = new RegExp("(.*) - ([0-9]*) - (.*)(\.mp3|\.flac)");
for(var i=0;i<files.count;i++){
// DOpus.Output("File: [" + files(i).name+"]");
var matches = String(files(i).name).match(re);
// if (!matches){ DOpus.Output(" skipped"); continue; }
var artist = matches[1];
var track = matches[2];
var title = matches[3];
var cmdli = 'SetAttr META="artist:'+artist+'" "track:'+track+'" "title:'+title+'" FILE="'+files(i).realpath+'"';
//DOpus.Output(" cmd: " + cmdli);
cmd.RunCommand(cmdli);
}
}
need a little more help!
after the tagging part done, I want to rename the filenames also with var title = matches[3]; what I mean
Michael Jackson - 01 - Beat it.flac
should be Beat it.flac
Celine Dion - 02 - My Heart Will Go On.flac
should be My Heart Will Go On.flac
Jennifer Lopez - 03 - Waiting For Tonight (Remix).flac
should be Waiting For Tonight (Remix).flac
for that should I start a new function like function OnGetNewName(getNewNameData)
or is there any way to rename those selected files in the same function function OnClick(data)
Compare your FILES argument in the SetAttr and Rename commands. You are passing files(i) (just one file) to one and files (a list of files) to the other.
If you want to pay a consultancy fee I'm sure someone will write all the custom things you want every day. I have too much work to do to help more, sorry.