Mp3 Tag File

Nice work @Dasota, very handy script. I appreciate the share!

1 Like

@Duke999R It makes me happy to know that the script can help others make their audio files much better!

1 Like

Thank you so much for the All.js.txt. I have tested this file. That's nicely works with m4a and flac file. But One field doesn't works the copyright field. I have tried with m4a file and flac files.

You are absolutely right, the Copyrigth field did not have its respective assigned value, I had made that version of the script before your request and I forgot to include that information. Below I leave you the updated script, so try it and tell me if it works for you, hugs.

// Mp3 Tag File
// (c) 2024 DASOTA
// Script para Directory Opus.

var configName = "genero";

function OnInit(initData) {
    initData.name = "Mp3 Tag File";
    initData.version = "1.0";
    initData.copyright = "(c) 2024 DASOTA";
    initData.desc = "Mp3 Tag File";
    initData.default_enable = true;
    initData.min_version = "13.0";

    initData.config_desc = DOpus.Create.Map();

    initData.config_desc(configName) = "Modify musical genres";

    var gen_perso = DOpus.NewVector();

    gen_perso.push_back('A Cappella');
    gen_perso.push_back('Abstract');
    gen_perso.push_back('Acid');
    gen_perso.push_back('Acoustic');
    gen_perso.push_back('Alternative');
    gen_perso.push_back('Ambient');
    gen_perso.push_back('Anime');
    gen_perso.push_back('Ballad');
    gen_perso.push_back('Baroque');
    gen_perso.push_back('Blues');
    gen_perso.push_back('Breakbeat');
    gen_perso.push_back('Cabaret');
    gen_perso.push_back('Chorus');
    gen_perso.push_back('Christian');
    gen_perso.push_back('Classical');
    gen_perso.push_back('Comedy');
    gen_perso.push_back('Country');
    gen_perso.push_back('Cult');
    gen_perso.push_back('Dance');
    gen_perso.push_back('Disco');
    gen_perso.push_back('Dream');
    gen_perso.push_back('Electro');
    gen_perso.push_back('Electronic');
    gen_perso.push_back('Folklore');
    gen_perso.push_back('Freestyle');
    gen_perso.push_back('Funk');
    gen_perso.push_back('Fusion');
    gen_perso.push_back('Game');
    gen_perso.push_back('Gospel');
    gen_perso.push_back('Gothic');
    gen_perso.push_back('Grunge');
    gen_perso.push_back('Hard Rock');
    gen_perso.push_back('Hardcore');
    gen_perso.push_back('Heavy Metal');
    gen_perso.push_back('Hip-Hop');
    gen_perso.push_back('House');
    gen_perso.push_back('Humour');
    gen_perso.push_back('Industrial');
    gen_perso.push_back('Industro-Goth');
    gen_perso.push_back('Instrumental');
    gen_perso.push_back('Jazz');
    gen_perso.push_back('Latin');
    gen_perso.push_back('Meditative');
    gen_perso.push_back('Merengue');
    gen_perso.push_back('Metal');
    gen_perso.push_back('Musical');
    gen_perso.push_back('Noise');
    gen_perso.push_back('Oldies');
    gen_perso.push_back('Opera');
    gen_perso.push_back('Other');
    gen_perso.push_back('Podcast');
    gen_perso.push_back('Pop');
    gen_perso.push_back('Pranks');
    gen_perso.push_back('Primus');
    gen_perso.push_back('Punk');
    gen_perso.push_back('Rap');
    gen_perso.push_back('Reggae');
    gen_perso.push_back('Retro');
    gen_perso.push_back('Rock');
    gen_perso.push_back('Rock & Roll');
    gen_perso.push_back('Salsa');
    gen_perso.push_back('Samba');
    gen_perso.push_back('Sonata');
    gen_perso.push_back('Soul');
    gen_perso.push_back('Space');
    gen_perso.push_back('Tango');
    gen_perso.push_back('Techno');
    gen_perso.push_back('Trailer');
    gen_perso.push_back('Tribal');
    gen_perso.push_back('Vocal');

    initData.config[configName] = gen_perso;
}

function OnAddCommands(addCmdData) {
    var cmd = addCmdData.AddCommand();
    cmd.name = "Mp3TagFile";
    cmd.method = "OnMp3TagFile";
    cmd.desc = "";
    cmd.label = "Mp3 Tag File";
    cmd.template = "Mp3TagFile";
    cmd.hide = false;
    cmd.icon = "script";
}

