FROM python:3.12-slim-bookworm

ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1

# Install mpv, ffmpeg and system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    mpv \
    ffmpeg \
    curl \
    ca-certificates \
    libgl1 \
    libegl1 \
    libx11-6 \
    libxext6 \
    libasound2 \
    pulseaudio-utils \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Install python dependencies and latest yt-dlp
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt yt-dlp

COPY src/ ./src/
COPY config.example.yaml ./config.example.yaml

# If no config.yaml exists at runtime, fallback to config.example.yaml
RUN cp config.example.yaml config.yaml

EXPOSE 8080 9090 8097 9777/udp

ENTRYPOINT ["python3", "-m", "src.main"]
CMD ["-c", "config.yaml"]
