List Update

To discuss development of addons / skins / customization of MediaMonkey.

Moderator: jiri

serendip1959
Posts: 30
Joined: Mon Apr 07, 2014 2:59 pm
Contact:

List Update

Post by serendip1959 »

If I call:

list = app.db.getTracklist(<SQL SELECT>, -1)
list.whenLoaded().then(function () {

A list is returned. but if I edit the list and then call

list.commitAsync;

The main window updates with the changes, but they are not committed to the database. When MM is reloaded the changes are undone.
Ludek
Posts: 3414
Joined: Fri Mar 09, 2007 9:00 am
Contact:

Re: List Update

Post by Ludek »

Which changes are you referring? Based on documentation it "Commits all tracks into database and tag"
i.e. if you e.g. change a property (say title) for the tracks within the list then the changes are commited to the DB and tag.
It is similar like if you would call commitAsync for each track individually.

Or are you referring some other changes?
serendip1959
Posts: 30
Joined: Mon Apr 07, 2014 2:59 pm
Contact:

Re: List Update

Post by serendip1959 »

I am updating play count and last played.

I have tried both track.commitAsync and list.commitAsync without success. I also tried creating an empty track list interface and then addList with the same result. The main window updates but nothing is written to the database.
Ludek
Posts: 3414
Joined: Fri Mar 09, 2007 9:00 am
Contact:

Re: List Update

Post by Ludek »

Strange, as we use this function regularly in the native code and it works.

e.g. see tracksToUpdate.commitAsync(); in the dlgAutoTagFromFilename.js :
https://www.dropbox.com/s/6ek9t53uyfzro ... 7.png?dl=0

Just tested it and it updated the tracks metadata to the database and tags without an issue. Also tested with app.db.getTracklist and it also worked.

Are you using the newest build 2238 ?
Maybe if you could share a sample script that I could try and debug?
serendip1959
Posts: 30
Joined: Mon Apr 07, 2014 2:59 pm
Contact:

Re: List Update

Post by serendip1959 »

Take a look at this. I am using 2238.

Code: Select all

var list;
            list = app.db.getTracklist("SELECT * FROM Songs WHERE Artist = '" + artist + "' AND Album = '" + album + "' AND SongTitle = '" + track + "'", -1)
            list.whenLoaded().then(async function () {

                if (list.count === 0) {
                    return;
                }

                var changed = false;
                list.beginUpdate;
                list.forEach(async function (itm) {
                    itm.beginUpdate;
                    if (played > itm.playCounter && played > 0) {
                        changed = true;
                        itm.playCounter = itm.playCounter + (played - itm.playCounter);
                    }
                    if (playedDate > itm.lastTimePlayed) {
                        changed = true;
                        itm.lastTimePlayed = playedDate;
                    }
                    if (changed === true) {
                        itm.commitAsync;
                        changed = false;
                    };
                    itm.endUpdate;
                });
                list.endUpdate;

            });
Thanks. Is there another way of finding a specific track?
Ludek
Posts: 3414
Joined: Fri Mar 09, 2007 9:00 am
Contact:

Re: List Update

Post by Ludek »

Hi,
I guess that the problem is that commitAsync is not property, but method.

So use itm.commitAsync(); instead!

Also I think that the 'async' is not needed, you can use just 'function' or the arrow notation, i.e. (itm) => {.....
And if you want to make the processing faster for large lists then use fastForEach from mminit.js

Code: Select all

fastForEach(list, function (itm) { ....
just note that in the fast variant the itm object is just 'temporal JS object that is used for binding all tracks', i.e. you should avoid using it outside of function(itm) {... body.
serendip1959
Posts: 30
Joined: Mon Apr 07, 2014 2:59 pm
Contact:

Re: List Update

Post by serendip1959 »

Doh! Right in front of me. Thanks, don't know how many times I looked at that. Great tip about fast for each.
Post Reply