npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hls-get-scte-segments

v0.0.4

Published

Utility for parsing .m3u8 and extract information about CUE-OUT/CUE-IN segments

Downloads

4

Readme

hls-get-scte-segments

Utility for parsing .m3u8 and extract information about CUE-OUT/CUE-IN segments

Usage

For the manifests where a SCTE35 message is expressed as EXT-X-DATERANGE tags

import {getScteSegments} from 'hls-get-scte-segments';


const playlistText = `
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:7
#EXT-X-MEDIA-SEQUENCE:103090
#EXT-X-PROGRAM-DATE-TIME:2023-01-31T06:28:47.759Z
#EXTINF:5.572,
manifest_1_103090.ts
#EXT-X-DATERANGE:ID="198",START-DATE="2023-01-31T06:28:53.331Z",PLANNED-DURATION=22.087,SCTE35-OUT=0xFC302500000003289800FFF01405000000C67FEFFECA4EF5BDFE010BC8DC0EAC000000002B9AD333
#EXT-X-PROGRAM-DATE-TIME:2023-01-31T06:28:53.331Z
#EXTINF:4.438,
manifest_1_103091.ts
#EXT-X-PROGRAM-DATE-TIME:2023-01-31T06:28:57.769Z
#EXTINF:6.006,
manifest_1_103092.ts
#EXT-X-PROGRAM-DATE-TIME:2023-01-31T06:29:03.775Z
#EXTINF:6.006,
manifest_1_103093.ts
#EXT-X-PROGRAM-DATE-TIME:2023-01-31T06:29:09.781Z
#EXTINF:5.639,
manifest_1_103094.ts
#EXT-X-DATERANGE:ID="198",START-DATE="2023-01-31T06:28:53.331Z",END-DATE="2023-01-31T06:29:08.146Z",DURATION=22.089
#EXT-X-PROGRAM-DATE-TIME:2023-01-31T06:29:15.420Z
#EXTINF:5.639,
manifest_1_103095.ts
#EXT-X-PROGRAM-DATE-TIME:2023-01-31T06:29:21.059Z
#EXTINF:6.006,
manifest_1_103096.ts
`;

const scteSegments = getScteSegments(playlistText);
// List the URLs of CUE-OUT/CUE-IN segments
for (const segment of scteSegments) {
  // segment is a Segment object parsed by hls-parser (See https://github.com/kuu/hls-parser)
  console.log(`${getSuffix(segment)}${segment.uri}`);
}
// manifest_1_103091.ts => CUE-OUT
// manifest_1_103095.ts => CUE-IN
  

// You can also get adjacent N segments
const scteSegments = getScteSegments(playlistText, {adjacentSegments: 1});

for (const segment of scteSegments) {
  console.log(`${getPrefix(segment)}${segment.uri}`);
}
// manifest_1_103090.ts 
// manifest_1_103091.ts => CUE-OUT
// manifest_1_103092.ts
// manifest_1_103094.ts
// manifest_1_103095.ts => CUE-IN duration=22.089
// manifest_1_103096.ts

// You can also get all the in-between segments
const scteSegments = getScteSegments(playlistText, {hollow: false});

for (const segment of scteSegments) {
  console.log(`${getPrefix(segment)}${segment.uri}`);
}
// manifest_1_103091.ts => CUE-OUT
// manifest_1_103092.ts
// manifest_1_103093.ts
// manifest_1_103094.ts
// manifest_1_103095.ts => CUE-IN duration=22.089

function getSuffix({dateRange}) {
  if (!dateRange) {
    return '';
  }
  return ` => ${dateRange.end ? 'CUE-IN duration=' + dateRange.duration : 'CUE-OUT'}`;
}

For the manifests where a SCTE35 message is expressed as EXT-X-CUE-OUT/IN tags

import {getScteSegments} from 'hls-get-scte-segments';


