fast-dirpy
TypeScript icon, indicating that this package has built-in type declarations

0.1.9 • Public • Published

fast-dirpy

npm version JSR npm downloads JSDocs License

A simple library/CLI to download youtube(etc.) videos.

Supported Websites

And .m3u8 videos(using ffmpeg).

Installation

As a library

npm i fast-dirpy

# deno
deno add jsr:@vince-g/fast-dirpy

As a command line tool

npm i fast-dirpy -g

Usage

Config file

[!IMPORTANT] fast-dirpy.config can be fast-dirpy.config.['ts', 'mts', 'cts', 'js', 'mjs', 'cjs', 'json']

You can create a fast-dirpy.config file in your library root or same location in command line.

import { defineConfig } from 'fast-dirpy'

export default defineConfig({
  proxy: {
    protocol: 'http',
    host: '127.0.0.1',
    port: 7890,
  },
  timeout: 20000, // request timeout: 20s
  puppeteer: {
    // Path to Chrome. Please notice that you must give the inner unix executable file path in macOS.
    // /Applications/Google Chrome.app will not work.
    executablePath: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
    headless: true
  },
  // binary file path of ffmpeg
  // in Windows, use: "xx/ffmpeg.exe"
  // if no ffmpeg path given, it will rely on your env variable.
  ffmpeg: "./ffmpeg"
}

Use in command line

[!IMPORTANT]

  1. Some website listed in Supported Websites requires Google Chrome installed for Puppeteer use. You have to use a config file or give parameter of puppeteer executable path.
  2. .m3u8 source is handled by ffmpeg, please download it if you want to download .m3u8 videos.

Get Direct Link

# get video direct link
# Proxy:
#   -H, --proxyHost: proxy host
#   -P, --proxyPort: proxy port
#   -c, --config: Specified external config file.
#       e.g.: fast-dirpy get https://xxx -c ~/Downloads/fast-dirpy.config.json
#   --chromePath: Path to your Google Chrome browser.
fast-dirpy get https\://www.youtube.com/watch\?v\=6c28qWDMPBA -H 127.0.0.1 -P 7890

# Bilibili source doesn't need any proxy, so it's disabled by default.
fast-dirpy get https://www.bilibili.com/video/BV1TSPeeGE35

if you have set your proxy config in fast-dirpy.config.ts, you can omit proxy parameters:

fast-dirpy get https\://www.youtube.com/watch\?v\=6c28qWDMPBA

Download Video

[!IMPORTANT]

  1. Some website listed in Supported Websites requires Google Chrome installed for Puppeteer use. You have to use a config file or give parameter of puppeteer executable path.
  2. .m3u8 source is handled by ffmpeg, please download it if you want to download .m3u8 videos.
# get video direct link
# Path: --path, -p: Downloaded video save path.
#
# Proxy:
#  -H, --proxyHost: proxy host.
#  -P, --proxyPort: proxy port.
#  -c, --config: Specified external config file.
#       e.g.: fast-dirpy get https://xxx -c ~/Downloads/fast-dirpy.config.json
#  --chromePath: Path to your Google Chrome browser.
fast-dirpy download https\://www.youtube.com/watch\?v\=6c28qWDMPBA -p ./test.mp4  -H 127.0.0.1 -P 7890

# Bilibili source doesn't need any proxy, so it's disabled by default.
fast-dirpy download https://www.bilibili.com/video/BV1TSPeeGE35 -p ./test.mp4

m3u8 sources

fast-dirpy download https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8 -p ./test.mp4

if you have set your proxy config in fast-dirpy.config.ts, you can omit proxy parameters:

fast-dirpy download https\://www.youtube.com/watch\?v\=6c28qWDMPBA -p ./test.mp4

For further CLI help:

fast-dirpy --help

Download and parse .m3u8 files

Use as a library

[!IMPORTANT] If a website is listed in Supported Websites, then getXXXLink is to get direct link and downloadXXX is to download video.

import { downloadDirpy, remoteM3U8ToMP4, getBilibiliLink, getDirpyLink } from 'fast-dirpy'

// get direct link
const link = await getDirpyLink(
  {
    url: '<url>',
    cwd: '/path/to/external-config' // Optional: You can specify an external config file.
  },
  {
    host: '127.0.0.1',
    port: 7890
  }
)

// get bilibili direct link
const link = await getBilibiliLink(
  '<url>',
)

// download video
await downloadDirpy({
  url: '<url>',
  path: './download.mp4',
  cwd: '/path/to/external-config', // Optional: You can specify an external config file.
  proxy: {
    host: '127.0.0.1',
    port: 7890
  }
})

// download bilibili video
await downloadBilibili({
  url: '<url>',
  path: './myvideo.mp4'
})

// download `.m3u8` video
await remoteM3U8ToMP4({
  input: 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8',
  output: './test.mp4',
})

Test

To run single test case in Vitest, using:

pnpm run test src/test/xxx.test.ts:<line_number>

License

MIT License © 2025-PRESENT Vincent-the-gamer

Readme

Keywords

none

Package Sidebar

Install

npm i fast-dirpy

Weekly Downloads

5

Version

0.1.9

License

MIT

Unpacked Size

22.2 kB

Total Files

13

Last publish

Collaborators

  • vincent-the-gamer