Therefore I needed to introduce new method move2TagAsync, usage like this:
Code: Select all
firstCover.move2TagAsync().then(() => {
next(); // succcess
}, (error) => {
ODS('Error during moving cover to file tag: ' + error);
next();
});
Code: Select all
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";
}
}
}
//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;
}
}
}
//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();
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) {
cvrList.modified = true; // just in case no cover has been deleted and we change the storage below
firstCover.move2TagAsync().then(() => {
next(); // succcess
}, (error) => {
ODS('Error during moving cover to file tag: ' + error);
next(); // error
});
return;
}
}
// Commit track, then AFTER the commit is done, process the next track
next();
});
});
},
// callback when done
() => {
// finish the background task
trackList.commitAsync().then(() => {
taskProgress.terminate();
messageDlg(_('Album Art is fixed!'), 'Information', ['btnOK'], {
defaultButton: 'btnOK'
}, undefined);
});
}
);
}