From d60c3760138884288a90e63ead5f41585851daff Mon Sep 17 00:00:00 2001 From: "juancarlos.cavero" Date: Sat, 20 Dec 2025 04:59:38 +0100 Subject: [PATCH] reafactor readme added instructions and texts --- README.md | 119 ++++---- app.py | 2 +- dashboard/src/App.jsx | 383 ++++++++++++++------------ dashboard/src/components/KeyInput.jsx | 13 +- 4 files changed, 275 insertions(+), 242 deletions(-) diff --git a/README.md b/README.md index 5d1664d..9982e66 100644 --- a/README.md +++ b/README.md @@ -1,108 +1,103 @@ -# OpenShorts 🚀🎬 +# OpenShorts.app 🚀🎬 -OpenShorts is an open-source tool designed to automate the creation of viral vertical content. It transforms long YouTube videos or local files into multiple short clips optimized for **TikTok**, **Instagram Reels**, and **YouTube Shorts**. +OpenShorts is an all-in-one open-source solution to automate the creation and distribution of viral vertical content. It transforms long YouTube videos or local files into high-potential short clips optimized for **TikTok**, **Instagram Reels**, and **YouTube Shorts**. ![OpenShorts Demo](https://github.com/kamilstanuch/Autocrop-vertical/blob/main/churchil_queen_vertical_short.gif?raw=true) -*(The demo shows the smart crop process, now powered by AI clip selection)* --- ## ✨ Key Features -OpenShorts goes beyond simple cropping. It combines the power of Artificial Intelligence to understand your video and extract pure gold: +OpenShorts leverages state-of-the-art AI to handle the entire content lifecycle: -1. **🧠 AI Virality Detection (Gemini + Whisper):** - * Automatically transcribes video audio using **OpenAI Whisper**. - * Analyzes content with **Google Gemini 1.5 Flash** to identify moments with the highest viral potential (hooks, jokes, impactful conclusions). - * Generates SEO-optimized titles and descriptions for social media. +1. **🧠 Viral Moment Detection:** + * **Faster-Whisper**: High-speed, CPU-optimized transcription and word-level timestamps. + * **Google Gemini 2.0 Flash**: Advanced AI analysis to identify the 3-15 most viral moments based on hooks and engagement potential. + * **Automatic Copywriting**: Generates SEO-optimized titles and descriptions for all platforms. -2. **✂️ Smart Cropping (Auto-Crop):** - * Detects people and faces using **YOLOv8** and **OpenCV**. - * Keeps the subject always in the center of the vertical frame (9:16). - * Automatically applies *letterboxing* if multiple people are detected far apart to preserve context. +2. **✂️ Smart AI Cropping:** + * **YOLOv8 + OpenCV**: intelligent subject tracking that keeps people/faces centered in the 9:16 frame. + * **Dynamic Letterboxing**: Automatically handles multiple subjects to preserve context when they are far apart. -3. **⚡ Fast Processing:** - * Downloads YouTube videos in the best compatible quality. - * Performs precise cuts based on exact timestamps dictated by AI. - * Uses FFmpeg for efficient rendering. +3. **📲 Direct Social posting:** + * **Upload-Post Integration**: Share your generated clips directly to TikTok, Instagram, and YouTube with a single click. + * **Profile Selector**: Manage multiple social accounts easily through the dashboard. + +4. **🎨 Modern Web Dashboard:** + * **Real-time Progress**: Watch clips appear as they are generated with a live results feed. + * **Log Streaming**: Follow the technical process with real-time log updates. + * **Responsive Design**: A premium, dark-mode glassmorphism interface. --- ## 🛠️ Requirements -* **Docker** and **Docker Compose** installed on your machine. -* A **Google Gemini API Key** (Free at [Google AI Studio](https://aistudio.google.com/app/apikey)). +* **Docker & Docker Compose**. +* **Google Gemini API Key** ([Get it for free here](https://aistudio.google.com/app/apikey)). +* **Upload-Post API Key** (Optional, for direct social posting). + +### 📲 Social Media Setup (Upload-Post) +To enable direct posting, follow these steps: +1. **Login/Register**: [app.upload-post.com/login](https://app.upload-post.com/login) +2. **Create Profile**: Go to [Manage Users](https://app.upload-post.com/manage-users) and create a user profile. +3. **Connect Accounts**: In the same section, connect your TikTok, Instagram, or YouTube accounts to that profile. +4. **Get API Key**: Navigate to [API Keys](https://app.upload-post.com/api-keys) and generate your key. +5. **Use in OpenShorts**: Paste the API Key and select your Profile in the dashboard. + +![Upload-Post Setup Guide](file:///Users/juancarlos.cavero/.gemini/antigravity/brain/d72ee29e-ee3b-45f0-b00b-fe2d705bb56f/uploaded_image_1766201890395.png) --- -## 🚀 Quick Start +## 🚀 Getting Started + +The easiest way to run OpenShorts is using Docker Compose. ### 1. Setup - -Clone the repository and configure your API key: - ```bash -# 1. Clone the repo git clone https://github.com/your-username/OpenShorts.git cd OpenShorts - -# 2. Configure environment variables -cp .env.example .env - -# 3. Edit .env and paste your GEMINI_API_KEY (must start with 'AIza...') -nano .env ``` -### 2. Run with Docker - -No need to install Python or libraries on your system, everything runs in a container. - -**From a YouTube video:** -The system will download the video, search for viral clips, and deliver multiple vertical files ready for upload. - +### 2. Launch the Application ```bash -docker compose run --rm autocrop -u "https://www.youtube.com/watch?v=YOUR_VIDEO_ID" +docker compose up --build ``` -**From a local file:** -Place your video in the `videos/input/` folder. +### 3. Access the Dashboard +Open your browser and navigate to: +**`http://localhost:5173`** -```bash -docker compose run --rm autocrop -i /videos/input/my_video.mp4 -``` - -### 3. Results - -Generated clips will appear in the `videos/` folder (or wherever you specified). Additionally, you'll find a `.json` file with the viral titles and descriptions suggested by AI for each clip. +1. Enter your **Gemini API Key**. +2. (Optional) Enter your **Upload-Post API Key** to enable social sharing. +3. Paste a **YouTube URL** or **Upload a Video**. +4. Click **"Generate Clips"** and watch the magic happen! --- -## ⚙️ Advanced Options +## 🏗️ Technical Pipeline -| Flag | Description | -| :--- | :--- | -| `-u`, `--url` | YouTube URL to download and process. | -| `-i`, `--input` | Path to the local video file (inside the container). | -| `-o`, `--output` | Output directory or specific filename. | -| `--keep-original` | Keeps the original downloaded video after processing. | -| `--skip-analysis` | **Classic Mode:** Skips Gemini/Whisper AI and converts the ENTIRE video to flat vertical format. | +1. **Ingestion**: Downloads YouTube videos via `yt-dlp` or handles local uploads. +2. **Transcription**: `faster-whisper` converts audio to text in seconds. +3. **AI Intelligence**: Gemini reads the transcript and selects periods of high interest. +4. **Extraction**: FFmpeg precisely cuts the selected segments. +5. **Reframing**: AI-powered visual tracking crops clips to vertical format. +6. **Distribution**: One-click posting via Upload-Post API. --- -## 🏗️ How It Works (Pipeline) +## 🔒 Security & Performance -1. **Download/Input**: Gets the source video in high quality. -2. **Transcription (Whisper)**: Converts all audio to text with word-level timestamps. -3. **Analysis (Gemini)**: AI reads the transcript and identifies the 3-15 most interesting segments, returning exact timestamps and metadata. -4. **Extraction**: Selected segments are cut from the original video. -5. **Vertical Conversion**: Each clip goes through the visual detection engine (YOLO) to dynamically reframe the action to 9:16 format. +* **Non-Root Execution**: Containers run as a dedicated `appuser` for security. +* **Concurrency Control**: Configurable job queue (`MAX_CONCURRENT_JOBS`). +* **Auto-Cleanup**: Automatic purging of old jobs and temporary files. +* **File Limits**: Built-in protection against oversized uploads. --- ## 🤝 Contributions -Contributions are welcome! If you have ideas to improve clip detection or cropping, feel free to open a PR. +Contributions are welcome! Whether it's adding new AI models or improving the cropping engine, feel free to open a PR. ## 📄 License -MIT License. Feel free to use it for your personal or commercial projects. +MIT License. OpenShorts is yours to use, modify, and scale. diff --git a/app.py b/app.py index de05938..7411aba 100644 --- a/app.py +++ b/app.py @@ -23,7 +23,7 @@ os.makedirs(OUTPUT_DIR, exist_ok=True) # Configuration # Default to 1 if not set, but user can set higher for powerful servers -MAX_CONCURRENT_JOBS = int(os.environ.get("MAX_CONCURRENT_JOBS", "1")) +MAX_CONCURRENT_JOBS = int(os.environ.get("MAX_CONCURRENT_JOBS", "5")) MAX_FILE_SIZE_MB = 500 # 500 MB limit JOB_RETENTION_SECONDS = 3600 # 1 hour retention diff --git a/dashboard/src/App.jsx b/dashboard/src/App.jsx index ede07a6..a81f29c 100644 --- a/dashboard/src/App.jsx +++ b/dashboard/src/App.jsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from 'react'; -import { Upload, FileVideo, Sparkles, Youtube, Instagram, Share2, LogOut, ChevronDown, Check, Activity, LayoutDashboard, Settings, PlusCircle, History, Menu, X, Terminal } from 'lucide-react'; +import { Upload, FileVideo, Sparkles, Youtube, Instagram, Share2, LogOut, ChevronDown, Check, Activity, LayoutDashboard, Settings, PlusCircle, History, Menu, X, Terminal, Shield } from 'lucide-react'; import KeyInput from './components/KeyInput'; import MediaInput from './components/MediaInput'; import ResultCard from './components/ResultCard'; @@ -9,14 +9,15 @@ import { getApiUrl } from './config'; // Enhanced "Encryption" using XOR + Base64 with a Salt // This is better than plain Base64 but still client-side. const SECRET_KEY = import.meta.env.VITE_ENCRYPTION_KEY || "OpenShorts-Secret-Key-2025-V1"; +const ENCRYPTION_PREFIX = "ENC:"; const encrypt = (text) => { if (!text) return ''; try { - const xor = text.split('').map((c, i) => + const xor = text.split('').map((c, i) => String.fromCharCode(c.charCodeAt(0) ^ SECRET_KEY.charCodeAt(i % SECRET_KEY.length)) ).join(''); - return btoa(xor); + return ENCRYPTION_PREFIX + btoa(xor); } catch (e) { console.error("Encryption failed", e); return text; @@ -25,17 +26,23 @@ const encrypt = (text) => { const decrypt = (text) => { if (!text) return ''; - try { - // Check if it's plain base64 or our custom XOR (simple try) - const xor = atob(text); - const result = xor.split('').map((c, i) => - String.fromCharCode(c.charCodeAt(0) ^ SECRET_KEY.charCodeAt(i % SECRET_KEY.length)) - ).join(''); - return result; - } catch (e) { - // Fallback if decryption fails (might be old plain text) - return text; + if (text.startsWith(ENCRYPTION_PREFIX)) { + try { + const raw = text.slice(ENCRYPTION_PREFIX.length); + // Check if it's plain base64 or our custom XOR (simple try) + const xor = atob(raw); + const result = xor.split('').map((c, i) => + String.fromCharCode(c.charCodeAt(0) ^ SECRET_KEY.charCodeAt(i % SECRET_KEY.length)) + ).join(''); + return result; + } catch (e) { + // Fallback if decryption fails (might be old plain text) + return ''; + } } + // Backward compatibility: If no prefix, assume old plain text (or return empty if you want to force re-login) + // For migration: Return text as is, so it populates the field, and next save will encrypt it. + return text; }; // Simple TikTok icon sine Lucide might not have it or it varies @@ -122,11 +129,11 @@ function App() { const [apiKey, setApiKey] = useState(localStorage.getItem('gemini_key') || ''); // Social API State - Load encrypted or plain const [uploadPostKey, setUploadPostKey] = useState(() => { - const stored = localStorage.getItem('uploadPostKey_v2'); // Changed key to force re-login or fresh start if needed - if (stored) return decrypt(stored); - return ''; + const stored = localStorage.getItem('uploadPostKey_v3'); + if (stored) return decrypt(stored); + return ''; }); - + const [uploadUserId, setUploadUserId] = useState(() => localStorage.getItem('uploadUserId') || ''); const [userProfiles, setUserProfiles] = useState([]); // List of {username, connected: []} const [jobId, setJobId] = useState(null); @@ -138,15 +145,17 @@ function App() { const [activeTab, setActiveTab] = useState('dashboard'); // dashboard, settings useEffect(() => { + // Encrypt Gemini Key too for consistency if desired, but user asked specifically about Social integration not saving well. + // For now keeping gemini plain for compatibility unless requested. if (apiKey) localStorage.setItem('gemini_key', apiKey); }, [apiKey]); useEffect(() => { if (uploadPostKey) { - localStorage.setItem('uploadPostKey_v2', encrypt(uploadPostKey)); + localStorage.setItem('uploadPostKey_v3', encrypt(uploadPostKey)); } if (uploadUserId) { - localStorage.setItem('uploadUserId', uploadUserId); + localStorage.setItem('uploadUserId', uploadUserId); } }, [uploadPostKey, uploadUserId]); @@ -260,22 +269,22 @@ function App() { const Sidebar = () => (
-
- +
+ Logo
OpenShorts
-
- +
-

