j-holub / Node-MPV

A NodeJs Module for MPV Player
https://www.npmjs.com/package/node-mpv
MIT License
116 stars 73 forks source link

View current playlist #97

Open gilphilbert opened 2 years ago

gilphilbert commented 2 years ago

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 commented 2 years ago

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.

j-holub commented 2 years ago

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.