How subhamsarangi/yt-collector-backend works
1. Overall shape
- This repository is a small FastAPI backend that acts as a media-processing gateway for YouTube content.
- The app receives authenticated API requests, runs YouTube scraping/download workflows, stores artifacts in Cloudflare R2, and generates PDFs on demand.
2. Request entrypoint and API surface
- main.py is the FastAPI application entrypoint and route registrar.
- The HTTP API is split by concern into routers/video.py, routers/jobs.py, and routers/pdf.py.
- Publicly exposed endpoints are centered on video ingestion, channel scanning, search, job polling, metadata retrieval, and PDF generation.
3. Authentication boundary
- auth.py provides a shared bearer-token check using OCI_API_KEY.
- Every API endpoint is protected by this dependency, so the backend is effectively a private service meant to be called from a trusted frontend or orchestrator.
4. Video ingestion pipeline
- routers/video.py is the main workflow surface for /video, /channel/scan, and /search.
- These routes orchestrate YouTube discovery and download work, then hand off to service code for extraction and storage.
- The route layer stays thin; the actual scraping/downloading logic lives in services/ytdlp.py.
5. YouTube integration
- services/ytdlp.py wraps yt-dlp operations.
- It is responsible for pulling video metadata, thumbnails, and audio, and likely for channel/topic discovery used by the scan and search endpoints.
- The README also indicates ffmpeg and the yt-dlp binary are runtime dependencies, so media extraction is done outside Python as part of the system environment.
6. Object storage boundary
- services/r2.py is the persistence layer for Cloudflare R2.
- This service uploads and deletes generated assets, acting as the backend’s durable storage for downloaded media and derived artifacts.
- R2 is the main external storage system; the API itself does not appear to persist application state locally beyond transient job handling.
7. PDF generation pipeline
- routers/pdf.py exposes /pdf/video/{id} and /pdf/topic/{id} for on-demand document generation.
- services/pdf.py contains the rendering logic, and the README shows WeasyPrint is used at runtime.
- PDF generation appears to depend on data already fetched or stored elsewhere, rather than re-scraping everything from scratch.
8. Job status and metadata access
- routers/jobs.py provides /job/{id} and /job/{id}/metadata.
- This is the async boundary for longer-running work such as downloads, uploads, or PDF generation.
- The architecture implies jobs are tracked separately from the immediate request/response cycle so the frontend can poll for completion.
9. Supporting scripts and operational utilities
- poller.py suggests a background or CLI polling utility for job processing or status checks.
- check_models_groq.py appears to be a validation or model-checking script, likely used for experimentation or integration checks rather than serving API traffic.
- colab/whisper_transcriber.ipynb is clearly an exploratory notebook, not part of the production request path.
10. Deployment and runtime environment
- The backend is designed to run on a small OCI Ubuntu VM with uvicorn, managed by systemd in production.
- System dependencies matter to the architecture: ffmpeg for media extraction, WeasyPrint libraries for PDFs, and the yt-dlp binary for scraping.
- Network access is intentionally narrow: the service listens on port 8000 and is expected to be protected by bearer auth and possibly source-IP restrictions.
11. External systems and data dependencies
- Cloudflare R2 is the primary file storage backend.
- Supabase is referenced in the README as a data source used for PDF generation, so PDFs likely combine YouTube-derived data with application data from Supabase.
- The service is not standalone; it is a processing layer between a frontend/orchestrator and these external systems.
12. How to draw the architecture
- Model it as four layers: authenticated HTTP API, orchestration/routing, media/PDF/storage services, and external systems.
- The dominant flows are: request in → auth → router → yt-dlp/PDF/R2 service → external storage/data source → job result/metadata out.
- The job endpoints form the main asynchronous feedback loop, while /health is the only simple liveness endpoint.
Main entry points: video.py Video API · main.py App entry · ytdlp.py yt-dlp service · r2.py R2 storage
Components 17
Authenticated API
FastAPI entrypoint and route surfaces protected by shared bearer auth.
- App entry · Creates the API application and registers routers and middleware boundaries.
main.py - Auth guard · Shared API-key authentication dependency used by protected endpoints.
auth.py - Video API · Endpoints for video ingestion, channel scan, and search workflows.
routers/video.py - Job API · Polling and metadata endpoints for long-running tasks.
routers/jobs.py - PDF API · On-demand PDF generation endpoints for video and topic documents.
routers/pdf.py
Core services
Media, storage, PDF, search, and summarization logic.
- yt-dlp service · Wraps YouTube scraping, metadata retrieval, thumbnail/audio extraction, and discovery flows.
services/ytdlp.py - R2 storage · Uploads and deletes derived artifacts in Cloudflare R2.
services/r2.py - PDF renderer · Renders PDFs from fetched data and stored artifacts.
services/pdf.py - Search service · Search-oriented support logic used by the video workflows.
services/search.py - Summary service · Summarization logic used by downstream content workflows.
services/summarize.py
External systems
Remote systems and runtime dependencies used by the backend.
- YouTube · Primary upstream content source for discovery and downloads.
- Cloudflare R2 · Durable object storage for downloaded media and generated assets.
- Supabase · Referenced data source used during PDF generation.
- Media tools · System-level dependencies such as yt-dlp, ffmpeg, and WeasyPrint libraries.
Ops and tools
Background utilities and exploratory scripts.
- Poller · Background or CLI utility for checking or advancing job state.
poller.py - Model check · Ad hoc script for validating model connectivity or integration behavior.
check_models_groq.py - Notebook · Experimental Whisper transcription notebook outside the production request path.
colab/whisper_transcriber.ipynb
Connections 21
- App entry → Auth guard: secures · Applies shared bearer-token protection to the API surface.
- App entry → Video API: registers · Mounts the video workflow routes.
- App entry → Job API: registers · Mounts async job polling and metadata routes.
- App entry → PDF API: registers · Mounts PDF generation routes.
- Video API → Auth guard: depends on · Protects ingestion and discovery endpoints with the API key check.
- Job API → Auth guard: depends on · Protects job status and metadata endpoints.
- PDF API → Auth guard: depends on · Protects document generation endpoints.
- Video API → yt-dlp service: orchestrates · Delegates discovery and download work to the YouTube media pipeline.
- Video API → Search service: uses · Supports search-oriented video workflows.
- Video API → R2 storage: stores · Persists downloaded and derived media artifacts.
- PDF API → PDF renderer: renders · Delegates PDF document creation to the rendering service.
- PDF renderer → Supabase: reads · Combines PDF content with external application data.
- PDF renderer → R2 storage: reads/writes · Uses stored artifacts as PDF inputs and outputs.
- yt-dlp service → YouTube: fetches · Pulls metadata and media from YouTube.
- yt-dlp service → Media tools: relies on · Uses external media tooling during extraction and conversion.
- R2 storage → Cloudflare R2: uploads · Persists media and generated assets in Cloudflare R2.
- Job API → Poller: surfaces · Exposes the async job state tracked by background processing.
- Poller → R2 storage: monitors · Likely checks or advances jobs tied to stored artifacts.
- Model check → Media tools: validates · Script-level validation around external model/runtime access.
- Notebook → yt-dlp service: experiments with · Exploratory transcription workflow adjacent to the main media pipeline.
- Notebook → Media tools: requires · Notebook experimentation depends on the same media-processing environment.