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

m3u8-multi-thread-downloader

v1.0.1

Published

use node.js download m3u8 to mp4 by thread pool.

Downloads

4

Readme

m3u8 Downloader (m3u8文件下载器)

本项目fork自:m3u8Downloader,但发现之前的项目实际上用的是单线程执行的,是假的多线程,也不稳定。所以采用了Node真正意义上的多线程来处理。

目前有以下特性:

  • 采用了Worker Thread
  • 采用了WorkerPool,支持自定义并发线程数量,示例采用:Using AsyncResource for a Worker thread pool ,并解决了当失败后不能重启任务的问题。
  • 网络请求框架变为axios
  • 支持参数化运行
  • 增加了下载进度条
  • 增加了已下载文件检测,避免重复下载
  • 重构了文件清理逻辑,支持unix与windows

Tip: 在运行时,需要提前安装好*FFMPEG环境,并设置好环境变量。

Warm: 在通过Node运行时需要在node后面添加--experimental-worker参数才可以正常运行,否则回报Cannot find module 'worker_threads'错误。例如: node --experimental-worker index.js

How to use

const downloader = require('m3u8-multi-thread-downloader');

downloader.download({
    url: 'https://www.hkg.haokan333.com/201903/07/qM3F7ntN/800kb/hls/index.m3u8',
    processNum: 4, // 同时开启的线程数,线程不宜开的过多,否则容易造成资源无法正常下载的情况
    filePath: 'video', // 所存放的文件夹
    fileName: 'baby' // 视频资源的文件名
});

支持参数化的方式:

node  --experimental-worker .\download.js --url=https://www.hkg.haokan333.com/201903/07/qM3F7ntN/800kb/hls/index.m3u8 --path=video --name=baobaby --deleteTemp=false --process=8

支持的参数有:

--url 下载的m3u8文件路径
--process 下载的线程数,不宜过多,4个很稳定,取决于服务器的并发措施
--path 文件存放路径, 默认为:video
--name 文件合并后的名称, 谨慎使用非英文字符, 默认为:video
--deleteTemp 是否在处理完抽删除临时文件, 默认为: true

下载时的进度展示:

  Downloading:97% [=================================================================================================---]  Current:101 Total:104 当前用时:54.2s 剩余时长:1.6

完整的运行日志:

node  --experimental-worker .\download.js --url=https://www.hkg.haokan333.com/201903/07/qM3F7ntN/800kb/hls/index.m3u8 --path=video2 --name=baobaby --deleteTemp=false --process=8
已初始化线程池,线程数量为: 8
开始解析m3u8文件...
解析成功,开始下载...
  Downloading:100% [====================================================================================================]  Current:104 Total:104 当前用时:0.0s 剩余时长:0.0s
正在合并ts为mp4...
1. FFMPEG mp4 0处理完成.
2. FFMPEG mp4 1处理完成.
所有FFMPEG处理完成.

希望可以帮助大家下载到喜欢的资源,有问题可以联系我:[email protected] ^-^