Retrieving Track Comments

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

Moderators: jiri, drakinite, Addon Administrators

Keeps
Posts: 17
Joined: Sat Sep 03, 2011 4:25 pm

Retrieving Track Comments

Post by Keeps »

Hello,

I'm trying to write a script that copies the metadata from an older copy of a file to a new one. I had to sort them in a pretty round-about way, but it's mostly working - everything except the track comments.

The API tells me Track.summary is a read-only shortened version of the track comment, topping out at 200 characters. That wouldn't be ideal, obviously, but I could work with it - except it doesn't seem to be true. There's a second entry in the API for Track.summary that just says "gets/sets summary," and if I use it with .setCommentAsync() the comment just gets set to "Artist - Track Name".

The better solution would be to use getCommentAsync() and setCommentAsync() to guarantee I get the entire comment, except that getCommentAsync() takes a string and setCommentAsync() returns a "Promise." All the methods for a Promise also return Promises, and I haven't found any reference either in MM's API or Mozilla's linked JavaScript documentation to actually using the async data - just methods to wait for it to finish loading. I tried adding .toString(), but that just sets the comment to the object name.

Here's my current module, along with a lot of commented-out previous attempts, if you want more context. Also, if there's a better way to operate on the members of a track list to pick the source and destination, please let me know - everything else I tried didn't do anything.

https://www.dropbox.com/s/jraymy16lvcyi ... .mmip?dl=0

Thank you!
drakinite
Posts: 965
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: Retrieving Track Comments

Post by drakinite »

Here's a simple run-down on how to retrieve data from Promises and async functions: https://javascript.info/async-await

Essentially, you have two options: Promise.then(callback) or async/await. The webpage goes into more detail.
Image
Student electrical-computer engineer, 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.
Post Reply