import React, { useState, useEffect } from 'react'; import { Upload, FileVideo, Sparkles, Youtube, Instagram, Share2, LogOut, ChevronDown, Check, Activity } from 'lucide-react'; import KeyInput from './components/KeyInput'; import MediaInput from './components/MediaInput'; import ResultCard from './components/ResultCard'; import ProcessingAnimation from './components/ProcessingAnimation'; import { getApiUrl } from './config'; // Simple TikTok icon sine Lucide might not have it or it varies const TikTokIcon = ({ size = 16, className = "" }) => ( ); const UserProfileSelector = ({ profiles, selectedUserId, onSelect }) => { const [isOpen, setIsOpen] = useState(false); if (!profiles || profiles.length === 0) return null; const selectedProfile = profiles.find(p => p.username === selectedUserId) || profiles[0]; return (
{isOpen && (
{profiles.map((profile) => ( ))}
)}
); }; // Mock polling function const pollJob = async (jobId) => { const res = await fetch(getApiUrl(`/api/status/${jobId}`)); if (!res.ok) throw new Error('Status check failed'); return res.json(); }; function App() { const [apiKey, setApiKey] = useState(localStorage.getItem('gemini_key') || ''); // Social API State const [uploadPostKey, setUploadPostKey] = useState(() => localStorage.getItem('uploadPostKey') || ''); const [uploadUserId, setUploadUserId] = useState(() => localStorage.getItem('uploadUserId') || ''); const [userProfiles, setUserProfiles] = useState([]); // List of {username, connected: []} const [jobId, setJobId] = useState(null); const [status, setStatus] = useState('idle'); // idle, processing, complete, error const [results, setResults] = useState(null); const [logs, setLogs] = useState([]); const [logsVisible, setLogsVisible] = useState(false); const [processingMedia, setProcessingMedia] = useState(null); useEffect(() => { if (apiKey) localStorage.setItem('gemini_key', apiKey); }, [apiKey]); useEffect(() => { localStorage.setItem('uploadPostKey', uploadPostKey); localStorage.setItem('uploadUserId', uploadUserId); }, [uploadPostKey, uploadUserId]); // Auto-fetch profiles when key is set (and not just on mount, but when key changes we might want to debounce or wait) // But user said "when I reload the web I have to hit load profiles". // So on mount, if key exists, fetch. useEffect(() => { if (uploadPostKey && userProfiles.length === 0) { fetchUserProfiles(); } }, [uploadPostKey]); useEffect(() => { let interval; if ((status === 'processing' || status === 'completed') && jobId) { interval = setInterval(async () => { try { const data = await pollJob(jobId); console.log("Job status:", data); // Update results if available (real-time) if (data.result) { setResults(data.result); } if (data.status === 'completed') { setStatus('complete'); clearInterval(interval); } else if (data.status === 'failed') { setStatus('error'); setLogs(prev => [...prev, "Error: " + data.error]); clearInterval(interval); } else { // Update logs if available if (data.logs) setLogs(data.logs); } } catch (e) { console.error("Polling error", e); } }, 2000); } return () => clearInterval(interval); }, [status, jobId]); const fetchUserProfiles = async () => { if (!uploadPostKey) return; try { const res = await fetch(getApiUrl('/api/social/user'), { headers: { 'X-Upload-Post-Key': uploadPostKey } }); if (!res.ok) throw new Error("Failed to fetch"); const data = await res.json(); if (data.profiles && data.profiles.length > 0) { setUserProfiles(data.profiles); // Auto select first if none selected if (!uploadUserId) { setUploadUserId(data.profiles[0].username); } } else { alert("No profiles found for this API Key."); } } catch (e) { alert("Error fetching User Profiles. Please check key."); console.error(e); } }; const handleProcess = async (data) => { setStatus('processing'); setLogs(["Starting process..."]); setResults(null); setProcessingMedia(data); try { let body; const headers = { 'X-Gemini-Key': apiKey }; if (data.type === 'url') { headers['Content-Type'] = 'application/json'; body = JSON.stringify({ url: data.payload }); } else { const formData = new FormData(); formData.append('file', data.payload); body = formData; // Content-Type is auto-set for FormData } const res = await fetch(getApiUrl('/api/process'), { method: 'POST', headers: data.type === 'url' ? headers : { 'X-Gemini-Key': apiKey }, body }); if (!res.ok) throw new Error(await res.text()); const resData = await res.json(); setJobId(resData.job_id); } catch (e) { setStatus('error'); setLogs(l => [...l, `Error starting job: ${e.message}`]); } }; return (
{/* Background Gradients */}
AI Viral Clipper

OpenShorts.app

Transform long-form videos into viral Shorts, Reels, and TikToks instantly with Gemini AI.

setUploadPostKey(e.target.value)} className="flex-1 bg-black/20 border border-white/10 rounded-lg px-4 py-2 text-sm text-zinc-300 focus:outline-none focus:border-primary/50 transition-colors" />
{userProfiles.length > 0 ? ( ) : (
setUploadUserId(e.target.value)} className="w-full bg-black/20 border border-white/10 rounded-lg px-4 py-2 text-sm text-zinc-300 focus:outline-none focus:border-primary/50 transition-colors" />
)}

Social Auto-Post

Connect your accounts to post directly to TikTok, Instagram & YouTube.

Post directly to all your social networks. Start with a free trial (no credit card required). Simply connect your accounts, generate an API Key, and you're ready to go.

Get Account Used
{status === 'processing' && processingMedia && ( )} {(status === 'processing' || status === 'error') && (
{status === 'error' ? 'Process Failed' : 'Processing Status'}
{logsVisible && (
{logs.map((log, i) => (
{'>'} {log}
))} {status === 'processing' &&
{'>'} _
}
)} {!logsVisible && status === 'processing' && (
Analyzing video content with Gemini AI...
)}
)} {status === 'error' && (
Processing encountered an error.
)} {status === 'complete' && results && (

Results Generated

{results.clips.map((clip, i) => ( ))}
)}
); } export default App;