yt-dlf/scripts/create_zip.py
Stefan Waidele 3544a89609 Initial commit — yt-dlf YouTube downloader & transcript extractor
SvelteKit web frontend for yt-dlp and ffmpeg. Paste a YouTube URL to
download best-quality video, subtitles (original + EN + DE), and thumbnail.
Subtitles are converted to clean Markdown. Optional audio extraction to MP3.

Supports ZIP & Send mode: downloaded files are packed into a ZIP and
delivered to the browser, with optional server-side cleanup after delivery.
An extra directory (ZIP_EXTRA_DIR) can be bundled into every ZIP.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 20:33:23 +02:00

35 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python3
"""Create a ZIP archive from a directory, with an optional extra directory.
Usage: create_zip.py <source_dir> <output.zip> <archive_dir_name> [extra_dir]
Files from source_dir and (if given) extra_dir are both stored under
archive_dir_name/ in the ZIP, regardless of the actual directory names on disk.
"""
import sys
import zipfile
from pathlib import Path
if len(sys.argv) < 4:
print(f'Usage: {sys.argv[0]} <source_dir> <output.zip> <archive_dir_name> [extra_dir]', file=sys.stderr)
sys.exit(1)
source_dir = Path(sys.argv[1])
zip_path = sys.argv[2]
archive_name = sys.argv[3]
extra_dir = Path(sys.argv[4]) if len(sys.argv) >= 5 else None
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED, compresslevel=6) as zf:
for file_path in sorted(source_dir.rglob('*')):
if file_path.is_file():
arcname = Path(archive_name) / file_path.relative_to(source_dir)
zf.write(file_path, arcname)
if extra_dir and extra_dir.is_dir():
for file_path in sorted(extra_dir.rglob('*')):
if file_path.is_file():
arcname = Path(archive_name) / file_path.relative_to(extra_dir)
zf.write(file_path, arcname)
print(f'Created: {zip_path}')