Mp3 Tag File (Built)

I made those modifications, but it still gives the same error

var archivo = dlg.Control("archivo").value;
var titulo = dlg.Control("titulo").value;
var artista = dlg.Control("artista").value;
var album = dlg.Control("album").value;
var anio = dlg.Control("anio").value;
var pista = dlg.Control("pista").value;
var genero = dlg.Control("genero").value;
var comentario = dlg.Control("comentario").value;
var artista_album = dlg.Control("artista_album").value;
var compositor = dlg.Control("compositor").value;
var numero_disco = dlg.Control("numero_disco").value;
var caratula = dlg.Control("caratula").value;

Then you probably put the code in the wrong place. Hard to tell from here :wink:

The most likely thing will be that, what a difficult situation for me, wanting to do something and not knowing :smile:

As you told me, I was placing the code out of place, outside the function. Let me ask you another question, the last one, I promise :smile:

Now I inserted those lines:

titulo.value = item.metadata.audio.mp3title;
artista.value = item.metadata.audio.mp3artist;
album.value = item.metadata.audio.mp3album;
anio.value = item.metadata.audio.mp3year;
pista.value = item.metadata.audio.mp3track;
genero.value = item.metadata.audio.mp3genre;
comentario.value = item.metadata.audio.mp3comment;
artista_album.value = item.metadata.audio.mp3albumartist;
compositor.value = item.metadata.audio.mp3composer;
numero_disco.value = item.metadata.audio.mp3disc;
caratula.value = item.metadata.audio.mp3coverart;

And it tells me that item is not defined, I tried var item =

item.name
item.name_stem
item.ext
item.realpath
item.path

and nothing works, how could I define that variable?

You could use the first selected file:

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

That's exactly what I want, I'm going to try, big hug!

How could I obtain the resolution, depth and size of an cover mp3? I have tried this, but no success.


var cover = item.metadata.audio.coverart(0);
var full = cover.width + " x " + cover.height +  " x " + cover.depth + " (" + cover.size   + ")";

is it a new one after last?))))

It's the same, only I've changed it so much that it looks different.

I have created a static control as image (image="yes") to display the file cover:

<control halign="center" height="86" image="yes" name="caratula" title="Carátula" type="static" valign="center" width="100" x="218" y="15" />

I declared its value to the cover variable:

var caratula = dlg.Control("caratula");

And I assigned it as a value:

caratula.value = item.metadata.audio.coverart;

Even so, the cover is not shown, what is missing, where is the error? Thank you

With a lot of work, but little by little the script is taking shape, now I just need to capture the cover and make the buttons work, if someone could help me with that I would appreciate it so much!

02

// Mp3 Tag File
// (c) 2024 DASOTA

// Script para Directory Opus.

// Iniciar el script
function OnInit(initData)
{
	initData.name = "Mp3 Tag File";
	initData.version = "1.0";
	initData.copyright = "(c) 2024 DASOTA";
	initData.desc = "Editor Mp3 Tag de archivo único";
	initData.default_enable = true;
	initData.min_version = "13.0";
}

// Añadir comando
function OnAddCommands(addCmdData)
{
	var cmd = addCmdData.AddCommand();
	cmd.name = "Mp3TagFile";
	cmd.method = "OnMp3TagFile";
	cmd.desc = "";
	cmd.label = "Mp3 Tag File";
	cmd.template = "Mp3TagFile"; //Nombre del objeto Diálogo (pestaña Recursos)
	cmd.hide = false;
	cmd.icon = "script";
}

