How fullfran/youtube2pdf works
Project Type and Purpose
• Type: Full-stack web application with a static front-end and Python-based API back-end.
• Purpose:
• Extract subtitles from YouTube videos
• Use AI (LLMs) to format them into structured Markdown
• Convert Markdown into PDF
• Serve results via a lightweight API and static UI
File Structure
Top-level files:
• Dockerfile, requirements.txt – container and dependencies
• README.md, privacyPolice.md – documentation
• index.html, style.css, script.js – static front-end assets
• main.py – FastAPI entry point
• subtitles.py – logic to fetch/parse YouTube subtitles
• sub2md.py – logic to convert raw subtitles into Markdown
• md2pdf.py – logic to render Markdown into PDF
Patterns:
• Separation of concerns: extraction → formatting → generation
• Single process Python backend exposing REST endpoints
README for Additional Insights
• Tech stack: FastAPI, LLMs (external AI service), Docker, Railway, GitHub Pages
• Deployment:
• Front-end on GitHub Pages (static hosting)
• Back-end container on Railway or local Docker
• Data flow described: URL → API → subtitles → AI formatting → Markdown/PDF → download
Main Components & Relationships
a. Front-end (Browser)
– index.html / style.css / script.js
– Hosted on GitHub Pages (CDN)
– User pastes YouTube URL, selects format, clicks “Generate”
– Makes HTTPS call (Fetch API) to Back-end API
b. API Layer (FastAPI)
– main.py (defines endpoints: /extract-markdown, /extract-pdf, etc.)
– Containerized via Dockerfile, deployed on Railway or any host
– Orchestrates internal modules
c. Subtitle Extraction Module
– subtitles.py
– Pulls captions via YouTube Data API or youtube-dl
d. Formatting Module
– sub2md.py
– Sends transcript to LLM (e.g. OpenAI) for structured Markdown
e. PDF Generation Module
– md2pdf.py
– Converts Markdown → PDF (e.g. using WeasyPrint, pandoc)
f. External Services
– YouTube (subtitle source)
– LLM API (AI formatting)
Data Flow:
1. Front-end → Back-end API (URL + format)
2. Back-end → subtitles.py → YouTube service
3. Raw subtitles → sub2md.py → LLM API
4. Markdown → md2pdf.py (if PDF) → binary PDF
5. Back-end → Front-end (Markdown or PDF response)
Architectural Patterns & Design Principles
• Micro-modular design: each Python script handles a single responsibility
• Stateless API endpoints for scalability
• Containerization for environment consistency
• Separation of front-end (static hosting) vs back-end (dynamic API)