I'm back to the drawing board for my add-on "fixAlbumArt". The idea of this utility is to cycle through all selected songs and find the album art that is the front cover and remove the other art. When I run the following code on my machine I receive the following error:
Application throw an exception Exception EAccessViolation in module libcef.dll at 0231FD0D. Access violation at address 5AD2FD0D in module 'libcef.dll', Read of address 64340454.
Code: Select all
/*
title: Fix Album Art
description: Provides options to fix album art
Original: trixmoto
Author: MPG IT Consulting
Date:2021-11-30
*/
var trackList;
var breakException = {};
function removeAll() {
var cvr;
var cvrList;
// Create a background task so that the user can see the progress in the bottom bar
var taskProgress = app.backgroundTasks.createNew();
taskProgress.leadingText = ('Fixing art: ');
var trackCount = trackList.count;
var trackIdx = 0;
listAsyncForEach(trackList,
// callback for each track
(track, next) => {
// Update the background task text
trackIdx++;
taskProgress.text = sprintf('%d of %d', trackIdx, trackCount);
cvrList = track.loadCoverListAsync();
cvrList.whenLoaded().then(() => {
cvrList.modifyAsync(function () {
var blnFrontFound = false;
//find first cover identified as the front (if any)
for(var intCnt = 0; intCnt < cvrList.count; intCnt++){
cvr = cvrList.getValue(intCnt);
if (blnFrontFound == true){
cvr.coverTypeDesc = "Not specified";
} else {
if( cvr.coverTypeDesc == "Cover (front)"){
blnFrontFound = true;
} else {
cvr.coverTypeDesc = "Not specified";
}
}
}
//if none found make the first embedded cover the front
if (blnFrontFound == false){
for(var intCnt = 0; intCnt < cvrList.count; intCnt++){
if(cvrList.getValue(intCnt).coverStorage == 0){
cvr = cvrList.getValue(intCnt);
cvr.coverTypeDesc = "Cover (front)";
blnFrontFound = true;
break;
}
}
}
//if none found, make first image the front
if (blnFrontFound == false){
cvr = cvrList.getValue(0);
cvr.coverTypeDesc = "Cover (front)";
}
//select all covers except front cover
for(var intCnt = 0; intCnt < cvrList.count; intCnt++){
cvr = cvrList.getValue(intCnt);
if( cvr.coverTypeDesc == "Cover (front)"){
cvrList.setSelected(intCnt, false);
} else{
cvrList.setSelected(intCnt, true);
}
};
cvrList.deleteSelected();
var firstCover = cvrList.getValue(0);
// The if (firstCover &&) part is just a sanity check to avoid a crash
if (firstCover && firstCover.coverStorage != 0){
firstCover.coverStorage = 0;
}
// Commit track, then AFTER the commit is done, process the next track
cvrList.modified = true;
track.commitAsync().then(next);
});
});
},
// callback when done
() => {
// finish the background task
return taskProgress.terminate();
trackList.commitAsync();
}
);
}
function btnOkClick() {
var ddOptions = qid('ddOptions').controlClass.value;
if (ddOptions == ""){
messageDlg('You must select a value from the drop down.', 'Error', ['btnOk'], {
}, function (result) {
return;
});
}
switch(ddOptions.substring(0,2)){
case "01":
removeAll();
break;
case "02":
alert("02");
break;
case "03":
alert("03");
break;
case "04":
alert("04");
break;
case "05":
alert("05");
break;
case "06":
alert("06");
break;
case "07":
alert("07");
break;
case "08":
alert("08");
break;
case "09":
alert("09");
break;
case "10":
alert("10");
break;
case "11":
alert("11");
break;
case "12":
alert("12");
break;
case "13":
alert("13");
break;
case "14":
alert("14");
break;
case "15":
alert("15");
break;
case "16":
alert("16");
break;
case "17":
alert("17");
break;
}
app.setValue('fixAlbumArt', {
ddOptions: qid('ddOptions').controlClass.value
});
trackList.commitAsync();
closeWindow();
}
function btnCancelClick() {}
function init(params) {
this.title = params.title;
trackList = params.tracks;
var obj = app.getValue('fixAlbumArt', {
ddOptions: qid('ddOptions').controlClass.value
});
qid('ddOptions').controlClass.value = obj.ddOptions;
if (trackList === undefined) {
messageDlg(_("Select tracks to be updated"), 'Error', ['btnOK'], {
defaultButton: 'btnOK'
}, function (result) {
modalResult = 0;
});
return;
};
if (trackList.count === 0) {
messageDlg(_("Select tracks to be updated"), 'Error', ['btnOK'], {
defaultButton: 'btnOK'
}, function (result) {
modalResult = 0;
});
return;
};
window.localListen(qid('btnOK'), 'click', btnOkClick);
window.localListen(qid('btnCancel'), 'click', btnCancelClick, true);
}