FROM python:3.12-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
    ffmpeg \
    aria2 \
    git \
    curl \
    unzip \
    && rm -rf /var/lib/apt/lists/*

# Install Bento4 (mp4decrypt)
RUN curl -L -o /tmp/bento4.zip https://www.bok.net/Bento4/binaries/Bento4-SDK-1-6-0-641.x86_64-unknown-linux.zip \
    && unzip /tmp/bento4.zip -d /tmp/bento4 \
    && cp /tmp/bento4/Bento4-SDK-1-6-0-641.x86_64-unknown-linux/bin/mp4decrypt /usr/local/bin/ \
    && chmod +x /usr/local/bin/mp4decrypt \
    && rm -rf /tmp/bento4 /tmp/bento4.zip

# Install votify (official, glomatico). The [librespot] extra is required for the
# default --session-type librespot.
RUN pip install --no-cache-dir websocket-client \
    "votify[librespot] @ git+https://github.com/glomatico/votify.git"

# Install web app dependencies
COPY requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r /app/requirements.txt

COPY app.py /app/app.py
COPY db.py /app/db.py
COPY utils.py /app/utils.py
COPY templates /app/templates
COPY static /app/static
COPY monochrome /app/monochrome

WORKDIR /app

RUN mkdir -p /downloads /config /tmp/votify

EXPOSE 5000

CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "1", "--threads", "4", "app:app"]
