#!/usr/bin/env zsh
set -x
set -e
set -o nullglob

YYYYMMDD="$(date "+%Y-%m-%d")"
DST="$HOME/_TODO/$YYYYMMDD-video-import"
RSYNCOPTS="-ah --no-inc-recursive --info=progress2"
LASDST="root@las1:/srv/las1/video"

function downloadVideos() {
    SRC=(/Volumes/*/PRIVATE/M4ROOT/CLIP)
    if [[ ! -d "$SRC" ]]; then
        echo "no videos" > /dev/stderr
        exit 1
    fi

    if [[ ! -n "$(ls -A "$SRC" 2>/dev/null)" ]]; then
        echo "no videos" > /dev/stderr
        exit 1
    fi

    mkdir -p "$DST"
    du -sh "$SRC"
    rsync \
        -ah --no-inc-recursive --info=progress2 \
        --remove-source-files "$SRC"/ $DST/
    cd "$DST"
    #mv */* .
    f2 -r '{{mtime.YYYY}}/{{mtime.YYYY}}-{{mtime.MM}}/{{mtime.YYYY}}-{{mtime.MM}}-{{mtime.DD}}/{{mtime.YYYY}}-{{mtime.MM}}-{{mtime.DD}}.{{f}}.{{hash.sha256}}{{ext}}' -x --verbose
}

function amLocalToLAS1() {
    ifconfig | grep 10.100.205 | wc -l
}


function main() {
    # FIXME this doesn't work if there are no photos on the card but the
    # DCIM dir exists
    downloadVideos
}

main
