Skip to main content
# M3u8‑Tool
批量下载 m3u8 视频,支持 AES‑128 解密、自动过滤内容完全相同的广告 TS 分片;**支持交互式菜单 + 命令行参数两种模式**。

> ⚠️ 提示:本工具仅限个人学习研究使用,请勿用于下载、传播受版权保护的影视资源。

## 安装、更新
```powershell
# 安装
py -m pip install m3u8-dl-tool

# 更新到最新版本
pip install --upgrade m3u8-dl-tool

# 指定版本更新
pip install --upgrade m3u8_dl-tool==0.2.0

快速开始

✨交互式菜单模式(推荐普通用户)

终端直接执行,不带任何参数,会弹出交互式菜单:

m3u8dl

菜单功能:

  1. 完整运行【下载+合并+删除TS】
  2. 调试模式(分步执行:仅下载 / 仅合并 / 仅清理;子菜单内可查看、修改运行配置)
  3. 重新加载任务JSON
  4. 退出程序

首次运行,若目录不存在 m3u8_url.json,工具会自动生成示例模板文件,编辑填入视频信息后再执行下载。

JSON任务文件示例

文件名:m3u8_url.json

兼容旧字段url,也支持新字段m3u8_url,两种写法都可识别

[
    {
        "title": "第一集",
        "url": "[https://example.com/video/index.m3u8](https://example.com/video/index.m3u8)"
    },
    {
        "title": "第二集",
        "m3u8_url": "[https://example.com/video/episode2.m3u8](https://example.com/video/episode2.m3u8)"
    }
]

生成目录结构(工作目录下自动创建)

工作目录/
├─ m3u8_url.json      # 下载任务列表
├─ fail_task.json     # 下载失败任务自动记录
├─ ts/                 # ts分片临时缓存目录
└─ MP4/               # 输出mp4视频存放目录

📃命令行参数模式(脚本/批处理自动化,带参数则直接执行下载,不弹出菜单)

查看命令帮助:

m3u8dl -h
# 或者
m3u8dl --help

命令行选项

选项 说明
--base-dir 配置文件和输出目录,默认使用当前终端目录
--json 指定视频列表 JSON 文件;默认是 base‑dir 下的 m3u8_url.json
--start‑index 下载起始索引,从 0 开始,默认是 0
--end‑index 下载结束索引,不包含该索引;默认下载到列表末尾
--max‑workers TS 分片并发下载线程数,默认是 30
--retry‑times HTTP请求最大重试次数,默认 6
-h, --help 显示帮助信息

命令行示例

m3u8dl --base-dir "D:\Videos" --json "series.json" --start-index 0 --end-index 5 --max-workers 10 --retry-times 4

在Python程序代码中调用(库API调用,不会弹出菜单)

from m3u8dl.M3u8DL import M3u8Downloader

app = M3u8Downloader(
    max_workers=10,
    base_dir=r"D:\Videos",
    retry_times=6,
    retry_sleep_range=(0.5, 1)
)

# 执行全部任务:下载‑合并‑清理完整流程
app.run()

# 也支持分步调用
# app.load_video_json()
# app.download_ts(is_debug=False, skip_load_json=True)
# app.merge_mp4(is_debug=False, skip_load_json=True)
# app.clean_ts(is_debug=False, skip_load_json=True)

依赖

安装包的时候pip会自动安装依赖,无需手动安装:

  • requests
  • pycryptodome

运行逻辑说明

  1. 任意ts分片多次重试全部失败,该视频标记为失败,写入fail_task.json,不会生成残缺损坏的mp4文件;
  2. 自动通过sha256哈希识别、删除重复广告ts分片;
  3. 不依赖ffmpeg,直接二进制拼接ts输出mp4;
  4. 支持master多级嵌套m3u8索引;
  5. 支持AES‑128加密流解密;

源码直接运行(开发调试)

直接执行源码文件,启动交互式菜单:

python M3u8DL.py

注意事项

  1. 修改配置(线程数、重试次数)仅内存生效,程序退出后丢失;
  2. fail_task.json记录下载失败的视频,可复制里面条目到m3u8_url.json重试下载失败剧集;
  3. 程序不会自动清理旧的失败记录,每次启动会重置失败任务列表。

Metadata

Release files for m3u8-dl-tool 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for m3u8-dl-tool 0.2.3
File Size Uploaded Provenance Actions
m3u8_dl_tool-0.2.3.tar.gz 15.5 kB Without provenance Details for m3u8_dl_tool-0.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for m3u8-dl-tool 0.2.3
File Interpreter ABI Platform Actions
m3u8_dl_tool-0.2.3-py3-none-any.whl Python 3 none any Details for m3u8_dl_tool-0.2.3-py3-none-any.whl

Total release size: 31.4 kB

Release files / m3u8_dl_tool-0.2.3.tar.gz

Download URL m3u8_dl_tool-0.2.3.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0fd0bb70d3bfe27e949b75c52e3460fe256f32056ae8f94e9572a1979864ad39
BLAKE2b-256 checksum
How to use checksums
5f82c0663ca8f0e372d22ca5710369f1dde9ff08674d0686d7458d8a6d3f9326
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Release files / m3u8_dl_tool-0.2.3-py3-none-any.whl

Download URL m3u8_dl_tool-0.2.3-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea8541b7227705738b03765c4a455311e3960f80893376bb801fc45390cf0332
BLAKE2b-256 checksum
How to use checksums
3a4fe7de3c529f3cdc1c658a54bcc27e3d0915a6b5ab02c99d545b222c104643
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Security for m3u8-dl-tool 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page