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

@renmu/m3u8-downloader

v0.3.1

Published

m3u8 downloader

Downloads

165

Readme

M3U8Downloader

M3U8Downloader is a tool for downloading and merging M3U8 video segments. It supports concurrent downloads, retry mechanisms, and can merge downloaded TS segments into a single file, with an option to convert to MP4 format.

Features

  • Concurrent downloading of M3U8 video segments
  • Automatic retry on download failure
  • Support for stop, resume, cancel function
  • Merging TS segments into a single file
  • Optional conversion of TS files to MP4 format

Installation

Install using npm:

npm install @renmu/m3u8-downloader

Usage

Initialization

import M3U8Downloader from "@renmu/m3u8-downloader";

// download ts segments and convert to single ts file
const downloader = new M3U8Downloader(
  "https://example.com/path/to/playlist.m3u8",
  "/path/output.ts", // ts ext
  {
    convert2Mp4: false,
  }
);

// download ts segments and convert to single mp4 file
const downloader = new M3U8Downloader(
  "https://example.com/path/to/playlist.m3u8",
  "/path/output.mp4", // mp4 ext
  {
    convert2Mp4: true,
    ffmpegPath: "/usr/local/bin/ffmpeg",
  }
);

// download ts segments
const downloader = new M3U8Downloader(
  "https://example.com/path/to/playlist.m3u8",
  "anything",
  {
    mergeSegments: false,
    segmentsDir: outputDir, // the directory to store downloaded segments
  }
);

Options

/**
 * @param m3u8Url M3U8 URL
 * @param options
 * @param options.concurrency Number of segments to download concurrently
 * @param options.segmentsDir directory to store downloaded segments,default: system temp dir
 * @param options.mergeSegments Whether to merge downloaded segments into a single file
 * @param options.convert2Mp4 Whether to convert2Mp4 downloaded segments into a single file, you must open mergeSegments
 * @param options.ffmpegPath Path to ffmpeg binary if you open convert2Mp4
 * @param options.retries Number of retries for downloading segments
 * @param options.clean Whether to clean up downloaded segments after download is error or canceled
 * @param options.headers Axios headers to be sent with the HTTP request
 * */

Start Download

downloader.download();

Pause Download

downloader.pause();

Resume Download

downloader.resume();

Cancel Download

downloader.cancel();

Event Listeners

M3U8Downloader extends from EventEmitter, and you can listen to the following events:

  • start - Download started
  • progress - Download progress
  • paused - Download paused
  • resumed - Download resumed
  • canceled - Download canceled
  • completed - Download completed
  • converted - Conversion completed
  • error - Error occurred

Example:

downloader.on("progress", progress => {
  console.log(`Download progress: ${progress.downloaded}/${progress.total}`);
});

downloader.on("completed", () => {
  console.log("Download completed");
});

downloader.on("error", error => {
  console.error("Error occurred:", error);
});

License

MIT License