const playlistText = `
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:7
#EXT-X-MEDIA-SEQUENCE:103090
#EXT-X-PROGRAM-DATE-TIME:2023-01-31T06:28:47.759Z
#EXTINF:5.572,
manifest_1_103090.ts
#EXT-OATCLS-SCTE35:/DAlAAFuu/s2AP/wFAUAAAACf+/+LEknYf4AKTGxAAEBAQAASvVJ6w==
#EXT-X-CUE-OUT:22.087
#EXT-X-PROGRAM-DATE-TIME:2023-01-31T06:28:53.331Z
#EXTINF:4.438,
manifest_1_103091.ts
#EXT-X-CUE-OUT-CONT:ElapsedTime=4.438,Duration=22.087,SCTE35=/DAlAAFuu/s2AP/wFAUAAAACf+/+LEknYf4AKTGxAAEBAQAASvVJ6w==
#EXT-X-PROGRAM-DATE-TIME:2023-01-31T06:28:57.769Z
#EXTINF:6.006,
manifest_1_103092.ts
#EXT-X-CUE-OUT-CONT:ElapsedTime=10.444,Duration=22.087,SCTE35=/DAlAAFuu/s2AP/wFAUAAAACf+/+LEknYf4AKTGxAAEBAQAASvVJ6w==
#EXT-X-PROGRAM-DATE-TIME:2023-01-31T06:29:03.775Z
#EXTINF:6.006,
manifest_1_103093.ts
#EXT-X-CUE-OUT-CONT:ElapsedTime=16.450,Duration=22.087,SCTE35=/DAlAAFuu/s2AP/wFAUAAAACf+/+LEknYf4AKTGxAAEBAQAASvVJ6w==
#EXT-X-PROGRAM-DATE-TIME:2023-01-31T06:29:09.781Z
#EXTINF:5.639,
manifest_1_103094.ts
#EXT-X-CUE-IN
#EXT-X-PROGRAM-DATE-TIME:2023-01-31T06:29:15.420Z
#EXTINF:5.639,
manifest_1_103095.ts
#EXT-X-PROGRAM-DATE-TIME:2023-01-31T06:29:21.059Z
#EXTINF:6.006,
manifest_1_103096.ts
`;

const scteSegments = getScteSegments(playlistText);
// List the URLs of CUE-OUT/CUE-IN segments
for (const segment of scteSegments) {
  // segment is a Segment object parsed by hls-parser (See https://github.com/kuu/hls-parser)
  console.log(`${getSuffix(segment)}${segment.uri}`);
}
// manifest_1_103091.ts => CUE-OUT
// manifest_1_103095.ts => CUE-IN
  

// You can also get adjacent N segments
const scteSegments = getScteSegments(playlistText, {adjacentSegments: 1});

for (const segment of scteSegments) {
  console.log(`${getPrefix(segment)}${segment.uri}`);
}
// manifest_1_103090.ts 
// manifest_1_103091.ts => CUE-OUT duration=22.087
// manifest_1_103092.ts
// manifest_1_103094.ts
// manifest_1_103095.ts => CUE-IN
// manifest_1_103096.ts

// You can also get all the in-between segments
const scteSegments = getScteSegments(playlistText, {hollow: false});

for (const segment of scteSegments) {
  console.log(`${getPrefix(segment)}${segment.uri}`);
}
// manifest_1_103091.ts => CUE-OUT duration=22.087
// manifest_1_103092.ts
// manifest_1_103093.ts
// manifest_1_103094.ts
// manifest_1_103095.ts => CUE-IN

function getSuffix({markers}) {
  for (const marker of markers) {
    if (marker.type === 'OUT') {
      return `CUE-OUT duration=${marker.duration}`;
    } else if (marker.type === 'IN') {
      return 'CUE-IN';
    }
  }
  return '';
}

API

getScteSegments(playlist[, options])

Extracts CUE-OUT/CUE-IN segments from playlist

params

| Name | Type | Required | Default | Description | | -------- | ------ | -------- | ------- | ------------- | | playlist | string | Yes | N/A | A text data of an HLS media playlist |

return value

An array of instances of Segment (See hls-parser)