Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hls-parser

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hls-parser

A simple library to read/write HLS playlists

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
27K
increased by10.59%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Coverage Status Dependency Status XO code style

hls-parser

Provides synchronous functions to read/write HLS playlists

Usage

const HLS = require('hls-parser');

fetch('https://foo.com/bar.m3u8')
.then(result => {
  return result.text();
})
.then(data => {
  // Parse the playlist
  const playlist = HLS.parse(data);
  // You can access the playlist as a JS object
  if (playlist.isMasterPlaylist) {
    console.log('Master playlist');
  } else {
    console.log('Media playlist');
  }
  // Create a new playlist
  const {MediaPlaylist} = HLS.types;
  const newPlaylist = new MediaPlaylist({
    targetDuration: 9,
    playlistType: 'VOD',
    segments: [
      new Segment({
        uri: 'low/1.m3u8'
        duration: 9,
        mediaSequenceNumber: 0,
        discontinuitySequence: 0
      })
    ]
  }));
  // Convert the object into a text
  const text = HLS.stringify(newPlaylist);
  console.log(`New playlist: ${text}`);
})
.catch(err => {
  console.error(err.stack);
});

API

HLS.parse(str)

Converts a text playlist into a structured JS object

params
NameTypeRequiredDefaultDescription
strstringYesN/AA text data that conforms to the HLS playlist spec
return value

An instance of either MasterPlaylist or MediaPlaylist (See Data format below.)

HLS.stringify(obj)

Converts a JS object into a plain text playlist

params
NameTypeRequiredDefaultDescription
objMasterPlaylist or MediaPlaylist (See Data format below.)YesN/AAn object returned by HLS.parse() or a manually created object
return value

A text data that conforms to the HLS playlist spec

HLS.types

An object that holds all the classes described below.

Data format

This section describes the structure of the object returned by parse() method.

data structure

Data

PropertyTypeRequiredDefaultDescription
typestringYesN/AEither playlist or segment}

Playlist (extends Data)

PropertyTypeRequiredDefaultDescription
isMasterPlaylistbooleanYesN/Atrue if this playlist is a master playlist
uristringNoundefinedPlaylist URL
versionobjectNoundefinedSee EXT-X-VERSION
independentSegmentsbooleanNofalseSee EXT-X-INDEPENDENT-SEGMENTS
startobject({offset: number, precise: boolean})NoundefinedSee EXT-X-START
sourcestringNoundefinedThe unprocessed text of the playlist

MasterPlaylist (extends Playlist)

PropertyTypeRequiredDefaultDescription
variants[Variant]No[]See EXT-X-STREAM-INF and EXT-X-I-FRAME-STREAM-INF
currentVariantnumberNoundefinedArray index that points to the chosen item in variants
sessionDataList[SessionData]No[]See EXT-X-SESSION-DATA
sessionKeyList[Key]No[]See EXT-X-SESSION-KEY

Variant

PropertyTypeRequiredDefaultDescription
uristringYesN/AURI of the variant playlist
isIFrameOnlybooleanNoundefinedtrue if the variant is an I-frame media playlist. See EXT-X-I-FRAME-STREAM-INF
bandwidthnumberYesN/ASee BANDWIDTH attribute in EXT-X-STREAM-INF
averageBandwidthnumberNoundefinedSee AVERAGE-BANDWIDTH attribute in EXT-X-STREAM-INF
codecsstringNoundefinedSee CODECS attribute in EXT-X-STREAM-INF
resolutionobject ({width: number, height: number})NoundefinedSee RESOLUTION attribute in EXT-X-STREAM-INF
frameRatenumberNoundefinedSee FRAME-RATE attribute in EXT-X-STREAM-INF
hdcpLevelstringNoundefinedSee HDCP-LEVEL attribute in EXT-X-STREAM-INF
audio[Rendition(type='AUDIO')]No[]See AUDIO attribute in EXT-X-STREAM-INF
video[Rendition(type='VIDEO')]No[]See VIDEO attribute in EXT-X-STREAM-INF
subtitles[Rendition(type='SUBTITLES')]No[]See SUBTITLES attribute in EXT-X-STREAM-INF
closedCaptions[Rendition(type='CLOSED-CAPTIONS')]No[]See CLOSED-CAPTIONS attribute in EXT-X-STREAM-INF
currentRenditionsobject ({AUDIO: number, VIDEO: number, SUBTITLES: number, CLOSED-CAPTIONS: number})No{}A hash object that contains array indices that points to the chosen Rendition for each type

Rendition

