Files
yottob/alembic/versions/1b18a0e65b0d_add_download_tracking_fields_to_.py
Ryan Chen 2305dfddb1 Add async video downloads with yt-dlp and Celery
- Added yt-dlp, celery, and redis dependencies to pyproject.toml
- Extended VideoEntry model with download tracking fields:
  - download_status (enum: pending, downloading, completed, failed)
  - download_path, download_started_at, download_completed_at
  - download_error, file_size
- Created celery_app.py with Redis broker configuration
- Created download_service.py with async download tasks:
  - download_video() task downloads as MP4 format
  - Configured yt-dlp for best MP4 quality with fallback
  - Automatic retries on failure (max 3 attempts)
  - Progress tracking and database updates
- Added Flask API endpoints in main.py:
  - POST /api/download/<video_id> to trigger download
  - GET /api/download/status/<video_id> to check status
  - POST /api/download/batch for bulk downloads
- Generated and applied Alembic migration for new fields
- Created downloads/ directory for video storage
- Updated .gitignore to exclude downloads/ directory
- Updated CLAUDE.md with comprehensive documentation:
  - Redis and Celery setup instructions
  - Download workflow and architecture
  - yt-dlp configuration details
  - New API endpoint examples

Videos are downloaded as MP4 files using Celery workers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 14:04:30 -05:00

45 lines
1.9 KiB
Python

"""Add download tracking fields to VideoEntry
Revision ID: 1b18a0e65b0d
Revises: 270efe6976bc
Create Date: 2025-11-26 14:01:41.900938
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '1b18a0e65b0d'
down_revision: Union[str, Sequence[str], None] = '270efe6976bc'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('video_entries', sa.Column('download_status', sa.Enum('PENDING', 'DOWNLOADING', 'COMPLETED', 'FAILED', name='downloadstatus'), nullable=False))
op.add_column('video_entries', sa.Column('download_path', sa.String(length=1000), nullable=True))
op.add_column('video_entries', sa.Column('download_started_at', sa.DateTime(), nullable=True))
op.add_column('video_entries', sa.Column('download_completed_at', sa.DateTime(), nullable=True))
op.add_column('video_entries', sa.Column('download_error', sa.String(length=2000), nullable=True))
op.add_column('video_entries', sa.Column('file_size', sa.BigInteger(), nullable=True))
op.create_index('idx_download_status', 'video_entries', ['download_status'], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index('idx_download_status', table_name='video_entries')
op.drop_column('video_entries', 'file_size')
op.drop_column('video_entries', 'download_error')
op.drop_column('video_entries', 'download_completed_at')
op.drop_column('video_entries', 'download_started_at')
op.drop_column('video_entries', 'download_path')
op.drop_column('video_entries', 'download_status')
# ### end Alembic commands ###