saveToFileFolder
Moderators: jiri, drakinite, Addon Administrators
saveToFileFolder
Hi,
I am building my last add-on. this add-on will remove all of the album arts, except the first one. It will set embed the first one and set it as the front cover.
When I attempt to save the first cover so that it can be added later, the following saves the image, however, it also adds it to the image list. When I go to remove all of the images, it's not being picked up in the count. Is this the expected behavior? If so, is there a way to refresh the itmRec to pick up?
trackList.forEach(function (itmRec){
itmRec.coverList.locked(function (){
cvr = itmRec.coverList.getValue(0);
cvr.saveToFileFolder(itmRec.path, "fixAlbumArtTemp.jpg", false);
});
itmRec.coverList.locked(function (){
for(intCnt=0; intCnt<=itmRec.coverList.count; intCnt++){
cvr = itmRec.coverList.getValue(intCnt);
itmRec.coverList.removeAsync(cvr);
}
});
});
I am building my last add-on. this add-on will remove all of the album arts, except the first one. It will set embed the first one and set it as the front cover.
When I attempt to save the first cover so that it can be added later, the following saves the image, however, it also adds it to the image list. When I go to remove all of the images, it's not being picked up in the count. Is this the expected behavior? If so, is there a way to refresh the itmRec to pick up?
trackList.forEach(function (itmRec){
itmRec.coverList.locked(function (){
cvr = itmRec.coverList.getValue(0);
cvr.saveToFileFolder(itmRec.path, "fixAlbumArtTemp.jpg", false);
});
itmRec.coverList.locked(function (){
for(intCnt=0; intCnt<=itmRec.coverList.count; intCnt++){
cvr = itmRec.coverList.getValue(intCnt);
itmRec.coverList.removeAsync(cvr);
}
});
});
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
Re: saveToFileFolder
Why you are saving the first cover to add it later?
It should be possible just change the cover storage from the file to tag.
Something like this:
Note that I haven't tested the code, just a snippet that should work IMO
It should be possible just change the cover storage from the file to tag.
Something like this:
Code: Select all
var coverList = track.loadCoverListAsync();
coverList.whenLoaded(()=> {
coverList.modifyAsync(() => {
for(i=coverList-1; i>=0; i--){
if (i > 0)
coverList.delete(i);
else
coverList.getValue(0).coverStorage = 0; // move from file to tag if not already
}
// track.saveCoverListAsync(); // probably not needed, is part of track.commitAsync(); below
track.commitAsync(); // commits and writes to tag & DB
});
});
Re: saveToFileFolder
Sweet! TY Ludek. I will play with your snippet and let you know the results!
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
Re: saveToFileFolder
I hope it's not your last add-on ever - It's great having you make addons and helping increase the versatility of how people can use MediaMonkey.

