#!/bin/bash
# Complete workflow to fix missing stem/infill encodings
# Run this to identify and prepare for encoding missing files

set -e

echo "=========================================="
echo "Fix Missing Crow T1 Encodings - Workflow"
echo "=========================================="
echo ""

# Step 1: Generate complete audio list from pickle
echo "Step 1/2: Generating complete audio list from pickle file..."
echo "  - This extracts ALL clip IDs (main + stem + infill + conditions)"
echo ""

python3 /home/tony/Work/tony/RealGen/create_crow_t1_audio_list.py \
    --input-pkl /home/tony/Data/Preference/crow_t1/interesting_clips_crow_t1_20251030_full_slice.pkl \
    --audio-dir /app2/suno/data/dpo/audios/crow \
    --output /home/tony/Data/Preference/crow_t1/crow_t1_audio_list_complete.jsonl

echo ""
echo "✓ Complete audio list generated!"
echo ""

# Step 2: Find which files are missing encodings
echo "Step 2/2: Finding files missing NPZ encodings..."
echo ""

python3 /home/tony/Work/tony/RealGen/find_missing_encodings.py \
    --audio-list /home/tony/Data/Preference/crow_t1/crow_t1_audio_list_complete.jsonl \
    --encoded-dir /app2/suno/data/semantic_code/crow \
    --output /home/tony/Data/Preference/crow_t1/crow_t1_missing_encodings.jsonl

echo ""
echo "=========================================="
echo "Workflow Complete!"
echo "=========================================="
echo ""
echo "Next step:"
echo "  If there are missing files, submit encoding job:"
echo "  sbatch /home/tony/Work/tony/RealGen/submit_encode_crow_missing.sh"
echo ""
echo "Files created:"
echo "  - /home/tony/Data/Preference/crow_t1/crow_t1_audio_list_complete.jsonl"
echo "  - /home/tony/Data/Preference/crow_t1/crow_t1_missing_encodings.jsonl"
echo ""


