#!/bin/bash
# 笔标注成片出来后：传 OCS（视频N_hand_pen_annotated.mp4）+ 各抽 2 帧质检图传 OCS
# 用法：笔标注 4 个全 done 后再跑本脚本
set -u
cd /home/agent/.claude/workspace/project
FF=$(python3 -c "import imageio_ffmpeg; print(imageio_ffmpeg.get_ffmpeg_exe())")
while read -r shipin pen_id; do
  out=$(ls data/out/${pen_id}/*.mp4 2>/dev/null | head -1)
  echo "=== ${shipin} pen_job=${pen_id} out=${out} ==="
  if [ -z "$out" ] || [ ! -f "$out" ]; then echo "SKIP ${shipin}: pen output not found"; continue; fi
  ls -la "$out"
  md5sum "$out"
  n=${shipin#shipin}
  enc=$(python3 -c "import urllib.parse; print(urllib.parse.quote('视频${n}_hand_pen_annotated.mp4'))")
  curl -s --upload-file "$out" "https://ocs.dimond.top/${enc}"
  echo "uploaded 视频${n}_hand_pen_annotated.mp4"
  "$FF" -hide_banner -loglevel error -y -ss 20 -i "$out" -frames:v 1 -q:v 3 "qc/${shipin}_final_20s.jpg"
  "$FF" -hide_banner -loglevel error -y -ss 60 -i "$out" -frames:v 1 -q:v 3 "qc/${shipin}_final_60s.jpg"
  curl -s --upload-file "qc/${shipin}_final_20s.jpg" "https://ocs.dimond.top/${shipin}_final_20s.jpg"
  curl -s --upload-file "qc/${shipin}_final_60s.jpg" "https://ocs.dimond.top/${shipin}_final_60s.jpg"
  echo "qc frames uploaded for ${shipin}"
done < pen_job_ids.txt
echo "FINALS DONE"
