Files
encoderPro/setup-test-environment.sh
2026-01-24 17:43:28 -05:00

153 lines
4.9 KiB
Bash

#!/bin/bash
################################################################################
# TEST ENVIRONMENT SETUP
################################################################################
# This script creates a test environment with sample files to verify
# the re-encoding system works correctly before running on real data
################################################################################
set -euo pipefail
echo "=========================================="
echo "Setting up test environment"
echo "=========================================="
# Test directories
TEST_ROOT="/tmp/reencode-test"
TEST_MOVIES="$TEST_ROOT/movies"
TEST_ARCHIVE="$TEST_ROOT/archive"
TEST_WORK="$TEST_ROOT/work"
TEST_LOG="$TEST_ROOT/test.log"
# Clean up any existing test environment
if [[ -d "$TEST_ROOT" ]]; then
echo "Cleaning up existing test environment..."
rm -rf "$TEST_ROOT"
fi
# Create directory structure
echo "Creating test directories..."
mkdir -p "$TEST_MOVIES/Movie1 (2020)"
mkdir -p "$TEST_MOVIES/Movie2 (2021)/Special Features"
mkdir -p "$TEST_ARCHIVE"
mkdir -p "$TEST_WORK"
# Check if FFmpeg is available
if ! command -v ffmpeg &> /dev/null; then
echo "ERROR: FFmpeg not found. Please install FFmpeg first."
exit 1
fi
echo "Generating test video files..."
# Generate test video 1 (with subtitle track)
echo " Creating Movie1/movie.mkv (with subtitle track)..."
ffmpeg -f lavfi -i testsrc=duration=10:size=1280x720:rate=30 \
-f lavfi -i sine=frequency=1000:duration=10 \
-c:v libx264 -preset ultrafast -crf 23 \
-c:a aac -b:a 128k \
-metadata:s:s:0 language=eng \
-f srt -i <(cat <<'EOF'
1
00:00:00,000 --> 00:00:05,000
This is a test subtitle
2
00:00:05,000 --> 00:00:10,000
Second subtitle line
EOF
) \
-map 0:v -map 1:a -map 2:s \
-y "$TEST_MOVIES/Movie1 (2020)/movie.mkv" 2>/dev/null
# Generate test video 2 (MP4 format, with subtitle)
echo " Creating Movie2/movie.mp4 (with subtitle track)..."
ffmpeg -f lavfi -i testsrc=duration=5:size=1920x1080:rate=30 \
-f lavfi -i sine=frequency=500:duration=5 \
-c:v libx264 -preset ultrafast -crf 23 \
-c:a aac -b:a 128k \
-metadata:s:s:0 language=spa \
-f srt -i <(cat <<'EOF'
1
00:00:00,000 --> 00:00:03,000
Spanish subtitle test
2
00:00:03,000 --> 00:00:05,000
Another line
EOF
) \
-map 0:v -map 1:a -map 2:s \
-y "$TEST_MOVIES/Movie2 (2021)/movie.mp4" 2>/dev/null
# Generate test video 3 (bonus feature, no subtitles)
echo " Creating Movie2/Special Features/bonus.mkv (no subtitles)..."
ffmpeg -f lavfi -i testsrc=duration=3:size=640x480:rate=30 \
-f lavfi -i sine=frequency=800:duration=3 \
-c:v libx264 -preset ultrafast -crf 23 \
-c:a aac -b:a 128k \
-y "$TEST_MOVIES/Movie2 (2021)/Special Features/bonus.mkv" 2>/dev/null
echo ""
echo "Test environment created successfully!"
echo ""
echo "=========================================="
echo "Test Directory Structure:"
echo "=========================================="
tree "$TEST_MOVIES" 2>/dev/null || find "$TEST_MOVIES" -type f
echo ""
echo "=========================================="
echo "Verifying test files with ffprobe:"
echo "=========================================="
for file in $(find "$TEST_MOVIES" -type f -name "*.mkv" -o -name "*.mp4"); do
echo ""
echo "File: $file"
echo " Video streams: $(ffprobe -v error -select_streams v -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$file" | wc -l)"
echo " Audio streams: $(ffprobe -v error -select_streams a -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$file" | wc -l)"
echo " Subtitle streams: $(ffprobe -v error -select_streams s -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$file" | wc -l)"
done
echo ""
echo "=========================================="
echo "How to run the test:"
echo "=========================================="
cat <<'EOF'
# 1. First run in DRY RUN mode to verify:
MOVIES_DIR="/tmp/reencode-test/movies" \
ARCHIVE_DIR="/tmp/reencode-test/archive" \
WORK_DIR="/tmp/reencode-test/work" \
LOG_FILE="/tmp/reencode-test/test.log" \
DRY_RUN=1 \
./reencode-movies.sh
# 2. Then run for real:
MOVIES_DIR="/tmp/reencode-test/movies" \
ARCHIVE_DIR="/tmp/reencode-test/archive" \
WORK_DIR="/tmp/reencode-test/work" \
LOG_FILE="/tmp/reencode-test/test.log" \
./reencode-movies.sh
# 3. Verify results:
# Check that subtitles were removed:
for file in /tmp/reencode-test/movies/**/*.{mkv,mp4}; do
echo "Checking: $file"
ffprobe -v error -select_streams s -show_entries stream=codec_name "$file" 2>&1 | grep -q "Stream #" && echo " HAS SUBTITLES (BAD)" || echo " No subtitles (GOOD)"
done
# Check that originals are in archive:
ls -lR /tmp/reencode-test/archive/
# Review the log:
cat /tmp/reencode-test/test.log
# 4. Clean up when done:
rm -rf /tmp/reencode-test/
EOF
echo "=========================================="
echo "Test environment ready!"
echo "=========================================="