#!/bin/bash

# Check if a directory path is provided as an argument
if [ -z "$1" ]; then
  echo "Usage: $0 <directory_path>"
  exit 1
fi

# Set the directory to search
DIRECTORY="$1"
OUTPUT_FILE="$(pwd)/output.csv"

# Initialize the output CSV file
echo -n "" > "$OUTPUT_FILE"

# Function to find .mp4 files recursively
find_mp4_files() {
  while IFS= read -r -d '' file; do
    echo "$file" >> temp_output.txt
  done < <(find "$DIRECTORY" -type f -name "*.mp4" -print0)
}

# Run the search
find_mp4_files

# Convert the list to CSV format
if [ -f temp_output.txt ]; then
  paste -sd, temp_output.txt > "$OUTPUT_FILE"
  rm temp_output.txt
fi

# Display the CSV output
cat "$OUTPUT_FILE"
