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-dash-dl

v1.2.3

Published

HLS(.m3u8) and DASH(.mpd) video streaming download tool.

Downloads

444

Readme

hls-dash-dl

HLS(.m3u8) and DASH(.mpd) video streaming download tool.

Supports multiple audio tracks and multiple subtitle tracks.

Install

npm install hls-dash-dl

Usage

const HLS = "https://cdn.theoplayer.com/video/elephants-dream/playlist-single-audio.m3u8";
const DASH = "https://dash.akamaized.net/akamai/test/caption_test/ElephantsDream/elephants_dream_480p_heaac5_1_https.mpd";

const Downloader = require("hls-dash-dl");

const dl = new Downloader({
  ffmpegPath: "./bin/ffmpeg.exe",
  // quality: "highest", // "highest" | "medium" | "lowest"
  // concurrency: 5,
  // videoCodec: "copy",
  // audioCodec: "copy",
  // subtitleCodec: "srt",
  // clean: true,
});

dl.download(DASH, "./DASH.mkv").then((video_info) => {
  console.log(video_info);
});

dl.parse(HLS, "./HLS.mkv").then((video_info) => {
  console.log(video_info);
});
// handler example
dl.download(DASH, "./DASH.mkv", (event, data) => {
  if (event === "video_info") {
    const { video_info } = data;
  } else if (event === "ffmpeg_spawn") {
    const { process, cwd, command, args } = data;
  } else if (event === "ffmpeg_data") {
    // console.log(`Stderr: ${data.data}`);
  } else if (event === "ffmpeg_close") {
    const { code } = data;
  } else if (event === "ffmpeg_error") {
    const { error } = data;
  }
});
// logger example
const fs = require("node:fs");
const logFile = "./log.txt";
const dl = new Downloader({
  ffmpegPath: "./bin/ffmpeg.exe",
  // logger: console, // default
  // logger: null, // silence
  logger: {
    indentSize: 2,
    indent: 0,
    group(...args) {
      this.indent += 1;
      fs.appendFileSync(logFile, args.join(" ") + "\n");
    },
    groupEnd() {
      this.indent -= 1;
    },
    log(...args) {
      fs.appendFileSync(logFile, " ".repeat(this.indent * this.indentSize) + args.join(" ") + "\n");
    },
    error(...args) {
      this.log(...args);
    },
  },
});

API

new Downloader(options?)

options

  • ffmpegPath? string - FFmpeg executable file path (download here). Default by ffmpeg.exe (in the Path of the system environment variables).
  • outDir? string - Default output directory. Default by Downloads directory.
  • quality? string - Quality of video to download, can be highest | medium | lowest. Default by highest.
  • concurrency? number - Number of concurrent downloads of segments. Default by 5.
  • clean? boolean - Clear temporary files after download is complete. Default by true.
  • logger? console - Custom logger. Default by console. Set to null for silence.
  • videoCodec? string - Video Codec. Default by copy.
  • audioCodec? string - Audio Codec. Default by copy.
  • subtitleCodec? string - Subtitle Codec. Default by srt.

downloader.download(url, outFile, handler?): Promise

  • url string - HLS(.m3u8) or DASH(.mpd) manifest url.
  • outFile string - Output file path.
  • handler(event, data)? Function - Event handler.
    • ("video_info", { video_info }) - Manifest parsed.
    • ("ffmpeg_spawn", { process, cwd, command, args }) - Execute ffmpeg.
    • ("ffmpeg_close", { code }) - ffmpeg closed.
    • ("ffmpeg_error", { error }) - ffmpeg error.
    • ("ffmpeg_data", { data }) - ffmpeg stderr data.

Resolves with video_info.

downloader.parse(url, outFile): Promise

  • url string - HLS(.m3u8) or DASH(.mpd) manifest url.
  • outFile string - Output file path.

Resolves with video_info.

video_info

{
  ffmpegPath: './bin/ffmpeg.exe',
  outDir: 'C:\\Users\\ssnangua\\Downloads',
  quality: 'highest',
  videoCodec: 'copy',
  audioCodec: 'copy',
  subtitleCodec: 'srt',
  concurrency: 5,
  clean: true,
  logger: { /*...*/ },
  url: 'https://.../*.mpd',
  handler: (event, data) => { /*...*/ },
  manifest: { /*...*/ }, // dasha library Manifest object
  video: [
    {
      type: 'video',
      segments: [
        {
          url: 'https://.../*.mp4',
          file: 'E:\\GitHub\\hls-dash-dl\\DASH\\video0_Segment1.mp4',
          stat: 'waiting'
        },
        /*...*/
      ],
      file: 'E:\\GitHub\\hls-dash-dl\\DASH\\video0.mp4',
      bitrate: { /*...*/ },,
      quality: '480p',
      language: '',
      label: undefined
    }
  ],
  audio: [
    {
      type: 'audio',
      segments: [
        {
          url: 'https://.../*.mp4',
          file: 'E:\\GitHub\\hls-dash-dl\\DASH\\audio0_Segment1.mp4',
          stat: 'waiting'
        },
        /*...*/
      ],
      file: 'E:\\GitHub\\hls-dash-dl\\DASH\\audio0.mp4',
      bitrate: { /*...*/ },,
      quality: undefined,
      language: 'en',
      label: undefined
    },
    /*...*/
  ],
  text: [ // subtitle
    {
      type: 'text',
      segments: [
        {
          url: 'https://.../*.vtt',
          file: 'E:\\GitHub\\hls-dash-dl\\DASH\\text0_Segment1.vtt',
          stat: 'waiting'
        },
        /*...*/
      ],
      file: 'E:\\GitHub\\hls-dash-dl\\DASH\\text0.vtt',
      bitrate: { /*...*/ },
      quality: undefined,
      language: 'en',
      label: undefined
    },
    /*...*/
  ],
  tmpDir: 'E:\\GitHub\\hls-dash-dl\\tmp-DASH',
  name: 'DASH',
  ext: '.mkv',
  file: 'E:\\GitHub\\hls-dash-dl\\DASH.mkv'
}

See Also

dasha