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

dlm3u8

v2.0.4

Published

m3u8视频下载

Downloads

168

Readme

dlm3u8

介绍

m3u8 视频下载工具,只是很简单的下载工具,而且仅做了 AES 的 CBC 模式解密,其他的加密方式没做处理,仅供学习交流。

安装

npm install dlm3u8

# 或
npm install -g dlm3u8

使用示例 V1 版

import { DownLoader, ffmpegPath, ffprobePath } from "dlm3u8";

import Slogbar from "slog-progress";

let url = "https://xxxxxxxxxxx/index.m3u8";

let pb = new Slogbar("下载进度 :percent :bar :current/:total", 50);
let pb2 = new Slogbar("合并进度 :percent :bar :completedFormat/:totlFormat", 50);

new DownLoader({
	url, // 下载路径,必传
	fileName: "videoName", //输出的视频名称,不包括后缀
	outputDir: "./output", // 输出目录,最好写绝对路径,如path.join('/path/to/download')
	ffmpegPath, // ffmpeg的路径,必传,也可以用你自己的路径
	ffprobePath, // ffprobe的路径,必传,也可以用你自己的路径
	replace: true, // 是否替换已存在的视频文件,
	removeTmpDir: false, // 下载完成是否删除临时ts文件
	onDownloadProgress(info) {
		// 下载进度
		if (info.detail) {
			pb.render({
				current: info.detail.completed,
				total: info.detail.total,
			});
		} else {
			console.log(info.message);
		}
	},
	onDownloadEnd(info) {
		//下载结束
		console.log("\n下载分片完成");
		console.log(info);
	},
	onConvertProgress(info) {
		//合并进度
		pb2.render({
			current: info.detail.completed,
			total: info.detail.total,
			completedFormat: info.detail.completedFormat,
			totlFormat: info.detail.totalFormat,
		});
	},
	onConvertEnd(arg) {
		//合并结束
		console.log("\n合并完成");
	},
})
	.run()
	.then(() => {
		// 执行完回调
		console.log("done");
	})
	.catch((err) => {
		// 报错回调
		console.log(err);
		console.log("notdone");
	});

使用示例 V2 版

V2 和 V1 不兼容,有些属性删除了,V2 添加 stop 取消方法,监听事件继承 EventEmitter

事件名称 on(event: "download-start", listener: () => void): this; on(event: "download-end", listener: (info?: DownloadEndInfo) => void): this; on(event: "download-progress", listener: (info?: DownloadProgressInfo) => void): this; on(event: "download-error", listener: (error?: Error) => void): this; on(event: "convert-start", listener: () => void): this; on(event: "convert-end", listener: (outputPath?: string) => void): this; on(event: "convert-progress", listener: (info?: ConvertProgressInfo) => void): this; on(event: "convert-error", listener: (error?: Error) => void): this; on(event: "error", listener: (error?: Error) => void): this; on(event: "done", listener: (outputPath?: string) => void): this;

const { createDownloader, ffmpegPath, ffprobePath } = require("dlm3u8");

const Slogbar = require("slog-progress");
const path = require("path");

let url = "https://xxxxxxxxxxx/index.m3u8";

let pb = new Slogbar("下载进度 :percent :bar :current/:total", 50);
let pb2 = new Slogbar("合并进度 :percent :bar :completedFormat/:totlFormat", 50);

let task = createDownloader({
	url,
	fileName: "xxxx",
	outputDir: path.join(__dirname, "./output"),
	ffmpegPath,
	ffprobePath,
	replace: true,
	removeTmpDir: false,
	requestTimeout: 300000, // 分片请求的超时时间,默认300000,单位毫秒,不要设置太小,不然没下载完就超时,如果你的网速非常慢,你又不想等待太长时间,可以设置短一点超时时间,让它早点失败,≧◉◡◉≦,或者设置长一点,耐心的等下去
})
	.on("download-start", () => {
		console.log("下载开始");
	})
	.on("download-progress", (info) => {
		if (info.detail) {
			pb.render({
				current: info.detail.completed,
				total: info.detail.total,
			});
		} else {
			console.log(info.message);
		}
	})
	.on("download-end", (info) => {
		console.log("\n下载分片完成");
		console.log(info);
	})
	.on("convert-progress", (info) => {
		pb2.render({
			current: info.detail.completed,
			total: info.detail.total,
			completedFormat: info.detail.completedFormat,
			totlFormat: info.detail.totalFormat,
		});
	})
	.on("convert-end", () => {
		console.log("\n合并完成");
	})
	.on("error", (err) => {
		console.log(err);
	})
	.on("done", () => {
		console.log("完成");
	});

// ---------------------
//可以停止

task.start();

setTimeout(() => {
	task.stop();
}, 6000);

setTimeout(() => {
	task.start();
}, 12000);

setTimeout(() => {
	task.stop();
}, 18000);

setTimeout(() => {
	task.start();
}, 24000);

// ---------------------
// 使用promise,注意:每次调用startPromise()记得catch,start和startPromise都可以通过on监听事件,start()返回的是task实例,startPromise()返回的是promise

task.startPromise()
	.then(() => {
		console.log("完成");
	})
	.catch((err) => {
		console.log(err);
	});

命令使用示例

# 全局安装
npm install -g dlm3u8

# 使用

dlm3u8 -p m3u8的下载地址(必传) -f  输出的文件名,不包含后缀(可选)  -o 输出的目录(可选) -t  每个请求的总超时时间(可选,请勿设置太少,不然没下载完就超时,默认300000,单位毫秒,你觉得你的网速很慢的话,可以再调大点)