by MPG » Mon Feb 07, 2022 3:47 pm
Okay, so I completely redesigned it to set it up to be async. The code removes all of the art except one, sets it as Cover (front), and doesn't fail...yea me. Unfortunately, the results are not being saved. If I double click the image after running the script, MM freezes. If I just close MM and reopen it, the images are not saved.
Code: Select all
// A simple script that replaces a specified string in Song Title, Artist, Album and Album Artist
function removeAll( trackList) {
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 () {
if(cvrList.count > 0) {
//loop through all covers to find if any cover identified as the front
//any cover not identified as a front cover is set as "Not Specified"
var blnFrontFound = false;
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";
}
}
}
alert("1: " + blnFrontFound);
//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;
intCnt = cvrList.count + 1;
}
}
}
alert("2: " + blnFrontFound);
//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);
alert("3: " + blnFrontFound);
} else{
cvrList.setSelected(intCnt, true);
}
};
}
cvrList.deleteSelected();
if(cvrList.count > 0){
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;
alert("4: " + blnFrontFound);
}
}
// Commit track, then AFTER the commit is done, process the next track
cvrList.modified = true;
alert("track commit")
track.commitAsync().then(next);
});
});
},
// callback when done
() => {
// finish the background task
trackList.commitAsync();
alert("tracklist Commit")
return taskProgress.terminate();
}
);
messageDlg(_('Album Art is fixed!'), 'Information', ['btnOK'], {
defaultButton: 'btnOK'
}, undefined);
}
Disregard the alerts....that's me debugging.

Okay, so I completely redesigned it to set it up to be async. The code removes all of the art except one, sets it as Cover (front), and doesn't fail...yea me. Unfortunately, the results are not being saved. If I double click the image after running the script, MM freezes. If I just close MM and reopen it, the images are not saved.
[code]
// A simple script that replaces a specified string in Song Title, Artist, Album and Album Artist
function removeAll( trackList) {
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 () {
if(cvrList.count > 0) {
//loop through all covers to find if any cover identified as the front
//any cover not identified as a front cover is set as "Not Specified"
var blnFrontFound = false;
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";
}
}
}
alert("1: " + blnFrontFound);
//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;
intCnt = cvrList.count + 1;
}
}
}
alert("2: " + blnFrontFound);
//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);
alert("3: " + blnFrontFound);
} else{
cvrList.setSelected(intCnt, true);
}
};
}
cvrList.deleteSelected();
if(cvrList.count > 0){
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;
alert("4: " + blnFrontFound);
}
}
// Commit track, then AFTER the commit is done, process the next track
cvrList.modified = true;
alert("track commit")
track.commitAsync().then(next);
});
});
},
// callback when done
() => {
// finish the background task
trackList.commitAsync();
alert("tracklist Commit")
return taskProgress.terminate();
}
);
messageDlg(_('Album Art is fixed!'), 'Information', ['btnOK'], {
defaultButton: 'btnOK'
}, undefined);
}
[/code]
Disregard the alerts....that's me debugging. :cry: