Reading Downloaded Lyrics in MMW5

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

Moderators: jiri, drakinite, Addon Administrators

jmac0001
Posts: 3
Joined: Wed Mar 14, 2018 12:41 am

Reading Downloaded Lyrics in MMW5

Post by jmac0001 »

I'm trying to read the track lyrics that are already embedded in the tags. I can't find a way read the lyrics as a string.

https://www.mediamonkey.com/docs/api/cl ... yricsAsync

I don't see a track.lyrics property in the documentation but I see the lyrics data for the track in the gui. I do see the getLyricsAsync() but I think it's for fetching lyrics from the web. If I should be using the method instead of track.lyrics then can someone provide an example of how to use the function?

I think the lyrics property exists but in my code it's only returning 'undefined'.

var L = String(itm.lyrics);
drakinite
Posts: 975
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: Reading Downloaded Lyrics in MMW5

Post by drakinite »

Sorry about the unhelpful API docs - We're currently in the process of migrating them to Typedoc, which includes ALL accessible properties and methods, even those which don't have any jsdoc/tsdoc comments explicitly written. I see the docs comments for lyrics and comment is lacking, so I'll work on that now (but we don't update the api docs regularly, so it might take a bit for the update to show up).

https://www.mediamonkey.com/docs/apinew ... yricsShort

lyricsShort, commentShort, and extendedTagsShort are synchronous and retrieve the first 200 characters of the lyrics/comment/extendedTags, respectively.

getLyricsAsync, getCommentAsync, and getExtendedTagsAsync are promises and retrieve the full lyrics/comment/extendedTags, which requires a database call if they are not yet loaded in memory.
To my understanding, the reason you need an async call to load the full lyrics/comment/extendedTags is to optimize memory usage and/or load times, because if you have full lyrics for 100,000 songs loaded in memory that would be a lot to deal with.

To use getLyricsAsync:

Code: Select all

// inside a regular function:
track.getLyricsAsync().then(function(lyrics) {
  // do stuff
});

// or, inside an async function:
let lyrics = await track.getLyricsAsync();
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.
jmac0001
Posts: 3
Joined: Wed Mar 14, 2018 12:41 am

Re: Reading Downloaded Lyrics in MMW5

Post by jmac0001 »

I did dump the properties and methods for the track object and found other lyric related objects.
Before your comment I was testing the 'lyricsShort' property and that helped, but I didn't think it was the right method.
I'll try your code soon.
I also see 'getLyricsSync', but again, I don't know the difference.

Thanks for the help, Draknite.
drakinite
Posts: 975
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: Reading Downloaded Lyrics in MMW5

Post by drakinite »

The long explanation is that each Track object also has a value for internal use, "longTextLoaded", which is enabled after the track has loaded all the long text values. So if you run any one of the three async functions (getCommentAsync, getLyricsAsync, getExtendedTagsAsync) it'll actually load the values from all three at once. Then, when longTextLoaded is true and all the long texts are loaded in memory, the synchronous versions (getCommentSync, getLyricsSync, getExtendedTagsSync) will work and return the full strings. If longTextLoaded is false when you attempt to run getCommentSync/getLyricsSync/getExtendedTagsSync, then an exception will be raised and MediaMonkey will crash.

I would not recommend dealing with longTextLoaded and the get_____Sync functions, and I would instead recommend just sticking with getCommentAsync, getLyricsAsync, and getExtendedTagsAsync.

Internally, if the long texts are already loaded in memory, the async functions will just return the values from memory anyways, so there's no performance loss.
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.
jmac0001
Posts: 3
Joined: Wed Mar 14, 2018 12:41 am

Re: Reading Downloaded Lyrics in MMW5

Post by jmac0001 »

Thanks for the explanation. I'll let you know once I've tested the code.
Post Reply