FROM python:3.11-slim

WORKDIR /app

# Install dependencies
RUN apt-get update && apt-get install -y \
    ffmpeg \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy application files
COPY . .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt 2>/dev/null || pip install --no-cache-dir \
    flask \
    requests \
    gunicorn \
    m3u8 \
    pypdl \
    python-slugify \
    yt-dlp \
    2>/dev/null || true

# Create downloads directory
RUN mkdir -p /app/downloads /app/cookies

# Expose port
EXPOSE 8770

# Run with gunicorn for production
CMD ["gunicorn", "--bind", "0.0.0.0:8770", "--workers", "2", "--threads", "4", "app:app"]