Data scientist, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
Re: saveToFileFolder
Hi,
I tried for a couple of hours to get the following code to work, however, I keep having problems. The last section is based off Ludek's suggestion and I end up with one of the following problems:
1) if I leave the whenloaded as suggested, the code never falls into the modifyAsync.
2) if I remove the whenloaded, it works just fine sometimes. Sometimes MM just hangs
3) If one of the covers is a link to a file and the file is deleted from the hard drive (not through the MM interface), MM hangs.
When MM hangs, I've noticed that if I attempt to close MM by clicking the "X" on the image in the taskbar, the track property window shows up. So it's like MM is waiting for a response to the property window, but I can't get focus to it.
Any help you can provide, I'd appreciate it.
I tried for a couple of hours to get the following code to work, however, I keep having problems. The last section is based off Ludek's suggestion and I end up with one of the following problems:
1) if I leave the whenloaded as suggested, the code never falls into the modifyAsync.
2) if I remove the whenloaded, it works just fine sometimes. Sometimes MM just hangs
3) If one of the covers is a link to a file and the file is deleted from the hard drive (not through the MM interface), MM hangs.
When MM hangs, I've noticed that if I attempt to close MM by clicking the "X" on the image in the taskbar, the track property window shows up. So it's like MM is waiting for a response to the property window, but I can't get focus to it.
Any help you can provide, I'd appreciate it.
Code: Select all
function removeAll() {
var blnFrontFound = false;
var intCnt = 0;
var cvr;
var cvrList;
trackList.forEach(function (track){
track.coverList.locked(function () {
//find first cover identified as the front (if any)
for(intCnt=0; intCnt < track.coverList.count; intCnt++){
cvr = track.coverList.getValue(intCnt);
if( cvr.coverTypeDesc.toLowerCase() == "cover (front)"){
blnFrontFound = true;
intCnt = track.coverList.count + 1;
}
};
//if any cover is embedded, make it the front
if (blnFrontFound == false){
for(intCnt=0; intCnt < track.coverList.count; intCnt++){
if(track.coverList.getValue(intCnt).coverStorage = 0){
cvr = track.coverList.getValue(intCnt);
cvr.coverTypeDesc = "Cover (front)";
blnFrontFound = true;
intCnt = track.coverList.count + 1;
}
};
}
//if none found, make first image the front
if (blnFrontFound == false){
cvr = track.coverList.getValue(0);
cvr.coverTypeDesc = "Cover (front)";
}
cvrList = track.loadCoverListAsync();
// cvrList.whenLoaded(() => {
alert("h")
cvrList.modifyAsync(() => {
for(intCnt = cvrList.count-1; intCnt >= 0; intCnt--){
cvr = cvrList.getValue(intCnt);
alert(intCnt)
//delete all covers except for front cover
if( cvr.coverTypeDesc.toLowerCase() == "cover (front)"){
alert("embed")
//embed cover if not already
if (cvrList.getValue(intCnt).coverStorage != 0){
cvrList.getValue(intCnt).coverStorage = 0;
}
} else{
alert("delete")
cvrList.delete(intCnt);
}
}
});
// });
});
track.saveCoverListAsync;
track.commitAsync;
});
}
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
Re: saveToFileFolder
Isn't the problem that you are using track.loadConverListAsync inside of
track.coverList.locked(function () {
?
I suppose that mainly using list.modifyAsync() inside of list.locked() should result in "Write lock after read lock" assertion?
Are you using debug build?
I think you should load the coverList at first and do everything in the "write lock"
i.e. something like this:
And btw I think that track.saveCoverListAsync; shouldn't be needed once track.commitAsync(); is called.
If just track.commitAsync(); won't work then try rather :
track.coverList.locked(function () {
?
I suppose that mainly using list.modifyAsync() inside of list.locked() should result in "Write lock after read lock" assertion?
Are you using debug build?
I think you should load the coverList at first and do everything in the "write lock"
i.e. something like this:
Code: Select all
trackList.forEach(function (track){
var cvrList = track.loadCoverListAsync();
cvrList.whenLoaded(() => {
cvrList.modifyAsync(() => {
// and do everything here in the write lock:
//find first cover identified as the front (if any)
for(intCnt=0; intCnt < track.coverList.count; intCnt++){
cvr = track.coverList.getValue(intCnt);
if( cvr.coverTypeDesc.toLowerCase() == "cover (front)"){
blnFrontFound = true;
....
....
If just track.commitAsync(); won't work then try rather :
Code: Select all
track.saveCoverListAsync().then( track.commitAsync);
Re: saveToFileFolder
Thanks Ludek.
I tried:
alert("h") is never executed.
I tried:
Code: Select all
function removeAll() {
var blnFrontFound = false;
var intCnt = 0;
var cvr;
var cvrList;
trackList.forEach(function (track){
cvrList = track.loadCoverListAsync();
cvrList.whenLoaded(() => {
alert("h")
track.coverList.locked(function () {
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
Re: saveToFileFolder
Damn, my bad.
Try this:
Sorry for the typo
Try this:
Code: Select all
cvrList.whenLoaded().then(() => {
alert("h");
Re: saveToFileFolder
Back to the drawing board. It generates an error:
cvrList.whenLoaded.then is not a function.
cvrList.whenLoaded.then is not a function.
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
Re: saveToFileFolder
Use cvrList.whenLoaded().then(callback)
The whenLoaded() returns a Promise.*
*(it's not technically a native JavaScript promise, but you can treat it like one.)
The whenLoaded() returns a Promise.*
*(it's not technically a native JavaScript promise, but you can treat it like one.)

Data scientist, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.