API Docs
    Preparing search index...

    Function parser

    • Parses an M3U8 playlist string into a structured object.

      Automatically detects whether the playlist is a Master Playlist or Media Playlist and parses accordingly.

      Parameters

      • text: string

        The raw M3U8 playlist content as a string

      • Optionaloptions: ParserOptions

        Optional parsing options

        Options for the parser function.

        • Optionaluri?: string

          Base URI for resolving relative URLs in the playlist.

          If provided, all relative URIs (segment URIs, key URIs, map URIs, variant URIs, etc.) will be resolved to absolute URLs.

          const pl = parser(m3u8, { uri: 'https://example.com/hls/main.m3u8' });
          // pl.segments[0].uri → 'https://example.com/hls/segment.ts'

      Returns MasterPlaylist | MediaPlaylist

      A structured MasterPlaylist or MediaPlaylist object

      If the playlist violates RFC 8216 syntax rules

      import { parser } from '@skax/hls-parse';

      // Parse a simple media playlist
      const media = parser(`#EXTM3U
      #EXT-X-TARGETDURATION:10
      #EXTINF:9.009,
      segment1.ts
      #EXTINF:9.009,
      segment2.ts
      #EXT-X-ENDLIST`);

      // Parse with relative URL resolution
      const master = parser(m3u8Content, {
      uri: 'https://example.com/path/to/playlist.m3u8'
      });