#!/bin/bash
AUDIO_DIR="/home/user/adhan"
NUM="${1:-1}"
URL="http://www.islamcan.com/audio/adhan/azan${NUM}.mp3"
OUTPUT="$AUDIO_DIR/adhan.mp3"
echo "Downloading adhan audio (azan${NUM}.mp3)..."
echo "URL: $URL"
echo "Output: $OUTPUT"
cd "$AUDIO_DIR" || exit 1
if command -v wget &>/dev/null; then
    wget -O "$OUTPUT" "$URL"
elif command -v curl &>/dev/null; then
    curl -L -o "$OUTPUT" "$URL"
else
    echo "ERROR: Neither wget nor curl found!"
    exit 1
fi
if [ -f "$OUTPUT" ] && [ -s "$OUTPUT" ]; then
    SIZE=$(stat -c%s "$OUTPUT" 2>/dev/null || stat -f%z "$OUTPUT" 2>/dev/null)
    echo "Downloaded successfully: $OUTPUT (${SIZE} bytes)"
else
    echo "ERROR: Download failed or file is empty"
    exit 1
fi