Open Source

-

Free & Community Driven

+

Open Source

+

Free & Community Driven

@@ -310,187 +319,207 @@ function App() {
{/* Background Gradients */}
-
+
{/* Top Header */}
-
- {status !== 'idle' && ( - - )} -
+
+ {status !== 'idle' && ( + + )} +
-
- {userProfiles.length > 0 && ( - - )} - - {!apiKey && ( - - API Key Missing - - )} -
+
+ {userProfiles.length > 0 && ( + + )} + + {!apiKey && ( + + API Key Missing + + )} +
{/* Main Workspace */}
- + {/* View: Settings */} {activeTab === 'settings' && ( -
-

Settings

- - -
-

Social Integration

-
- -
- setUploadPostKey(e.target.value)} - className="input-field" - placeholder="ey..." - /> - -
-

- Connect your Upload-Post account to enable one-click publishing. -
- Key stored encrypted locally. -

+
+
+

Settings

+
+ Privacy: keys only live in your browser (sent to backend just to process) +
+
+ + +
+

Social Integration

+
+ +
+ setUploadPostKey(e.target.value)} + className="input-field" + placeholder="ey..." + /> + +
+

+ Connect your Upload-Post account to enable one-click publishing. +

-
-
+
+ + Keys are only stored in your browser. They are sent to the backend only to process your request, never stored server-side. + +

+
+
+
)} {/* View: Dashboard (Idle) */} {activeTab === 'dashboard' && status === 'idle' && (
-
-
-

- Create Viral Shorts -

-

- Drop your long-form video URL or file below to instantly generate viral clips with AI. -

-
- - +
+
+

+ Create Viral Shorts +

+

+ Drop your long-form video URL or file below to instantly generate viral clips with AI. +

+
-
- YouTube - Instagram - TikTok -
-
+ + +
+ YouTube + Instagram + TikTok +
+
)} {/* View: Processing / Results (Split View) */} {activeTab === 'dashboard' && (status === 'processing' || status === 'complete' || status === 'error') && (
- + {/* Left Panel: Preview & Status */}
-
-

- - Live Analysis -

- +

+ + Live Analysis +

+ - {status.toUpperCase()} - + }`}> + {status.toUpperCase()} +
+
+ + {/* Video Preview */} + {processingMedia && } + + {/* Logs Terminal */} +
+
+ + System Logs + +
- - {/* Video Preview */} - {processingMedia && } - - {/* Logs Terminal */} -
-
- - System Logs - - -
- {logsVisible && ( -
- {logs.map((log, i) => ( -
- {new Date().toLocaleTimeString()} - {log} -
- ))} - {status === 'processing' && ( -
_
- )} + {logsVisible && ( +
+ {logs.map((log, i) => ( +
+ {new Date().toLocaleTimeString()} + {log}
- )} -
+ ))} + {status === 'processing' && ( +
_
+ )} +
+ )} +
{/* Right Panel: Results Grid */}
-

- - Generated Shorts - {results?.clips?.length > 0 && ( - - {results.clips.length} Clips - - )} -

+

+ + Generated Shorts + {results?.clips?.length > 0 && ( + + {results.clips.length} Clips + + )} +

-
- {results && results.clips && results.clips.length > 0 ? ( -
- {results.clips.map((clip, i) => ( - - ))} -
- ) : ( - status === 'processing' ? ( -
-
-

Waiting for clips...

-
- ) : status === 'error' ? ( -
-

Generation failed.

-
- ) : null - )} -
+
+ {results && results.clips && results.clips.length > 0 ? ( +
+ {results.clips.map((clip, i) => ( + + ))} +
+ ) : ( + status === 'processing' ? ( +
+
+

Waiting for clips...

+
+ ) : status === 'error' ? ( +
+

Generation failed.

+
+ ) : null + )} +
diff --git a/dashboard/src/components/KeyInput.jsx b/dashboard/src/components/KeyInput.jsx index 4c40ba2..8276448 100644 --- a/dashboard/src/components/KeyInput.jsx +++ b/dashboard/src/components/KeyInput.jsx @@ -49,8 +49,8 @@ export default function KeyInput({ onKeySet, savedKey }) { onClick={handleSave} disabled={!key || isSaved} className={`px-6 rounded-xl font-medium transition-all flex items-center gap-2 ${isSaved - ? 'bg-green-500/20 text-green-400 cursor-default' - : 'bg-primary hover:bg-blue-600 text-white shadow-lg shadow-primary/20' + ? 'bg-green-500/20 text-green-400 cursor-default' + : 'bg-primary hover:bg-blue-600 text-white shadow-lg shadow-primary/20' }`} > {isSaved ? <> Ready : 'Set Key'} @@ -58,6 +58,15 @@ export default function KeyInput({ onKeySet, savedKey }) {

Your key is stored locally in your browser for convenience. +
+ + Get your free Gemini API Key here → +

);