// Implementar el comando Mp3TagFile
function OnMp3TagFile(scriptCmdData) {
    var dlg = scriptCmdData.func.Dlg();
    dlg.title = "Mp3 Tag File - Directory Opus"; //Nombre de la barra de Título
    dlg.template = 'Mp3TagFile';
	dlg.detach = true;
	dlg.Create //Crear el diálogo
		
	//Definir la variable item
	var tab = scriptCmdData.func.sourcetab;
	var item = tab.selected_files(0); //item = Al primer archivo seleccionado (0); si fuera (1) sería el segundo

	// Asignarle los valores a los controles
	dlg.Control("archivo").value = item.name_stem; //Nombre de archivo sin extensión
	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").value = item.metadata.audio.mp3genre;
	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("numero_disco").value = item.metadata.audio.mp3disc;

	//Carátula
	dlg.Control("caratula").label.value = item.metadata.audio.coverart; //Contenido
	dlg.Control("caratula").bg = "#FFFFFF"; //Fondo (blanco)

	//Resolución	
	dlg.Control("resolucion").label = item.metadata.audio.coverart.picsize; //Etiqueta
	dlg.Control("resolucion").fg = "#000000"; //Texto (negro)	
	dlg.Control("resolucion").bg = "#FFFFFF"; //Fondo (blanco)

	dlg.Show //Mostrar el diálogo

	while (true) { //Mientras verdadero
		msg = dlg.GetMsg(); //Mostrar el diálogo
		if (!msg.result) break; //Cuando falso, cerrar el diálogo

	//Establecer los eventos
	if (msg.event == "click") { //Eventos del tipo clic 
		switch (msg.control) {
			case "btn_guardar": Mp3TagFile(dlg); // Guardar los cambios aL presionar el botón "btn_guardar'
				break;
		}
    }




  }
}
==SCRIPT RESOURCES
<resources>
	<resource name="Mp3TagFile" type="dialog">
		<dialog fontsize="9" height="180" lang="esm" title="Mp3TagFile" width="332">
			<control halign="left" height="8" name="archivo_t" title="Archivo:" type="static" valign="top" width="48" x="8" y="10" />
			<control halign="left" height="12" name="archivo" readonly="yes" type="edit" width="148" x="58" y="8" />
			<control halign="left" height="8" name="titulo_t" title="Título:" type="static" valign="top" width="48" x="8" y="26" />
			<control halign="left" height="12" name="titulo" type="edit" width="148" x="58" y="25" />
			<control halign="left" height="8" name="artista_t" title="Artista:" type="static" valign="top" width="48" x="8" y="43" />
			<control halign="left" height="12" name="artista" type="edit" width="148" x="58" y="42" />
			<control halign="left" height="8" name="album_t" title="Álbum:" type="static" valign="top" width="48" x="8" y="60" />
			<control halign="left" height="12" name="album" type="edit" width="148" x="58" y="59" />
			<control halign="left" height="8" name="anio_t" title="Año:" type="static" valign="top" width="48" x="8" y="78" />
			<control halign="center" height="12" name="anio" number="yes" type="edit" updown="yes" val_min="1" width="50" x="58" y="76" />
			<control halign="left" height="8" name="pista_t" title="Pista:" type="static" valign="top" width="18" x="136" y="78" />
			<control halign="center" height="12" name="pista" number="yes" type="edit" updown="yes" val_min="1" width="30" x="157" y="76" />
			<control halign="left" height="8" name="genero_t" title="Género:" type="static" valign="top" width="48" x="8" y="94" />
			<control edit="yes" height="40" name="genero" sort="yes" type="combo" width="148" x="58" y="93">
				<contents>
					<item text="Romántico" />
					<item text="Balada" />
					<item text="Bolero" />
					<item text="Trova" />
					<item text="Patrio" />
					<item text="Son" />
					<item text="Salsa" />
					<item text="Guaracha" />
					<item text="Montuno" />
					<item text="Cumbia" />
					<item text="Merengue" />
					<item text="Tropical" />
					<item text="Ranchera" />
					<item text="Reggae" />
					<item text="Reggaetón" />
					<item text="Hip Hop" />
					<item text="Pop" />
					<item text="Rock" />
					<item text="Tecno" />
					<item text="Electrónico" />
					<item text="Jazz" />
					<item text="Infantil" />
					<item text="Religioso" />
					<item text="Instrumental" />
					<item text="Vocal" />
					<item text="Efecto sonoro" />
					<item text="Inglés" />
					<item text="Bossa Nova" />
					<item text="Tropicália" />
					<item text="Samba" />
					<item text="Pagode" />
					<item text="Lambada" />
					<item text="MPB" />
					<item text="Forró" />
					<item text="Sertanejo" />
					<item text="Sertanejo universitário" />
					<item text="Axé" />
					<item text="Funk" />
					<item text="Gospel" />
					<item text="Brega" />
					<item text="Choro" />
					<item text="Frevo" />
					<item text="Baião" />
					<item text="Piseiro" />
					<item text="Pisadinha" />
				</contents>
			</control>
			<control halign="left" height="8" name="comentario_t" title="Comentario:" type="static" valign="top" width="48" x="8" y="111" />
			<control halign="left" height="12" name="comentario" type="edit" width="148" x="58" y="110" />
			<control halign="left" height="8" name="artista_album_t" title="Artista álbum:" type="static" valign="top" width="48" x="9" y="128" />
			<control halign="left" height="12" name="artista_album" type="edit" width="148" x="59" y="127" />
			<control halign="left" height="8" name="compositor_t" title="Compositor:" type="static" valign="top" width="48" x="8" y="145" />
			<control halign="left" height="12" name="compositor" type="edit" width="148" x="58" y="144" />
			<control halign="left" height="8" name="numero_disco_t" title="Número disco:" type="static" valign="top" width="48" x="8" y="162" />
			<control halign="left" height="12" name="numero_disco" type="edit" updown="yes" val_min="1" width="148" x="58" y="161" />
			<control halign="center" height="8" name="resolucion" type="static" valign="top" width="100" x="218" y="95" />
			<control height="122" name="caratula_t" title="Carátula" type="group" width="113" x="212" y="4" />
			<control halign="center" height="86" image="yes" name="caratula" type="static" valign="center" width="100" x="218" y="15" />
			<control height="14" name="btn_añadir_caratula" title="Añadir..." type="button" width="41" x="224" y="107" />
			<control height="14" name="btn_eliminar_caratula" title="Eliminar" type="button" width="41" x="272" y="107" />
			<control height="15" name="btn_eliminar_todo" title="Eliminar todo" type="button" width="76" x="229" y="135" />
			<control default="yes" height="15" name="btn_guardar" title="Guardar" type="button" width="76" x="229" y="155" />
		</dialog>
	</resource>
