myYouTube/backend/app/services/video_presentation.py
vrubelroman 0ed20bb838 Implement Phases 1-5: skeleton, OAuth, categories, video sync/feed, playback
- FastAPI + PostgreSQL + Alembic + React/Vite skeleton, Docker Compose, healthcheck
- Google OAuth (single allowed account), encrypted refresh token storage
- Subscriptions sync with pagination, uploads playlist batch fetch
- Categories CRUD, many-to-many channel assignment, category filtering
- Video sync (playlistItems + videos.list batching), cached feed with cursor
  pagination, background scheduler (APScheduler)
- Video detail page with YouTube embed player
- SPA fallback routing, optimistic UI updates, client-side query caching

40 backend tests covering OAuth allow-list, sync idempotency, cascade deletes,
cursor pagination, and category filtering.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-16 18:44:30 +00:00

46 lines
1.6 KiB
Python

from sqlalchemy import select
from sqlalchemy.orm import Session
from app.models.category import Category
from app.models.channel import Channel
from app.models.channel_category import channel_categories
from app.models.video import Video
def channel_categories_map(db: Session, channel_ids: list[int]) -> dict[int, list[dict]]:
if not channel_ids:
return {}
rows = db.execute(
select(channel_categories.c.channel_id, Category.id, Category.name)
.join(Category, Category.id == channel_categories.c.category_id)
.where(channel_categories.c.channel_id.in_(channel_ids))
).all()
result: dict[int, list[dict]] = {}
for channel_id, category_id, category_name in rows:
result.setdefault(channel_id, []).append({"id": category_id, "name": category_name})
return result
def serialize_video(video: Video, channel: Channel, categories: list[dict]) -> dict:
return {
"youtube_video_id": video.youtube_video_id,
"title": video.title,
"description": video.description,
"channel": {
"id": channel.id,
"youtube_channel_id": channel.youtube_channel_id,
"title": channel.title,
"thumbnail_url": channel.thumbnail_url,
},
"thumbnail_url": video.thumbnail_url,
"published_at": video.published_at,
"duration_seconds": video.duration_seconds,
"youtube_url": video.youtube_url,
"categories": categories,
"local": {
"available": False,
"status": "not_downloaded",
"progress_percent": None,
"media_url": None,
},
}