# romhackman/m3u8-downloader architecture

> Architecture diagram of the GitHub repository romhackman/m3u8-downloader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/romhackman/m3u8-downloader
- Repository: https://github.com/romhackman/m3u8-downloader

## Overview

This repository is a small command-line video discovery and download toolkit. Its principal path is scanning a page and its iframes for HLS links, saving them to JSON, then loading that cache and invoking yt-dlp/ffmpeg to produce MP4 files. A separate crawler extracts MP4/HLS candidates and uses yt-dlp as a fallback. The source excerpts show these calls and transfers; optional cookies and external tools are documented in the README.

Main entry points: [`d_mp4.py`](https://github.com/romhackman/m3u8-downloader/blob/main/d_mp4.py) (Video crawler), [`d_m3u8.py`](https://github.com/romhackman/m3u8-downloader/blob/main/d_m3u8.py) (Download CLI), [`video.py`](https://github.com/romhackman/m3u8-downloader/blob/main/video.py) (HLS finder), [`help.py`](https://github.com/romhackman/m3u8-downloader/blob/main/help.py) (Usage banner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_discovery["Video discovery"]
  node_finder["HLS finder<br/>[video.py]"]
  node_page_scan["Page scan<br/>[video.py]"]
  node_iframe_scan["Iframe scan<br/>[video.py]"]
  node_crawler["Video crawler<br/>[d_mp4.py]"]
  node_html_extract["HTML extraction<br/>[d_mp4.py]"]
  node_regex_extract["Regex extraction<br/>[d_mp4.py]"]
  node_js_extract["JavaScript extraction<br/>[d_mp4.py]"]
  node_iframe_extract["Iframe extraction<br/>[d_mp4.py]"]
  node_help["Usage banner<br/>[help.py]"]
end

subgraph group_downloads["Downloads"]
  node_cache_reader["Cache reader<br/>[d_m3u8.py]"]
  node_download_cli["Download CLI<br/>[d_m3u8.py]"]
  node_command_builder["Command builder<br/>[d_m3u8.py]"]
  node_download_runner["Download runner<br/>[d_m3u8.py]"]
  node_file_lister["MP4 lister<br/>[d_m3u8.py]"]
  node_crawler_download["Crawler fallback<br/>[d_mp4.py]"]
end

subgraph group_state["Cache and output"]
  node_cache[("JSON cache<br/>[cache.json]")]
  node_output_files[("MP4 files")]
  node_cookies["cookies.txt"]
end

node_user(("CLI user"))
node_yt_dlp["yt-dlp"]
node_ffmpeg["ffmpeg"]

node_user -->|"runs scan"| node_finder
node_finder -->|"scans page"| node_page_scan
node_page_scan -->|"scans iframes"| node_iframe_scan
node_finder -->|"writes links"| node_cache
node_user -->|"runs download"| node_download_cli
node_download_cli -->|"loads cache"| node_cache_reader
node_cache_reader -->|"reads JSON"| node_cache
node_download_cli -->|"builds command"| node_command_builder
node_download_cli -->|"runs command"| node_download_runner
node_download_runner -->|"requests command"| node_command_builder
node_command_builder -->|"adds cookies"| node_cookies
node_download_runner -->|"invokes"| node_yt_dlp
node_yt_dlp -->|"uses downloader"| node_ffmpeg
node_download_runner -->|"writes MP4"| node_output_files
node_download_cli -->|"lists downloads"| node_file_lister
node_file_lister -->|"reads directory"| node_output_files
node_user -->|"enters URL"| node_crawler
node_crawler -->|"extracts tags"| node_html_extract
node_crawler -->|"extracts links"| node_regex_extract
node_crawler -->|"extracts sources"| node_js_extract
node_crawler -->|"follows iframes"| node_iframe_extract
node_crawler -->|"downloads on hits"| node_crawler_download
node_crawler_download -->|"invokes fallback"| node_yt_dlp
node_help -->|"shows usage"| node_finder
node_help -->|"shows usage"| node_download_cli

click node_finder "https://github.com/romhackman/m3u8-downloader/blob/main/video.py"
click node_page_scan "https://github.com/romhackman/m3u8-downloader/blob/main/video.py"
click node_iframe_scan "https://github.com/romhackman/m3u8-downloader/blob/main/video.py"
click node_crawler "https://github.com/romhackman/m3u8-downloader/blob/main/d_mp4.py"
click node_html_extract "https://github.com/romhackman/m3u8-downloader/blob/main/d_mp4.py"
click node_regex_extract "https://github.com/romhackman/m3u8-downloader/blob/main/d_mp4.py"
click node_js_extract "https://github.com/romhackman/m3u8-downloader/blob/main/d_mp4.py"
click node_iframe_extract "https://github.com/romhackman/m3u8-downloader/blob/main/d_mp4.py"
click node_cache "https://github.com/romhackman/m3u8-downloader/blob/main/cache.json"
click node_cache_reader "https://github.com/romhackman/m3u8-downloader/blob/main/d_m3u8.py"
click node_download_cli "https://github.com/romhackman/m3u8-downloader/blob/main/d_m3u8.py"
click node_command_builder "https://github.com/romhackman/m3u8-downloader/blob/main/d_m3u8.py"
click node_download_runner "https://github.com/romhackman/m3u8-downloader/blob/main/d_m3u8.py"
click node_file_lister "https://github.com/romhackman/m3u8-downloader/blob/main/d_m3u8.py"
click node_crawler_download "https://github.com/romhackman/m3u8-downloader/blob/main/d_mp4.py"
click node_help "https://github.com/romhackman/m3u8-downloader/blob/main/help.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_finder,node_page_scan,node_iframe_scan,node_crawler,node_html_extract,node_regex_extract,node_js_extract,node_iframe_extract,node_help,node_user toneBlue
class node_cache_reader,node_download_cli,node_command_builder,node_download_runner,node_file_lister,node_crawler_download toneAmber
class node_cache,node_output_files,node_cookies toneMint
class node_yt_dlp,node_ffmpeg toneIndigo
```

## Components

### Video discovery

- [HLS finder](https://github.com/romhackman/m3u8-downloader/blob/main/video.py): `video.py`
- [Page scan](https://github.com/romhackman/m3u8-downloader/blob/main/video.py): `video.py`
- [Iframe scan](https://github.com/romhackman/m3u8-downloader/blob/main/video.py): `video.py`
- [Video crawler](https://github.com/romhackman/m3u8-downloader/blob/main/d_mp4.py): `d_mp4.py`
- [HTML extraction](https://github.com/romhackman/m3u8-downloader/blob/main/d_mp4.py): `d_mp4.py`
- [Regex extraction](https://github.com/romhackman/m3u8-downloader/blob/main/d_mp4.py): `d_mp4.py`
- [JavaScript extraction](https://github.com/romhackman/m3u8-downloader/blob/main/d_mp4.py): `d_mp4.py`
- [Iframe extraction](https://github.com/romhackman/m3u8-downloader/blob/main/d_mp4.py): `d_mp4.py`
- [Usage banner](https://github.com/romhackman/m3u8-downloader/blob/main/help.py): `help.py`

### Downloads

- [Cache reader](https://github.com/romhackman/m3u8-downloader/blob/main/d_m3u8.py): `d_m3u8.py`
- [Download CLI](https://github.com/romhackman/m3u8-downloader/blob/main/d_m3u8.py): `d_m3u8.py`
- [Command builder](https://github.com/romhackman/m3u8-downloader/blob/main/d_m3u8.py): `d_m3u8.py`
- [Download runner](https://github.com/romhackman/m3u8-downloader/blob/main/d_m3u8.py): `d_m3u8.py`
- [MP4 lister](https://github.com/romhackman/m3u8-downloader/blob/main/d_m3u8.py): `d_m3u8.py`
- [Crawler fallback](https://github.com/romhackman/m3u8-downloader/blob/main/d_mp4.py): `d_mp4.py`

### Cache and output

- [JSON cache](https://github.com/romhackman/m3u8-downloader/blob/main/cache.json): `cache.json`
- **MP4 files**
- **cookies.txt**

### Other components

- **CLI user**
- **yt-dlp**
- **ffmpeg**

## Connections

- CLI user → HLS finder: runs scan (evidence: `README.md`)
- HLS finder → Page scan: scans page (evidence: `video.py`)
- Page scan → Iframe scan: scans iframes (evidence: `video.py`)
- HLS finder → JSON cache: writes links (evidence: `video.py`)
- CLI user → Download CLI: runs download (evidence: `README.md`)
- Download CLI → Cache reader: loads cache (evidence: `d_m3u8.py`)
- Cache reader → JSON cache: reads JSON (evidence: `d_m3u8.py`)
- Download CLI → Command builder: builds command (evidence: `d_m3u8.py`)
- Download CLI → Download runner: runs command (evidence: `d_m3u8.py`)
- Download runner → Command builder: requests command (evidence: `d_m3u8.py`)
- Command builder → cookies.txt: adds cookies (evidence: `d_m3u8.py`)
- Download runner → yt-dlp: invokes (evidence: `d_m3u8.py`)
- yt-dlp → ffmpeg: uses downloader
- Download runner → MP4 files: writes MP4 (evidence: `d_m3u8.py`)
- Download CLI → MP4 lister: lists downloads (evidence: `d_m3u8.py`)
- MP4 lister → MP4 files: reads directory (evidence: `d_m3u8.py`)
- CLI user → Video crawler: enters URL (evidence: `README.md`)
- Video crawler → HTML extraction: extracts tags (evidence: `d_mp4.py`)
- Video crawler → Regex extraction: extracts links (evidence: `d_mp4.py`)
- Video crawler → JavaScript extraction: extracts sources (evidence: `d_mp4.py`)
- Video crawler → Iframe extraction: follows iframes (evidence: `d_mp4.py`)
- Video crawler → Crawler fallback: downloads on hits (evidence: `d_mp4.py`)
- Crawler fallback → yt-dlp: invokes fallback (evidence: `d_mp4.py`)
- Usage banner → HLS finder: shows usage (evidence: `help.py`)
- Usage banner → Download CLI: shows usage (evidence: `help.py`)
