#!/bin/bash -e
IFS=$'\n'
INPUT_DIR="$1"
OUTPUT_DIR="$2"
# Script used to transcode a directory
# full of .flac files to .ogg
if [[ -z "$INPUT_DIR" ]] || [[ -z "$OUTPUT_DIR" ]]; then
    echo "./transcode_flac_dir.sh <input directory> <output directory>"
    exit 1
fi

ALL_FILES=$(find "$INPUT_DIR" -name "*flac")

for item in $ALL_FILES;
do
    local_filename="${item//$INPUT_DIR/}"
    replaced_dir="${item//$INPUT_DIR/$OUTPUT_DIR}"
    output_file="${replaced_dir//.flac/.ogg}"
    if [ -f "$output_file" ]; then
      echo "Skipping $local_filename"
      continue
    fi
    echo "Encoding $local_filename"
    oggenc -q 6 -Q -o $output_file $item
done

exit 0
