Hello guys...
i need help... i have a bunch of 36000 audios file and i would like to rename it with the Metadata... each audio file as the same file in XML.... EX: M000001_HEAVEN KNOWS.WAV / M000001_HEAVEN KNOWS.xml
Here's the info i have in the XML...
<items xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cmifunc="http://www.cogecomedia.com">
<item>
<Year>1978</Year>
<ISRC> </ISRC>
<CanCon>0</CanCon>
<itemcode>M000001</itemcode>
<categorycode/>
<fullpath>CATEGORIES/LIBRAIRIE MUSICALE CDI/MUSIQUE CMI 1</fullpath>
<title>HEAVEN KNOWS</title>
<artist>DONNA SUMMER,BROOKLYN DREAMS</artist>
<comment1/>
<comment2/>
<comment3/>
<author/>
<album>LIVE AND MORE</album>
<label/>
<!-- In ms; Offset from 0 duration -->
<intro>18058</intro>
<!-- In ms; Offset from 0 duration -->
<startmarker>0</startmarker>
<!-- In ms; Offset from 0 duration -->
<endmarker>193184</endmarker>
<!-- In ms; Fade in duration -->
<fadein>0</fadein>
<!-- In ms; Fade out duration -->
<fadeout>0</fadeout>
<!-- In ms; Mixpoint offset from outmarker; Negative = overlap -->
<crossfade>-2571</crossfade>
<!-- In ms; Total duration of the item -->
<duration>193184</duration>
<hiqfile>\\mlvpwdas-a01\STORAGE\Musique_6\003411DE.WAV</hiqfile>
<loqfile/>
</item>
</items>
What i want... is to rename my audio file (Artist - Title.wav)
@rfortin you have to download this, and copy to %appdata%\GPSoftware\Directory Opus\Rename Presets.
You don't need to know how to code (it's already done), but you must read this to understand how to use rename presets.
After doing that, select some files you want to rename as a test. Then type: > followed by Rename ADVANCED PRESET=rename_xml and press Return.
In the Advanced Rename dialog, click on Edit Script button, you will see some information on the bottom right side. You can deduce from that why it doesn't work.
@rfortin that's because you're using DO 12. You can give a try to DO13.
Or change that line to: title = artist.text + " - " + title.text;
But be careful, if artist or title have any characters like \, ?, " or any other invalid character for a filename, you may get unexpected results.
Anyway, I have updated the script above to work on DO 12 and DO 13. I hope it helps you and others.
var xmlFile = new ActiveXObject("Msxml2.DOMDocument");
var FSU = DOpus.FSUtil();
var valid_exts = /^\.(wav|mp3|flac)$/i; //change extensions to your like
function OnGetNewName(getNewNameData) {
var item = getNewNameData.item;
if (!valid_exts.test(item.ext)) {
DOpus.Output(item + " is not a valid file extension!!!");
return true;
}
var xmlPath = item.realpath;
xmlPath.ext = 'xml';
if (!FSU.Exists(xmlPath)) { //no xml for this file
DOpus.Output(xmlPath + " doesn't exists!!!");
return true;
}
xmlFile.load(String(xmlPath));
if (xmlFile.parseError.errorCode != 0) { //error while trying to read xml
DOpus.Output(xmlPath + " can't be readed!!!");
return true;
}
var artist = xmlFile.selectSingleNode("//items/item/artist");
var title = xmlFile.selectSingleNode("//items/item/title");
if (!artist || !title) {
DOpus.Output(xmlPath + " has missing tags!!!");
return true;
}
title = makeSafeFilename(artist.text + " - " + title.text);
DOpus.Output("Item : " + item.name + "\t; New title : " + title + item.ext);
return title + item.ext;
}
function makeSafeFilename(input) {
var replacements = {
'\\': '_',
'/': '_',
':': ';',
'*': '#',
'?': '!',
'"': '\'',
'<': '(',
'>': ')',
'|': '-'
};
var safeFilename = input.replace(/[\\\/:\*\?"<>\|]/g, function(match) {
return replacements[match];
});
return safeFilename;
}