utils.js 659 Bytes
const fs = require('fs').promises;

module.exports.readM3U8 = async (filePath) => {
  const data = await fs.readFile(filePath);
  const EXT_X_VERSION = String(data).split('#EXT-X-VERSION:')[1].split('\n')[0];
  const EXT_X_MEDIA_SEQUENCE = String(data).split('#EXT-X-MEDIA-SEQUENCE:')[1].split('\n')[0];
  const EXT_X_TARGETDURATION = String(data).split('#EXT-X-TARGETDURATION:')[1].split('\n')[0];
  const EXTINF = String(data).split('#EXTINF:');
  EXTINF.shift();
  const PLAYLIST = EXTINF.map(x => ({ file: x.split('\n')[1], time: x.split(',')[0] }));
  return {
    EXT_X_VERSION,
    EXT_X_MEDIA_SEQUENCE,
    EXT_X_TARGETDURATION,
    PLAYLIST,
  };
};