You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

38 lines
1.3 KiB

  1. #!/usr/bin/env zsh
  2. set -eu -o pipefail
  3. # Enable job control for wait-until-jobs-below
  4. set -m
  5. # Wait until the number of shell jobs drops below a limit.
  6. # This can be used as an alternative to parallel using
  7. # for i in ...; do something $i &; wait-until-jobs-below 8; done
  8. wait-until-jobs-below() {
  9. while test $(jobs | wc -l) -ge "$1"; do
  10. sleep 0.1
  11. done
  12. }
  13. # e.g. ~/stash/YouTube/whitehouse
  14. root=$1
  15. es x find -t f -- "$root" | take-wanted-ids ~/dead-video-ids | rg '\.(mp4|webm|flv|video)$' | while read i; do
  16. echo $i
  17. eye_path=$(path-to-eye-path "$i" | sed -r "s,$HOME/stash/,,g")
  18. file_id=$(es x info -- "$i" | jq .id)
  19. size=$(es x info -- "$i" | jq .size)
  20. # If already in namedfiles i.e. the-eye, skip
  21. es x info -- "$i" | rg -q -F '"type": "namedfiles"' && continue || true
  22. (
  23. es x get "$i" && \
  24. rclone --inplace --size-only --progress copyto "$i" "jeff:$eye_path" && \
  25. curl --fail-with-body -u "ya: ." -X POST -d "{\"file_id\": $file_id, \"location\": \"the-eye\", \"pathname\": \"$eye_path\"}" https://ya.borg.xyz/cgi-bin/new-namedfiles && \
  26. curl -X POST -d "{\"the_eye_any_bytes_saved\": $size, \"the_eye_video_bytes_saved\": $size, \"the_eye_any_files_saved\": 1, \"the_eye_video_files_saved\": 1}" "http://127.0.0.1:31416/metrics" || true
  27. ) &
  28. wait-until-jobs-below 9
  29. done