#!/bin/zsh
# Moves saved replay clips out of the recordings folder into clips/.
# Run by the optional clip watcher whenever the recordings folder changes; safe to run by hand.
# Usage: clip-sort <stream-kit folder>
DIR=${1:?usage: clip-sort <stream-kit folder>}
RECS="$DIR/recordings"
CLIPS="$DIR/clips"
mkdir -p "$CLIPS"

for f in "$RECS"/Replay*.(mp4|mov|mkv)(N); do
  # OBS may still be writing the file; wait until its size stops changing.
  size1=$(stat -f %z "$f"); sleep 2; size2=$(stat -f %z "$f")
  [[ "$size1" != "$size2" ]] && continue
  mv "$f" "$CLIPS/"
done