PropertyTypeRequiredDefaultDescription
typestringYesN/ASee TYPE attribute in EXT-X-MEDIA
uristringNoundefinedSee URI attribute in EXT-X-MEDIA
groupIdstringYesN/ASee GROUP-ID attribute in EXT-X-MEDIA
languagestringNoundefinedSee LANGUAGE attribute in EXT-X-MEDIA
assocLanguagestringNoundefinedSee ASSOC-LANGUAGE attribute in EXT-X-MEDIA
namestringYesN/ASee NAME attribute in EXT-X-MEDIA
isDefaultbooleanNofalseSee DEFAULT attribute in EXT-X-MEDIA
autoselectbooleanNofalseSee AUTOSELECT attribute in EXT-X-MEDIA
forcedbooleanNofalseSee FORCED attribute in EXT-X-MEDIA
instreamIdstringNoundefinedSee INSTREAM-ID attribute in EXT-X-MEDIA
characteristicsstringNoundefinedSee CHARACTERISTICS attribute in EXT-X-MEDIA
channelsstringNoundefinedSee CHANNELS attribute in EXT-X-MEDIA

SessionData

PropertyTypeRequiredDefaultDescription
idstringYesN/ASee DATA-ID attribute in EXT-X-SESSION-DATA
valuestringNoundefinedSee VALUE attribute in EXT-X-SESSION-DATA
uristringNoundefinedSee URI attribute in EXT-X-SESSION-DATA
languagestringNoundefinedSee LANGUAGE attribute in EXT-X-SESSION-DATA

MediaPlaylist (extends Playlist)

PropertyTypeRequiredDefaultDescription
targetDurationnumberYesN/ASee EXT-X-TARGETDURATION
mediaSequenceBasenumberNo0See EXT-X-MEDIA-SEQUENCE
discontinuitySequenceBasenumberNo0See EXT-X-DISCONTINUITY-SEQUENCE
endlistbooleanNofalseSee EXT-X-ENDLIST
playlistTypestringNoundefinedSee EXT-X-PLAYLIST-TYPE
isIFramebooleanNoundefinedSee EXT-X-I-FRAMES-ONLY
segments[Segment]No[]A list of available segments

Segment (extends Data)

PropertyTypeRequiredDefaultDescription
uristringYesN/AURI of the media segment
durationnumberYesN/ASee EXTINF
titlestringNoundefinedSee EXTINF
byterangeobject ({length: number, offset: number})NoundefinedSee EXT-X-BYTERANGE
discontinuitybooleanNoundefinedSee EXT-X-DISCONTINUITY
mediaSequenceNumbernumberYesN/ASee the description about 'Media Sequence Number' in 3. Media Segments
discontinuitySequencenumberYesN/ASee the description about 'Discontinuity Sequence Number' in 6.2.1. General Server Responsibilities
keyKeyNoundefinedSee EXT-X-KEY
mapMediaInitializationSectionNoundefinedSee EXT-X-MAP
programDateTimeDateNoundefinedSee EXT-X-PROGRAM-DATE-TIME
dateRangeDateRangeNoundefinedSee EXT-X-DATERANGE

Key

PropertyTypeRequiredDefaultDescription
methodstringYesN/ASee METHOD attribute in EXT-X-KEY
uristringNoundefinedSee URI attribute in EXT-X-KEY
ivBuffer(length=16)NoundefinedSee IV attribute in EXT-X-KEY
formatstringNoundefinedSee KEYFORMAT attribute in EXT-X-KEY
formatVersionstringNoundefinedSee KEYFORMATVERSIONS attribute in EXT-X-KEY

MediaInitializationSection

PropertyTypeRequiredDefaultDescription
uristringYesN/ASee URI attribute in EXT-X-MAP
byterangeobject ({length: number, offset: number})NoundefinedSee BYTERANGE attribute in EXT-X-MAP

DateRange

PropertyTypeRequiredDefaultDescription
idstringYesN/ASee ID attribute in EXT-X-DATERANGE
classIdstringNoundefinedSee CLASS attribute in EXT-X-DATERANGE
startDateYesN/ASee START-DATE attribute in EXT-X-DATERANGE
endDateNoundefinedSee END-DATE attribute in EXT-X-DATERANGE
durationnumberNoundefinedSee DURATION attribute in EXT-X-DATERANGE
plannedDurationnumberNoundefinedSee PLANNED-DURATION attribute in EXT-X-DATERANGE
endOnNextbooleanNoundefinedSee END-ON-NEXT attribute in EXT-X-DATERANGE
attributesobjectNo{}A hash object that holds SCTE35 attributes and user defined attributes. See SCTE35-* and X- attributes in EXT-X-DATERANGE

Keywords

FAQs

Package last updated on 15 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc