The browser reports the funnel, but not what decides whether this product retains: on 26-jul-2026, 491 of the 564 users who ever processed a video did it exactly once. Every clip-quality fix that shipped that day — 1080p delivery, captions by default, loudness normalisation — was aimed at that 87%, and nothing in the stack could measure whether it moved. Client-side cannot answer it. A render finishes minutes later, often after the tab is gone, and ad-blockers eat a share of the rest. So the backend now emits ClipsDelivered / JobFailed with the user's profileId and a `job_index` — the count of process jobs that user has run. Counting distinct users at index 1 versus index >= 2, before and after today, answers the question directly. Failures carry the same reason classification the Telegram alerts use, so the "did it break or did they just not come back" split is visible too. Fire-and-forget throughout: no config means a silent no-op (the normal state for self-hosted), every send is a background task, and every failure is swallowed. Analytics must never slow down or break a job. Needs OPENPANEL_CLIENT_ID and OPENPANEL_CLIENT_SECRET in the environment — a WRITE client, which is a different credential from the read/root client the MCP needs. Verified against the live instance: the write path returns 200 and the module no-ops cleanly when unconfigured.
129 lines
6.8 KiB
Markdown
129 lines
6.8 KiB
Markdown
# CLAUDE.md
|
|
|
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
|
|
## Project Overview
|
|
|
|
OpenShorts is an AI-powered vertical video generator that transforms long YouTube videos or local uploads into viral-ready short clips (9:16 format) for TikTok, Instagram Reels, and YouTube Shorts. Uses Google Gemini 2.0 Flash for viral moment detection and title generation.
|
|
|
|
## Development Commands
|
|
|
|
### Local Development (Docker)
|
|
```bash
|
|
docker compose up --build # Build and run full stack
|
|
```
|
|
- Backend: http://localhost:8000 (FastAPI/Uvicorn)
|
|
- Frontend: http://localhost:5175 (Vite proxies API calls to backend)
|
|
|
|
### Frontend Only (Dashboard)
|
|
```bash
|
|
cd dashboard
|
|
npm install
|
|
npm run dev # Dev server with HMR (port 5173)
|
|
npm run build # Production build
|
|
npm run lint # ESLint (strict, --max-warnings 0)
|
|
```
|
|
|
|
### Backend Only
|
|
```bash
|
|
pip install -r requirements.txt
|
|
uvicorn app:app --host 0.0.0.0 --port 8000
|
|
```
|
|
|
|
## Architecture
|
|
|
|
### Core Processing Pipeline
|
|
1. **Ingest** - YouTube download (yt-dlp) or local upload
|
|
2. **Transcription** - faster-whisper with word-level timestamps
|
|
3. **Scene Detection** - PySceneDetect for segment boundaries
|
|
4. **AI Analysis** - Gemini identifies 3-15 viral moments (15-60 sec each)
|
|
5. **FFmpeg Extraction** - Precise clip cutting
|
|
6. **AI Cropping** - Vertical reframing with subject tracking
|
|
7. **Effects/Subtitles** - Optional AI-generated FFmpeg filters
|
|
8. **Hook Overlay** - Text overlays with styled fonts
|
|
9. **Voice Dubbing** - Optional ElevenLabs AI translation (30+ languages)
|
|
10. **S3 Backup** - Silent background upload
|
|
11. **Social Distribution** - Upload-Post API (async upload)
|
|
|
|
### Key Files
|
|
| File | Purpose |
|
|
|------|---------|
|
|
| `main.py` | Core video processing: transcription, scene detection, clip extraction, vertical reframing |
|
|
| `app.py` | FastAPI server with async job queue and REST endpoints |
|
|
| `editor.py` | Gemini AI integration for dynamic video effects (FFmpeg filter generation) |
|
|
| `hooks.py` | Hook text overlay generation with font rendering |
|
|
| `s3_uploader.py` | AWS S3 upload with caching |
|
|
| `subtitles.py` | SRT generation, FFmpeg subtitle burning, and dubbed video transcription |
|
|
| `translate.py` | ElevenLabs dubbing API for AI voice translation |
|
|
| `dashboard/src/App.jsx` | Main React component with state management |
|
|
| `dashboard/src/components/TranslateModal.jsx` | Voice dubbing UI with language selection |
|
|
| `dashboard/vite-plugin-seo.js` | Build-time SEO surface: injects crawler-visible homepage content, emits static pages, sitemap.xml and llms.txt |
|
|
| `dashboard/seo/data.js` | Single source of truth for pricing, pipeline and competitor facts used by every generated page |
|
|
|
|
### SEO / AI-crawler surface
|
|
|
|
The dashboard is a client-rendered SPA with hash routing, so the HTML served for
|
|
`/` used to contain an empty `<div id="root">`. Googlebot renders JavaScript and
|
|
saw the real page; GPTBot, ClaudeBot and PerplexityBot do not and measured the
|
|
homepage as zero characters of text. `vite-plugin-seo.js` fixes that at build time:
|
|
|
|
- Injects the content of `seo/landing-fallback.js` into `#root`. React's
|
|
`createRoot().render()` replaces it on mount, so users get the app and
|
|
non-executing clients get the copy. **Keep it in sync with `Landing.jsx`.**
|
|
- Emits the standalone pages under `/alternatives`, `/free-ai-clip-generator`,
|
|
`/open-source-video-clipper` and `/how-openshorts-works` as flat `.html` files.
|
|
nginx resolves the clean URL through `try_files $uri $uri.html`; serving them as
|
|
directories instead makes nginx 301 to a trailing slash and every canonical
|
|
would then point at a redirect.
|
|
- Generates `sitemap.xml` and `llms.txt` from the same page list, so they cannot
|
|
drift. Do not add a static `public/sitemap.xml` back.
|
|
|
|
When editing pricing anywhere, edit `seo/data.js` too. Nothing on the site should
|
|
say "OpenShorts is free" without naming the Cloud price in the same breath: both
|
|
are true of different editions and quoting only the first one is what makes AI
|
|
answers describe the paid product as free.
|
|
|
|
### Dual-Mode Video Reframing
|
|
- **TRACK Mode** (single subject): MediaPipe face detection + YOLOv8 fallback with "Heavy Tripod" stabilization
|
|
- **GENERAL Mode** (groups/landscapes): Blurred background layout preserving full width
|
|
|
|
### Key Classes
|
|
- `SmoothedCameraman` - Stabilized camera movement with safe zone logic (prevents jitter)
|
|
- `SpeakerTracker` - Prevents rapid speaker switching, handles temporary occlusions
|
|
|
|
### API Endpoints
|
|
| Method | Route | Purpose |
|
|
|--------|-------|---------|
|
|
| POST | `/api/process` | Submit video for processing |
|
|
| GET | `/api/status/{job_id}` | Poll job status and logs |
|
|
| POST | `/api/edit` | Apply AI video effects |
|
|
| POST | `/api/subtitle` | Generate and apply subtitles (auto-transcribes dubbed videos) |
|
|
| POST | `/api/hook` | Add text hook overlays |
|
|
| POST | `/api/translate` | AI voice dubbing via ElevenLabs |
|
|
| GET | `/api/translate/languages` | List supported dubbing languages |
|
|
| POST | `/api/social/post` | Post to social media (async upload) |
|
|
|
|
### Concurrency Model
|
|
Async job queue with semaphore-based concurrency control. Configure via `MAX_CONCURRENT_JOBS` env var (default: 5). Jobs auto-cleanup after 1 hour.
|
|
|
|
## Environment Variables
|
|
|
|
**Server-side (.env):**
|
|
- `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION`, `AWS_S3_BUCKET` - For S3 backup
|
|
- `MAX_CONCURRENT_JOBS` - Concurrent processing limit (default: 5)
|
|
- `VITE_API_URL` - Production API URL override
|
|
- `VITE_OPENPANEL_API_URL`, `VITE_OPENPANEL_CLIENT_ID` - Optional product analytics, read at **build** time. Unset (the default, including every self-hosted build) means no analytics is initialised and no third-party script is loaded. `dashboard/index.html` also gates reporting on an `ANALYTICS_HOSTS` allowlist, so a build carrying credentials stays inert on any other host.
|
|
- `OPENPANEL_CLIENT_ID`, `OPENPANEL_CLIENT_SECRET` - Optional **server-side** analytics (`cloud/analytics.py`), same opt-in rule: unset means a silent no-op. Reports job outcomes with the user's job index, which the browser cannot do reliably — a render finishes after the tab is often gone, and ad-blockers eat a share of client events. Needs a *write* client; the read client used for querying is a different credential.
|
|
|
|
**Client-side (localStorage, encrypted):**
|
|
- `GEMINI_API_KEY` - Google Gemini API key (required)
|
|
- `ELEVENLABS_API_KEY` - ElevenLabs API key for voice dubbing (optional)
|
|
- `UPLOAD_POST_API_KEY` - Upload-Post API key for social posting (optional)
|
|
|
|
> API keys are stored encrypted in the browser and sent via headers only when needed. Never stored server-side.
|
|
|
|
## Tech Stack
|
|
- **Backend:** Python 3.11, FastAPI, google-genai, faster-whisper, ultralytics (YOLOv8), mediapipe, opencv-python, yt-dlp, FFmpeg, httpx
|
|
- **Frontend:** React 18, Vite 4, Tailwind CSS 3.4
|
|
- **External APIs:** Google Gemini, ElevenLabs Dubbing, Upload-Post
|
|
- **Infrastructure:** Docker + Docker Compose, AWS S3
|