function OnMp3TagFile(scriptCmdData) {
    var dlg = scriptCmdData.func.Dlg();
    dlg.title = "Mp3 Tag File - Directory Opus";
    dlg.template = 'Mp3TagFile';
    dlg.detach = true;
    dlg.Create

    var tab = scriptCmdData.func.sourcetab;
    var item = tab.selected_files(0);

    function cargar_valores() {
        dlg.Control("archivo").value = item.name;
        dlg.Control("titulo").value = item.metadata.audio.mp3title;
        dlg.Control("artista").value = item.metadata.audio.mp3artist;
        dlg.Control("album").value = item.metadata.audio.mp3album;
        dlg.Control("anio").value = item.metadata.audio.mp3year;
        dlg.Control("pista").value = item.metadata.audio.mp3track;

        dlg.Control("genero").label = item.metadata.audio.mp3genre;
        for (var i = 0; i < Script.config[configName].count; i++) {
            dlg.Control("genero").AddItem(Script.config[configName][i]);
        }

        dlg.Control("comentario").value = item.metadata.audio.mp3comment;
        dlg.Control("artista_album").value = item.metadata.audio.mp3albumartist;
        dlg.Control("compositor").value = item.metadata.audio.composers;
        dlg.Control("derechos").value = item.metadata.audio.copyright;
        dlg.Control("numero_disco").value = item.metadata.audio.mp3disc;

        if (item.metadata.audio.coverart > 0) {
            var tmpFile = DOpus.FSUtil().GetTempFile();
            tmpFile.Write(item.metadata.audio.coverart(0).data);
            tmpFile.Close();
            dlg.Control("caratula").label = Script.LoadImage(tmpFile);
        } else {
            dlg.Control("caratula").label = '';
        }

        dlg.Control("caratula").bg = "#FFFFFF";

        if (item.metadata.audio.coverart > 0) {
            var tmpFile = DOpus.FSUtil().GetTempFile();
            tmpFile.Write(item.metadata.audio.coverart(0).data);
            tmpFile.Close();
            var reso = item.metadata.audio.coverart(0);
            dlg.Control("resolucion").label = reso.width + " x " + reso.height + " x " + reso.depth + " (" + reso.size.fmt + ")";
        } else {
            dlg.Control("resolucion").label = '';
        }

        dlg.Control("resolucion").fg = "#000000";
        dlg.Control("resolucion").bg = "#FFFFFF";
    }

    cargar_valores();

    dlg.Show

    while (true) {
        msg = dlg.GetMsg();
        if (!msg.result) break;

        var cmd = scriptCmdData.func.command;
        var coverart_usuario;

        if (msg.event == "click") {
            switch (msg.control) {

                case "btn_anterior":

                    var items = tab.all;
                    if (items.count == 0) return;
                    var primer_item = items(0);
                    var ultimo_item = items(items.count - 1);

                    var compare = DOpus.FSUtil.ComparePath(tab.GetFocusItem(), primer_item);
                    if (compare == true) {
                        cmd.RunCommand("Select LAST");
                    } else {
                        cmd.RunCommand("Select PREV");
                        var item = tab.GetFocusItem;
                        cargar_valores();
                    }
                    break;

                case "btn_siguiente":

                    var items = tab.all;
                    if (items.count == 0) return;
                    var primer_item = items(0);
                    var ultimo_item = items(items.count - 1);

                    var compare = DOpus.FSUtil.ComparePath(tab.GetFocusItem(), ultimo_item);
                    if (compare == true) {
                        cmd.RunCommand("Select FIRST");
                    } else {
                        cmd.RunCommand("Select NEXT");
                        var item = tab.GetFocusItem;
                        cargar_valores();
                    }
                    break;

                case "btn_desde_archivo":

                    var name = dlg.Control("archivo").value;
                    var pista_name = name.replace(/(^[0-9]*)(.*)/, "$1");

                    var match = name.match(/(^[0-9\.\s]*)(.*)(\s-\s)(.*)/);
                    if (match) {
                        var title_name = name.replace(/(^[0-9\.\s]*)(.*)(\s-\s)(.*)/, "$2");
                        var artist_name = name.replace(/(^[0-9\.\s]*)(.*)(\s-\s)(.*)/, "$4");
                    } else {
                        var title_name = name.replace(/(^[0-9\.\s]*)(.*)/, "$2");
                        var artist_name = "";
                    }

                    var carpeta_superior = item.path.filepart;

                    dlg.Control("pista").value = pista_name;
                    dlg.Control("titulo").value = title_name;
                    dlg.Control("artista").value = artist_name;
                    dlg.Control("album").value = carpeta_superior;
                    break;

                case "btn_ayuda":

                    var dlg2 = DOpus.Dlg;
                    dlg2.window = dlg;
                    dlg2.title = "Help";
                    dlg2.icon = "info";
                    dlg2.message = "This option allows you to set the values of the track, title, artist and album fields from the file name.\n\nEXAMPLE\n\nFavorite ballads (folder)\n    01. Words - Bee Gees.mp3\n \nRESULT \n\nTrack:     01\nTitle:       Words\nArtist:     Bee Gees\nAlbum:   Favorite Ballads\n\nNote: This option will work even if the file name does not exactly match with the format ##. Title - Artist, applying only information that matches.";
                    dlg2.buttons = "OK";
                    dlg2.Show();
                    break;

                case "btn_anadir_caratula":
                    coverart_usuario = dlg.open("Carátula");
                    dlg.Control("caratula").label = Script.LoadImage(coverart_usuario);
                    break;

                case "btn_eliminar_caratula":
                    dlg.Control("caratula").label = '';
                    dlg.Control("resolucion").label = '';
                    var permitir = true;
                    break;

                case "btn_eliminar_todo":
                    dlg.Control("titulo").value = '';
                    dlg.Control("artista").value = '';
                    dlg.Control("album").value = '';
                    dlg.Control("anio").value = '';
                    dlg.Control("pista").value = '';
                    dlg.Control("genero").label = '';
                    dlg.Control("comentario").value = '';
                    dlg.Control("artista_album").value = '';
                    dlg.Control("compositor").value = '';
                    dlg.Control("derechos").value = '';
                    dlg.Control("numero_disco").value = '';
                    dlg.Control("caratula").label = '';
                    dlg.Control("resolucion").label = '';
                    break;

                case "btn_guardar":

                    var item = tab.GetFocusItem;
                    cmd.RunCommand('SetAttr' + ' FILE="' + item + '" META "title:' + dlg.Control("titulo").value + '"');
                    cmd.RunCommand('SetAttr' + ' FILE="' + item + '" META "artist:' + dlg.Control("artista").value + '"');
                    cmd.RunCommand('SetAttr' + ' FILE="' + item + '" META "album:' + dlg.Control("album").value + '"');
                    cmd.RunCommand('SetAttr' + ' FILE="' + item + '" META "year:' + dlg.Control("anio").value + '"');
                    cmd.RunCommand('SetAttr' + ' FILE="' + item + '" META "track:' + dlg.Control("pista").value + '"');
                    cmd.RunCommand('SetAttr' + ' FILE="' + item + '" META "genre:' + dlg.Control("genero").value.name + '"');
                    cmd.RunCommand('SetAttr' + ' FILE="' + item + '" META "comment:' + dlg.Control("comentario").value + '"');
                    cmd.RunCommand('SetAttr' + ' FILE="' + item + '" META "albumartist:' + dlg.Control("artista_album").value + '"');
                    cmd.RunCommand('SetAttr' + ' FILE="' + item + '" META "composers:' + dlg.Control("compositor").value + '"');
                    cmd.RunCommand('SetAttr' + ' FILE="' + item + '" META "copyright:' + dlg.Control("derechos").value + '"');
                    cmd.RunCommand('SetAttr' + ' FILE="' + item + '" META "discnumber:' + dlg.Control("numero_disco").value + '"');

                    if (coverart_usuario || permitir == true) {
                        cmd.RunCommand('SetAttr' + ' FILE="' + item + '" META "coverart:3:' + coverart_usuario + '"');
                    }
                    break;

                case "btn_cancelar":
                    dlg.EndDlg(0);
                    break;

            }
        }
        //DOpus.Output("Evento: " + msg.event + ",  Control: " + msg.control) //Ver eventos y controles que se que se activan, en el Registro de script
    }
}

