Rename Audio file with an XML metadata info

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)

Could you help me??

Can be done with a rename script. Here's a demo. Probably needs a bit of fine-tuning to reliably pick the right lines.

// https://resource.dopus.com/t/rename-audio-file-with-an-xml-metadata-info/47799

var fsu = DOpus.FSUtil();
var stt = DOpus.Create().StringTools();

function OnGetNewName(getNewNameData) {
    if (getNewNameData.item.is_dir) return;

    var xmlPath = getNewNameData.item.realpath;
    xmlPath.ext = 'xml';
    if (!fsu.Exists(xmlPath)) return;

    var xmlItem = fsu.GetItem(xmlPath);
    var arr = stt.Decode(xmlItem.Open().Read(), 'utf8').split('\r\n');

    var tmpStem = arr[9] + ' - ' + arr[8];
    var tmpExt = getNewNameData.newname_ext;

    return tmpStem + tmpExt;
}

Save 47799.orp to   ↓

%appdata%\GPSoftware\Directory Opus\Rename Presets

How to use Rename Presets from this forum

1 Like

Deleted to avoid future confusion.

Thanks but i'll know nothing in the coding... i don,t know what i need to change

i don't know if i do something wrong... but they don't work

@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.

ok but it's change to a number... normally i need the Artist - Title... Field

Deleted to avoid future confusion.

they said.... Error at line 31, position 9
2024-01-04 3:16 PM Object doesn't support this property or method (0x800a01b6)

@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.

i don't have access to Opus 13!

@rfortin why is that? If you have a valid license for v12 (even if you're in trial period) you can try v13 for free.

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;
}

Rename From XML.orp (2.3 KB)

1 Like

There's a wonderful freeware

It's an universal tag editor, and I've used it to tag and consistently rename almost 50.000 audio files.

Another choice would be (also freeware)

Both apps are around for something like 15 years, well maintained and come with a huge supportive community.

Man you are a genuis!!! it work amazingly!!! Thank you so much for your help!
That's just crazy!!
Thanks