#!/bin/sh
# This does all the FFmpeg magic we need
# to get distributable flac and mp3 files.
# Ada <ada@thingvellir.net> 2024, CC0-1.0

if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
	echo "usage: $0 source_file track_num title"
	exit 1
fi

tmp_file="$XDG_CACHE_HOME/${1}.wav"
furnace -output "${tmp_file}" "$1"

total_tracks=6
file_title="$(printf '%02i' $((${2}))) - ${3}"

ffmpeg -i "${tmp_file}" \
	-metadata title="${3}" \
	-metadata album='By Iron' \
	-metadata artist='Ada <ada@thingvellir.net>' \
	-metadata copyright='Creative Commons Zero' \
	-metadata author_url='https://thingvellir.net/' \
	-metadata track="$((${2}))/${total_tracks}" \
	-metadata date='2024' \
	"../${file_title}.flac" \
	-aq 4 \
	"../${file_title}.ogg" \
	-b:a 128K \
	"../${file_title}.mp3"

rm -f "$tmp_file"
