The OpenPanel endpoint and client id were hardcoded in dashboard/index.html, so
every clone, fork and self-hosted deployment inherited them and reported into
the hosted instance's dashboard. src/lib/analytics.js already documents the
intended behaviour ('analytics can never leak into the open-source experience');
this makes that true.
- apiUrl and clientId now come from VITE_OPENPANEL_API_URL /
VITE_OPENPANEL_CLIENT_ID, substituted by Vite at build time and unset by
default, so npm run dev and a plain npm run build initialise nothing.
- The third-party script is only fetched once analytics is actually enabled: a
default build makes no external analytics request at all.
- Reporting is additionally gated on a hostname allowlist, so a dist/ built with
credentials stays inert if it is served anywhere else.
Verified with a headless browser against real production builds:
credentials + non-allowlisted host -> no requests
credentials + allowlisted host -> initialises and reports
no credentials + allowlisted host -> no requests
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
128 lines
6.4 KiB
Markdown
128 lines
6.4 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.
|
|
|
|
**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
|