Reading Downloaded Lyrics in MMW5

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Reading Downloaded Lyrics in MMW5

Re: Reading Downloaded Lyrics in MMW5

by jmac0001 » Wed Sep 20, 2023 12:36 am

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

Re: Reading Downloaded Lyrics in MMW5

by drakinite » Wed Sep 20, 2023 12:30 am

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.

Re: Reading Downloaded Lyrics in MMW5

by jmac0001 » Tue Sep 19, 2023 11:50 pm

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.

Re: Reading Downloaded Lyrics in MMW5

by drakinite » Tue Sep 19, 2023 11:18 pm

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();

Reading Downloaded Lyrics in MMW5

by jmac0001 » Tue Sep 19, 2023 4:57 am

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);

Top