dasota
February 2, 2024, 2:35pm
61
@lxp the precision and success in your sentences is impressive, it worked wonderfully
But now, when I press the 'Save' button, an error is generated, and all the data is saved except the cover art?
cmd.RunCommand('SetAttr META "coverart:' + dlg.Control("caratula").label + '"');
errante
February 2, 2024, 2:45pm
62
@dasota if you carefully read the Dialog object part in the manual, for Open()
says:
A single Item object is returned to indicate the file selected by the user. This object will have an additional result property that will be False if the user cancelled the dialog - the other normal Item properties will only be valid if result is True
That means that :
coverart_usuario
is an Item object.
If you cancel the dialog, coverart_usuario.result
will be false . So you may want to check that before trying to load it.
Also, you are not checking if the file selected is an actual image.
Read and re-read the coverart part in Keywords for SetAttr META before getting into more questions.
1 Like
lxp
February 2, 2024, 2:50pm
63
SetAttr META "coverart:...
wants an item, not an image. See Docs .
Try
coverart_usuario
instead of
dlg.Control("caratula").label
dasota
February 2, 2024, 2:56pm
64
Thank you very much @errante , I'm really bad at these programming things, but I will read and read this cover issue a million times, I will make a mega summary and see if I can solve that little problem.
dasota
February 2, 2024, 2:59pm
65
I don't know if this is really what you're telling me, but it didn't work either.
cmd.RunCommand('SetAttr META "coverart:' + dlg.Control("coverart_usuario") + '"');
dasota
February 2, 2024, 3:01pm
66
case "btn_guardar":
cmd.RunCommand('SetAttr META "title:' + dlg.Control("titulo").value + '"');
cmd.RunCommand('SetAttr META "artist:' + dlg.Control("artista").value + '"');
cmd.RunCommand('SetAttr META "album:' + dlg.Control("album").value + '"');
cmd.RunCommand('SetAttr META "year:' + dlg.Control("anio").value + '"');
cmd.RunCommand('SetAttr META "track:' + dlg.Control("pista").value + '"');
cmd.RunCommand('SetAttr META "genre:' + dlg.Control("genero").value.name + '"');
cmd.RunCommand('SetAttr META "comment:' + dlg.Control("comentario").value + '"');
cmd.RunCommand('SetAttr META "albumartist:' + dlg.Control("artista_album").value + '"');
cmd.RunCommand('SetAttr META "composers:' + dlg.Control("compositor").value + '"');
cmd.RunCommand('SetAttr META "disc:' + dlg.Control("numero_disco").value + '"');
cmd.RunCommand('SetAttr META "coverart:' + dlg.Control("coverart_usuario") + '"');
break;
lxp
February 2, 2024, 3:04pm
67
I meant
cmd.RunCommand('SetAttr META "coverart:3:' + coverart_usuario + '"');
dasota
February 2, 2024, 3:06pm
68
Still giving the same error
lxp
February 2, 2024, 3:13pm
69
Works here
Seems to be rather slow, maybe you just need to wait a bit longer.
Are you really getting the same error?
lxp
February 2, 2024, 3:57pm
70
Hold on... each switch
case has its scope... so you need to define coverart_usuario
outside the switch statement.
Insert a line
var coverart_usuario;
somewhere before
switch (msg.control) {
dasota
February 2, 2024, 8:21pm
71
Hey @lxp , sorry for not responding sooner, but I spent the entire afternoon going from doctor to doctor.
Returning to the topic, even with cmd.RunCommand('SetAttr META "coverart:3:' + coverart_usuario + '"');
continues to give the same error regardless of how long I wait.
And I inserted var coverart_usuario;
and everything the same.
I'll pass the full code if you want to take a look.
// Mp3 Tag File
// (c) 2024 DASOTA
// Script para Directory Opus.
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";
}
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);
dlg.Control("archivo").value = item.name_stem;
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;
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
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";
//Resolución
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";
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_anadir_caratula":
var 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 = '';
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("numero_disco").value = '';
dlg.Control("caratula").label = '';
dlg.Control("resolucion").label = '';
break;
case "btn_guardar":
cmd.RunCommand('SetAttr META "title:' + dlg.Control("titulo").value + '"');
cmd.RunCommand('SetAttr META "artist:' + dlg.Control("artista").value + '"');
cmd.RunCommand('SetAttr META "album:' + dlg.Control("album").value + '"');
cmd.RunCommand('SetAttr META "year:' + dlg.Control("anio").value + '"');
cmd.RunCommand('SetAttr META "track:' + dlg.Control("pista").value + '"');
cmd.RunCommand('SetAttr META "genre:' + dlg.Control("genero").value.name + '"');
cmd.RunCommand('SetAttr META "comment:' + dlg.Control("comentario").value + '"');
cmd.RunCommand('SetAttr META "albumartist:' + dlg.Control("artista_album").value + '"');
cmd.RunCommand('SetAttr META "composers:' + dlg.Control("compositor").value + '"');
cmd.RunCommand('SetAttr META "disc:' + dlg.Control("numero_disco").value + '"');
cmd.RunCommand('SetAttr META "coverart:3:' + coverart_usuario + '"');
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_anadir_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>
lxp
February 2, 2024, 9:29pm
72
Remove var
from
var coverart_usuario = dlg.open("Carátula");
The missing step to get the scope right (forgot to mention).
Write segment case "btn_guardar":
as follows:
case "btn_guardar":
var cmdLine = 'SetAttr META' +
' "album:' + dlg.Control('album').value + '"' +
' "albumartist:' + dlg.Control('artista_album').value + '"' +
' "artist:' + dlg.Control('artista').value + '"' +
' "comment:' + dlg.Control('comentario').value + '"' +
' "composers:' + dlg.Control('compositor').value + '"' +
' "disc:' + dlg.Control('numero_disco').value + '"' +
' "genre:' + dlg.Control('genero').value.name + '"' +
' "track:' + dlg.Control('pista').value + '"' +
' "year:' + dlg.Control('anio').value + '"' +
' "coverart:3:' + coverart_usuario + '"';
DOpus.Output(cmdLine);
cmd.RunCommand(cmdLine);
break;
Looks like too many SetAttr
commands in a row can choke the script. Bonus: using just one SetAttr
command is faster
2 Likes
dasota
February 2, 2024, 10:23pm
73
Awesome, wonderful, here I am standing giving applause for you
But you know one thing, the disk number is not working, not even using ' "discnumber:' + dlg.Control('numero_disco').value + '"' +
And one last detail, how to make it so that when you press the save button, the window also closes?
dasota
February 2, 2024, 10:30pm
74
Now it is working with ' "discnumber:' + dlg.Control('numero_disco').value + '"' +
This PC has a slight mental retardation
Now the only detail that would be missing would be to close the window by pressing the "Save" button!!!
lxp
February 3, 2024, 7:12am
75
Write the while (true)
loop like this:
while (true) {
msg = dlg.GetMsg();
if (!msg.result) break;
var sayGoodBye = false;
if (msg.event == "click") {
switch (msg.control) {
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 = '';
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("numero_disco").value = '';
dlg.Control("caratula").label = '';
dlg.Control("resolucion").label = '';
break;
case "btn_guardar":
var cmdLine = 'SetAttr META' +
' "album:' + dlg.Control('album').value + '"' +
' "albumartist:' + dlg.Control('artista_album').value + '"' +
' "artist:' + dlg.Control('artista').value + '"' +
' "comment:' + dlg.Control('comentario').value + '"' +
' "composers:' + dlg.Control('compositor').value + '"' +
' "discnumber:' + dlg.Control('numero_disco').value + '"' +
' "genre:' + dlg.Control('genero').value.name + '"' +
' "title:' + dlg.Control('titulo').value + '"' +
' "track:' + dlg.Control('pista').value + '"' +
' "year:' + dlg.Control('anio').value + '"' +
' "coverart:3:' + coverart_usuario + '"';
DOpus.Output(cmdLine);
cmd.RunCommand(cmdLine);
sayGoodBye = true;
break;
}
}
if (sayGoodBye) break;
}
I also added the title
tag that was missing last time.
1 Like
dasota
February 3, 2024, 7:59am
76
dasota
February 18, 2024, 11:06pm
78
Thinking about musical genres, it would be ideal if these could be edited so that each person has the ones they like or need, could you help me with that?
Seeing other scripts I only knew how to write this:
initData.config_desc = DOpus.Create.Map();
configName = "genero";
initData.Config[configName] = true;
initData.config_desc(configName) = "Customize music genres";
lxp
February 19, 2024, 6:46am
79
Opus already has a list of genres. Do you want to maintain a second list? The internal list could be made available in the object model (I don't think it is yet). Then it'd be straightforward to add this collection to a drop-down.
If you don't want to wait, you could parse musicgenres.xml
yourself. Here's an example you could copy:
RecentToCollection
dasota I saw my shadow in you, I also have tried create some button for tagging Music files. Please Share your Button and script with me when it's complete.