</resources>

Mp3 Tag File.js.txt (7.6 KB)

Getting the coverart into the dialog is a bit tricky.

Replace

dlg.Control("caratula").label.value = item.metadata.audio.coverart; //Contenido

with

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 = '';
}
1 Like

@dasota By the way, why do you try to create a (greatly) cut down version of mp3tag in DO, when there is, well, mp3tag?

3 Likes

Thank you very much @lxp, it worked perfectly :star_struck: Really, entering the cover is something complex, I analyze and analyze your code and I realize that I would never, never have achieved that result!!!

@Xyzzy Nowadays I already have my music base very well formed, I no longer process music en masse, just a few songs from time to time, so this version of Mp3Tag is wonderful for me, simple, small, with a minimum of buttons.

Regardless of this, what I liked most about this experience of building my first script is everything I have learned, before it I didn't know absolutely anything about programming, and today, although I don't know much either, at least I have an idea more real about certain things.

But yes, Mp3Tag is a wonderful program, I have always used it!!!

1 Like

Wanting to show the dimensions of the cover, type 800 x 460 x 24 (170 KB) I have written:

var reso = Script.LoadImage(tmpFile);
dlg.Control(resolucion).label = reso.width + " x " + reso.height  + " x " + reso.depth + " (" + reso.size + ")";

Correctly displaying the width and height of the image, but not its depth and size. What could be happening?

Script.LoadImage() returns an Image object that doesn't have these properties.

Image.bitcount will give you the depth.

Size you can get from the file itself.

I understood, or rather, I learned :smile: I solved the situation by repeating your code to label:

	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 + ")";
	} else {
    	dlg.Control("resolucion").label = '';
	}

But there is still one detail that I would like to correct, and that is to be able to show the size unit. I used reso.sizeauto but it doesn't work.

Thanks Leo, the depth has already been resolved, now I will try to show the size of the image with its unit of measurement.