Node-MPV icon indicating copy to clipboard operation
Node-MPV copied to clipboard

View current playlist

Open gilphilbert opened this issue 2 years ago • 2 comments

Node-MPV allows to load, append to- and move items around the current playlist. But how do we get the content of the current playlist?

If there are 10 items on the playlist (we know this from getPlaylistSize() and the event playlist-count) how do we know what those 10 items are?

Perhaps I just missed in the 10 times I read the readme, but I can't see it!

gilphilbert avatar Aug 27 '21 07:08 gilphilbert

I'll answer my own question quickly:

const size = await mpv.getPlaylistSize()
const paths = []
const titles = []
for (i = 0; i < size; i++) {
  // do whatever you need with path
  const path = await mpv.getProperty(`playlist/${i}/filename`)

  // do whatever you need with title
  const title = await mpv.getProperty(`playlist/${i}/title`)

  // or add to an array...
  paths.push(await mpv.getProperty(`playlist/${i}/filename`))
  titles.push(await mpv.getProperty(`playlist/${i}/title`))
}

It seems it would be nice to wrap this up in the library for the sake of simplicity. I know it's not an MPV-native feature, but I'm sure it'll be handy to others, too.

gilphilbert avatar Aug 27 '21 08:08 gilphilbert

Hey there,

I'm super sorry for the late reply, somehow I didn't check GitHub. You are right, this should be offered in the module right away and I'll implement it. Thanks for providing code already, that speeds things up for me.

j-holub avatar Sep 24 '21 14:09 j-holub