kaledonya clips: a Discord-friendly clip site on top of Zipline

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
esefandClaude Opus 5.5 committed 2026-10-07 20:46:48 +03:00
commit e6f8905377
34 files changed
+2917

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
"""Filename rules for uploads: spaces become dashes, duplicates get -2, -3, ..."""
import os
import re
from collections.abc import Callable
def clean_name(filename: str) -> str:
"""Keep only the base name and turn every run of whitespace into one dash."""
base = filename.replace("\\", "/").rsplit("/", 1)[-1].strip()
base = re.sub(r"\s+", "-", base)
return base or "upload"
def split_name(name: str) -> tuple[str, str]:
"""('clip', '.mp4'); a name with no extension gives ('README', '')."""
return os.path.splitext(name)
def next_free_name(stem: str, ext: str, exists: Callable[[str], bool], limit: int = 1000) -> str:
"""First of stem+ext, stem-2+ext, stem-3+ext, ... that does not exist yet."""
for n in range(1, limit + 1):
name = f"{stem}{ext}" if n == 1 else f"{stem}-{n}{ext}"
if not exists(name):
return name
raise RuntimeError(f"no free name for {stem}{ext} after {limit} tries")