4.6 KiB
yt-dlp Download Manager (Textual TUI)
A small Textual user interface around a
specific yt-dlp workflow: enter a film
URL, inspect the m3u8_native formats yt-dlp reports for it, pick the
part(s) to download, and download (merging audio/video with ffmpeg when
they come as separate streams).
Requirements
-
Python 3.10+
-
yt-dlpandffmpegavailable on yourPATH(ffmpegis a system package, not a Python one — install it with your OS package manager, e.g.apt install ffmpeg/brew install ffmpeg). -
Python packages from
requirements.txt:pip install -r requirements.txt
Running
python main.py
Project layout
main.py Entry point; wires up i18n, then starts the app
app/
tui_app.py The Textual App: layout + all screen wiring
models.py FormatEntry / VideoInfo + the filtering logic
that decides split vs. combined audio/video
ytdlp_client.py async wrappers for `yt-dlp --dump-json` and
`yt-dlp -f <id> -o <file>` (with progress)
ffmpeg_client.py async wrapper for the `ffmpeg -c copy` merge
screens/
format_select_screen.py Modal format-selection table (audio & video)
error_screen.py Modal error dialog
lib/i18n/ The provided i18n library (unmodified aside from
a small `__init__.py` re-export so that
`from i18n import I18n` works as documented)
i18n/en/, i18n/de/ This application's own translation data
(strings.json + help.md), as expected by the
library at <project_root>/i18n/<lang>/
The i18n library is kept in lib/i18n (added to sys.path by
main.py), separate from the i18n data directory i18n/ at the project
root, since the library expects its translation data at
<project_root>/i18n/<lang>/strings.json — the same name as the library's
own package directory would use if it were placed at the project root.
How the app maps to the requirements
- Info gathering —
yt-dlp -i --dump-json <url>is run inytdlp_client.fetch_info. Only formats withprotocol == "m3u8_native"are kept (models.VideoInfo.from_json); anything else (includinghttps) is discarded. - Split vs. combined — if any surviving format has
resolution == "audio only", the film is treated as split and two selection dialogs are shown (audio, then video). Otherwise a single dialog is shown. - Selection dialogs —
screens/format_select_screen.pyrenders a table withformat_id,resolution,acodec,vcodec,format. Cancelling, pressing Escape, or an empty table all resolve to "no valid entry", which the main screen turns into an error dialog and a disabled Start download button. - Main screen — shows
Audio: .../Video: ...lines (underscores in the format text replaced with spaces), a progress line + bar, and the three buttons from the layout sketch. - Downloading —
yt-dlp -i url -o filename -f stream_id, run with--newlinesoytdlp_client.downloadcan parse[download] NN.N%lines and call back into the UI at most once per whole percentage point. The progress text is<fulltitle> - Audio|Video|Audio + Video - NN%. - Merging — for split downloads, both parts land in temporary files
next to the destination; once both finish,
ffmpeg -i video -i audio -c copy <destination>merges them, after which the temp files are deleted (in afinallyblock, so this also happens if something fails partway through). - Async — all subprocess-driving and status-bar-updating code
(
select_parts,start_download, theytdlp_client/ffmpeg_clientfunctions, and the progress callbacks) isasyncand is launched from button presses via Textual workers so the UI stays responsive.
Notes / assumptions
- The two example JSON documents from the requirements are used as the basis for the filtering logic and are exercised by an ad-hoc test during development; there is no bundled test suite since none was requested.
- Temporary files for split downloads are named
<destination-stem>.video.tmp.mp4/<destination-stem>.audio.tmp.mp4next to the destination file. - If "Select parts" is used again after a successful selection, the previous selection is only replaced once a new one completes successfully; cancelling out of the new attempt clears the selection and disables Start download, matching "no default selection".