FROM python:3.11-slim

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    ffmpeg \
    fonts-nanum \
    fonts-noto-cjk \
    git \
    curl \
    unzip \
    fontconfig \
    && rm -rf /var/lib/apt/lists/*

# Install additional Korean fonts for YouTube Shorts
RUN mkdir -p /usr/share/fonts/truetype/korean && \
    # Pretendard (가독성 최고)
    curl -L -o /tmp/pretendard.zip "https://github.com/orioncactus/pretendard/releases/download/v1.3.9/Pretendard-1.3.9.zip" && \
    unzip -j /tmp/pretendard.zip "*/Pretendard-Bold.otf" -d /usr/share/fonts/truetype/korean/ && \
    unzip -j /tmp/pretendard.zip "*/Pretendard-Regular.otf" -d /usr/share/fonts/truetype/korean/ && \
    # Black Han Sans (임팩트)
    curl -L -o /usr/share/fonts/truetype/korean/BlackHanSans-Regular.ttf "https://github.com/AcDevelopers/Black-Han-Sans/raw/master/fonts/ttf/BlackHanSans-Regular.ttf" && \
    # DoHyeon (귀여움)
    curl -L -o /usr/share/fonts/truetype/korean/DoHyeon-Regular.ttf "https://github.com/nicholasrq/DoHyeon/raw/master/fonts/DoHyeon-Regular.ttf" && \
    # Update font cache
    fc-cache -fv && \
    rm -rf /tmp/*.zip

# Install yt-dlp
RUN pip install --no-cache-dir yt-dlp

# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Download Whisper model (medium for CPU)
RUN python -c "import whisper; whisper.load_model('medium')"

# Copy application code
COPY . .

# Create data directories
RUN mkdir -p data/downloads data/processed data/bgm

# Expose port
EXPOSE 8000

# Run the application
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
