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
|
|
|
from sqlalchemy import select
|
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
|
|
2026-09-28 09:33:35 +00:00
|
|
|
from app.config import settings
|
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
|
|
|
from app.models.category import Category
|
|
|
|
|
from app.models.channel import Channel
|
|
|
|
|
from app.models.channel_category import channel_categories
|
2026-09-16 18:56:17 +00:00
|
|
|
from app.models.download_job import DownloadJob
|
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
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2026-09-16 18:56:17 +00:00
|
|
|
def _serialize_local(job: DownloadJob | None) -> dict:
|
|
|
|
|
if job is None:
|
|
|
|
|
return {"available": False, "status": "not_downloaded", "progress_percent": None, "media_url": None}
|
|
|
|
|
if job.status == "completed":
|
|
|
|
|
return {"available": True, "status": "completed", "progress_percent": 100, "media_url": job.media_url}
|
|
|
|
|
return {
|
|
|
|
|
"available": False,
|
|
|
|
|
"status": job.status,
|
|
|
|
|
"progress_percent": job.progress_percent,
|
|
|
|
|
"media_url": None,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def serialize_video(
|
|
|
|
|
video: Video, channel: Channel, categories: list[dict], download_job: DownloadJob | None = None
|
|
|
|
|
) -> dict:
|
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
|
|
|
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,
|
2026-09-28 09:33:35 +00:00
|
|
|
"is_short": video.duration_seconds is not None
|
|
|
|
|
and video.duration_seconds <= settings.shorts_max_duration_seconds,
|
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
|
|
|
"youtube_url": video.youtube_url,
|
|
|
|
|
"categories": categories,
|
2026-09-16 18:56:17 +00:00
|
|
|
"local": _serialize_local(download_job),
|
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
|
|
|
}
|