at main 767 B view raw
1#!/usr/bin/env bash 2# Simple helper to POST an audio file to the local transcoder API and save the result. 3set -euo pipefail 4 5if [[ $# -lt 1 ]]; then 6 echo "usage: $(basename "$0") <input-file> [output-file]" >&2 7 exit 1 8fi 9 10INPUT_FILE="$1" 11if [[ $# -ge 2 ]]; then 12 OUTPUT_FILE="$2" 13else 14 OUTPUT_FILE="$(basename "${INPUT_FILE%.*}").mp3" 15fi 16PORT="${TRANSCODER_PORT:-8082}" 17AUTH_TOKEN="${TRANSCODER_AUTH_TOKEN:-}" 18 19CURL_ARGS=( 20 --fail 21 --silent 22 --show-error 23 -X POST 24 -F "file=@${INPUT_FILE}" 25) 26 27# add auth header if token is set 28if [[ -n "${AUTH_TOKEN}" ]]; then 29 CURL_ARGS+=(-H "X-Transcoder-Key: ${AUTH_TOKEN}") 30fi 31 32curl "${CURL_ARGS[@]}" \ 33 "http://127.0.0.1:${PORT}/transcode?target=mp3" \ 34 --output "${OUTPUT_FILE}" 35 36echo "wrote ${OUTPUT_FILE}" >&2