Created
April 7, 2026 21:04
-
-
Save maxsei/f88d7bf8fcfcaa5fffe03abffd7e9b60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| from pathlib import Path | |
| import os | |
| from typing import List | |
| from typing import TypedDict | |
| src = Path("/home/mschulte/Videos/39th-gate-music-video") | |
| dst = Path("/tmp/nix-shell.i4wVnT/tmp.0BRU2RIDOa/overlays") | |
| max_size_mb = 10_000 | |
| class Overlay(TypedDict): | |
| files: List[Path] | |
| size: int | |
| def main(): | |
| dst.mkdir(exist_ok=True) | |
| overlays: List[Overlay] = [] | |
| for file in src.rglob("*"): | |
| if not file.is_file(): | |
| continue | |
| size = file.stat().st_size | |
| if size >= max_size_mb * 1e6: | |
| raise ValueError(f"file size {size} exceeds {max_size_mb}mb size limit") | |
| if len(overlays) == 0: | |
| overlays = [{"files": [file], "size": size}] | |
| elif overlays[-1]["size"] + size >= max_size_mb * 1e6: | |
| overlays.append({"files": [file], "size": size}) | |
| else: | |
| overlays[-1]["files"].append(file) | |
| overlays[-1]["size"] += size | |
| for i, overlay in enumerate(overlays): | |
| for file in overlay["files"]: | |
| overlay_dst = dst / f"{src.name}-{i:03d}.part" / file.relative_to(src) | |
| overlay_dst.parent.mkdir(exist_ok=True, parents=True) | |
| overlay_dst.symlink_to(file) | |
| if __name__ == "__main__": | |
| main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment