Skip to main content

m3u8downloader is a tool to download video at a m3u8 link. HTTP Live Streaming (HLS) is becoming popular. m3u8 playlist is used by HLS to serve video fragments of different quality to different clients. This tool supports HLS master playlist and media playlist. If master playlist is given, it selects the highest resolution automatically. HLS fragment encryption is supported. Resume from partial download is supported, just rerun the same command to continue.

ffmpeg is used to convert the downloaded fragments into final mp4 video file.

Installation

To install m3u8downloader, simply:

$ sudo apt install -y ffmpeg pipx
$ pipx install m3u8downloader

Quick Start

Example command line usage:

downloadm3u8 -o ~/Downloads/foo.mp4 https://example.com/path/to/foo.m3u8

If ~/.local/bin is not in $PATH, you can use full path:

~/.local/bin/downloadm3u8 -o ~/Downloads/foo.mp4 https://example.com/path/to/foo.m3u8

Here is built-in command line help:

usage: m3u8downloader [-h] [--user-agent USER_AGENT] [--origin ORIGIN] [--version]
                      [--debug] --output OUTPUT [--tempdir TEMPDIR] [--keep]
                      [--concurrency N]
                      URL

download video at m3u8 url

positional arguments:
  URL                   the m3u8 url

optional arguments:
  -h, --help            show this help message and exit
  --user-agent USER_AGENT
                        specify User-Agent header for HTTP requests
  --origin ORIGIN       specify Origin header for HTTP requests
  --version             show program's version number and exit
  --debug               enable debug log
  --output OUTPUT, -o OUTPUT
                        output video filename, e.g. ~/Downloads/foo.mp4
  --tempdir TEMPDIR     temp dir, used to store .ts files before combing them into mp4
  --keep                keep files in tempdir after converting to mp4
  --concurrency N, -c N
                        number of fragments to download at a time

Documentation

Config File Support

You may use a config file to specify some command line arguments.

  • supported config files, later takes precedence:

    • /etc/m3u8downloader.conf

    • /etc/m3u8downloader/m3u8downloader.conf

    • ~/.config/m3u8downloader.conf

    • ~/.config/m3u8downloader/m3u8downloader.conf

  • config file format

    # comments and empty lines are ignored.
    KEY=VALUE
    # or
    KEY="VALUE"
    # boolean values may be true|false|yes|no|1|0
  • supported keys:

    user_agent=<string>
    origin=<string>
    tempdir=<string>
    concurrency=<int>
    debug=<true|false>

    Their meaning is the same as their counterpart in command line arguments.

  • if a config is specified both in config file and command line arguments, command line arguments will take precedence.

Limitations

This tool only parses minimum m3u8 extensions for selecting media playlist from master playlist, downloading key and fragments from media playlist. If a m3u8 file doesn’t download correctly, it’s probably some new extension was added to the HLS spec which this tool isn’t aware of.

Bug Report

Bugs should be reported to github issues.

ChangeLog

  • v0.11.2

    • auto create target dir before running ffmpeg

  • v0.11.1

    • add –keep option to keep temp files after converting to mp4

    • bugfix: when on windows, properly delete temp dir when filename contains special characters.

  • v0.10.1

    • lifted lib version restriction

  • v0.10.0

    • add support for config file

    • handle Ctrl+C and SIGTERM properly

  • v0.9.0

    • add support for –user-agent and –origin parameters

  • v0.8.7

    • bugfix: do not rewrite KEY URI if it is already a local file path.

  • v0.8.6

    • fix a regression in v0.8.4. the v0.8.4 release should be avoided. Either use v0.8.3 or v0.8.6+

  • v0.8.4

    • minor bugfix: still try rewrite path when using m3u8 file from cache. when rewrite path in m3u8 file, do not rewrite if path has already been rewritten before. This is a minor change, it only fix things when process is killed when .m3u8 file is downloaded but path in it has not been rewritten yet.

  • v0.8.3

    • bugfix: ensure output file name and temp dir name is always valid for windows platform.

  • v0.8.1

    • bugfix: should rewrite key uri to local file path.

    • some bugfix for windows platform.

  • v0.8.0 2019-03-31

    • add logrotate for log handler

  • v0.7.8 2019-03-09

    • bugfix: fragment url rewrite fail for some cases

  • v0.7.7 2019-03-08

    • bugfix: always rewrite fragment url to local abs path

  • v0.7.5 2019-03-07

    • set default log level to INFO

  • v0.7.4 2019-03-07

    • initial release

Release files for m3u8downloader 0.11.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 m3u8downloader 0.11.3
File Size Uploaded
m3u8downloader-0.11.3.tar.gz 13.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for m3u8downloader 0.11.3
File Interpreter ABI Platform
m3u8downloader-0.11.3-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 26.2 kB

Release files / m3u8downloader-0.11.3.tar.gz

Download URL m3u8downloader-0.11.3.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
18ab9ac58a1345490d660e29f572b760ee790c861519189bc0aa056307caf159
BLAKE2b-256 checksum
How to use checksums
327980fa5c2dc0bccf1940693249499ad7ddac4894ffa691db36abab8c839443
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.2

Release files / m3u8downloader-0.11.3-py2.py3-none-any.whl

Download URL m3u8downloader-0.11.3-py2.py3-none-any.whl
Size 13.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
a19b6216c36dd8c538e1e42b2fb62957b5a0429374aa14089e783ac0b2959bab
BLAKE2b-256 checksum
How to use checksums
19f530542ca0176897a3e6df8306cb1e150ba5e093caff622aefa23e75848211
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.2

Release history Release notifications | RSS feed

This release

0.11.3 This release

2 release files

0.11.2

2 release files

0.11.1

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.6

2 release files

0.8.4

2 release files

0.8.0

2 release files

0.7.8

2 release files

0.7.7

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.3

2 release files

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