==SCRIPT RESOURCES
<resources>
	<resource name="Mp3TagFile" type="dialog">
		<dialog fontsize="9" height="193" lang="esm" title="Mp3TagFile" width="332">
			<control halign="left" height="8" name="archivo_t" title="File:" type="static" valign="top" width="48" x="8" y="8" />
			<control halign="left" height="12" name="archivo" readonly="yes" type="edit" width="148" x="58" y="6" />
			<control halign="left" height="8" name="titulo_t" title="Title:" type="static" valign="top" width="48" x="8" y="23" />
			<control halign="left" height="12" name="titulo" type="edit" width="148" x="58" y="21" />
			<control halign="left" height="8" name="artista_t" title="Artist:" type="static" valign="top" width="48" x="8" y="38" />
			<control halign="left" height="12" name="artista" type="edit" width="148" x="58" y="36" />
			<control halign="left" height="8" name="album_t" title="Album:" type="static" valign="top" width="48" x="8" y="53" />
			<control halign="left" height="12" name="album" type="edit" width="148" x="58" y="51" />
			<control halign="left" height="8" name="anio_t" title="Year:" type="static" valign="top" width="48" x="8" y="68" />
			<control halign="left" height="12" name="anio" number="yes" type="edit" updown="yes" val_min="1" width="50" x="58" y="66" />
			<control halign="left" height="8" name="pista_t" title="Track:" type="static" valign="top" width="18" x="136" y="68" />
			<control halign="left" height="12" name="pista" number="yes" type="edit" updown="yes" val_min="1" width="30" x="157" y="66" />
			<control halign="left" height="8" name="genero_t" title="Genre:" type="static" valign="top" width="48" x="8" y="84" />
			<control edit="yes" height="40" name="genero" sort="yes" type="combo" width="148" x="58" y="82" />
			<control halign="left" height="8" name="comentario_t" title="Comment:" type="static" valign="top" width="48" x="8" y="99" />
			<control halign="left" height="12" name="comentario" type="edit" width="148" x="58" y="97" />
			<control halign="left" height="8" name="artista_album_t" title="Album artist:" type="static" valign="top" width="48" x="9" y="113" />
			<control halign="left" height="12" name="artista_album" type="edit" width="148" x="59" y="112" />
			<control halign="left" height="8" name="compositor_t" title="Composers:" type="static" valign="top" width="48" x="8" y="129" />
			<control halign="left" height="12" name="compositor" type="edit" width="148" x="58" y="127" />
			<control halign="left" height="8" name="derechos_t" title="Copyright:" type="static" valign="top" width="48" x="8" y="144" />
			<control halign="left" height="12" name="derechos" type="edit" updown="yes" val_min="1" width="148" x="58" y="142" />
			<control halign="left" height="8" name="numero_disco_t" title="Disc number:" type="static" valign="top" width="48" x="8" y="159" />
			<control halign="left" height="12" name="numero_disco" type="edit" updown="yes" val_min="1" width="148" x="58" y="157" />
			<control height="14" name="btn_desde_archivo" title="Track, title, artist and album from file" type="button" width="132" x="57" y="174" />
			<control height="14" name="btn_ayuda" title="?" type="button" width="14" x="192" y="174" />
			<control height="12" name="btn_anterior" title="&lt;" type="button" width="30" x="236" y="6" />
			<control height="12" name="btn_siguiente" title="&gt;" type="button" width="30" x="273" y="6" />
			<control height="122" name="caratula_t" title="Carátula" type="group" width="113" x="212" y="21" />
			<control halign="center" height="8" name="resolucion" type="static" valign="top" width="100" x="218" y="112" />
			<control halign="center" height="86" image="yes" name="caratula" type="static" valign="center" width="100" x="218" y="32" />
			<control height="14" name="btn_anadir_caratula" title="Add..." type="button" width="41" x="225" y="124" />
			<control height="14" name="btn_eliminar_caratula" title="Delete" type="button" width="41" x="271" y="124" />
			<control height="14" name="btn_eliminar_todo" title="Delete all" type="button" width="51" x="242" y="147" />
			<control default="yes" height="14" name="btn_guardar" title="Save" type="button" width="45" x="220" y="171" />
			<control height="14" name="btn_cancelar" title="Exit" type="button" width="45" x="271" y="171" />
		</dialog>
	</resource>
</resources>

Mp3 Tag File (All).js.txt (16.1 KB)

@Duke999R, If you are one of those who are interested in the script being able to modify other types of audio files and not just Mp3 ones, I have updated the Mp3 Tag File (All) script, since the Copyright field was not working.

1 Like

Thanks @dasota, that is the one I'm using.

1 Like

Hi Thanks a lot for updating the script. I have tested that with flac file and it's work with copyright field.

  1. When I press the button when I did not select any file, Then it's show script error. I think you can add a warning dialog box for that case 'Please Select your Music file first' as like that.
  2. When I tried to add the albumart with a flac file then it's show a error also