added auto schedule posts
This commit is contained in:
parent
d7b1d8b55c
commit
eb19101102
3 changed files with 128 additions and 119 deletions
22
app.py
22
app.py
|
|
@ -527,9 +527,9 @@ class SocialPostRequest(BaseModel):
|
|||
platforms: List[str] # ["tiktok", "instagram", "youtube"]
|
||||
# Optional overrides if frontend wants to edit them
|
||||
title: Optional[str] = None
|
||||
tiktok_description: Optional[str] = None
|
||||
instagram_description: Optional[str] = None
|
||||
youtube_description: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
scheduled_date: Optional[str] = None # ISO-8601 string
|
||||
timezone: Optional[str] = "UTC"
|
||||
|
||||
import httpx
|
||||
|
||||
|
|
@ -558,6 +558,7 @@ async def post_to_socials(req: SocialPostRequest):
|
|||
# Construct parameters for Upload-Post API
|
||||
# Fallbacks
|
||||
final_title = req.title or clip.get('title', 'Viral Short')
|
||||
final_description = req.description or clip.get('video_description_for_instagram') or clip.get('video_description_for_tiktok') or "Check this out!"
|
||||
|
||||
# Prepare form data
|
||||
url = "https://api.upload-post.com/api/upload"
|
||||
|
|
@ -572,21 +573,24 @@ async def post_to_socials(req: SocialPostRequest):
|
|||
"platform[]": req.platforms # Pass list directly
|
||||
}
|
||||
|
||||
# Add scheduling if present
|
||||
if req.scheduled_date:
|
||||
data_payload["scheduled_date"] = req.scheduled_date
|
||||
if req.timezone:
|
||||
data_payload["timezone"] = req.timezone
|
||||
|
||||
# Add Platform specifics
|
||||
if "tiktok" in req.platforms:
|
||||
desc = req.tiktok_description or clip.get('video_description_for_tiktok', final_title)
|
||||
data_payload["tiktok_title"] = desc
|
||||
data_payload["tiktok_title"] = final_description
|
||||
|
||||
if "instagram" in req.platforms:
|
||||
desc = req.instagram_description or clip.get('video_description_for_instagram', final_title)
|
||||
data_payload["instagram_title"] = desc
|
||||
data_payload["instagram_title"] = final_description
|
||||
data_payload["media_type"] = "REELS"
|
||||
|
||||
if "youtube" in req.platforms:
|
||||
yt_title = req.title or clip.get('video_title_for_youtube_short', final_title)
|
||||
desc = req.youtube_description or clip.get('video_description_for_instagram', final_title) # Fallback
|
||||
data_payload["youtube_title"] = yt_title
|
||||
data_payload["youtube_description"] = desc
|
||||
data_payload["youtube_description"] = final_description
|
||||
data_payload["privacyStatus"] = "public"
|
||||
|
||||
# Send File
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import React, { useState } from 'react';
|
||||
import { Download, Share2, Instagram, Youtube, Video, CheckCircle, AlertCircle, X, Loader2, Copy, Wand2, Type } from 'lucide-react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Download, Share2, Instagram, Youtube, Video, CheckCircle, AlertCircle, X, Loader2, Copy, Wand2, Type, Calendar, Clock } from 'lucide-react';
|
||||
import { getApiUrl } from '../config';
|
||||
import SubtitleModal from './SubtitleModal';
|
||||
|
||||
|
|
@ -14,6 +14,11 @@ export default function ResultCard({ clip, index, jobId, uploadPostKey, uploadUs
|
|||
instagram: true,
|
||||
youtube: true
|
||||
});
|
||||
const [postTitle, setPostTitle] = useState("");
|
||||
const [postDescription, setPostDescription] = useState("");
|
||||
const [isScheduling, setIsScheduling] = useState(false);
|
||||
const [scheduleDate, setScheduleDate] = useState("");
|
||||
|
||||
const [posting, setPosting] = useState(false);
|
||||
const [postResult, setPostResult] = useState(null);
|
||||
|
||||
|
|
@ -21,6 +26,17 @@ export default function ResultCard({ clip, index, jobId, uploadPostKey, uploadUs
|
|||
const [isSubtitling, setIsSubtitling] = useState(false);
|
||||
const [editError, setEditError] = useState(null);
|
||||
|
||||
// Initialize/Reset form when modal opens
|
||||
useEffect(() => {
|
||||
if (showModal) {
|
||||
setPostTitle(clip.video_title_for_youtube_short || "Viral Short");
|
||||
setPostDescription(clip.video_description_for_instagram || clip.video_description_for_tiktok || "");
|
||||
setIsScheduling(false);
|
||||
setScheduleDate("");
|
||||
setPostResult(null);
|
||||
}
|
||||
}, [showModal, clip]);
|
||||
|
||||
const handleAutoEdit = async () => {
|
||||
setIsEditing(true);
|
||||
setEditError(null);
|
||||
|
|
@ -122,20 +138,36 @@ export default function ResultCard({ clip, index, jobId, uploadPostKey, uploadUs
|
|||
return;
|
||||
}
|
||||
|
||||
if (isScheduling && !scheduleDate) {
|
||||
setPostResult({ success: false, msg: "Please select a date and time." });
|
||||
return;
|
||||
}
|
||||
|
||||
setPosting(true);
|
||||
setPostResult(null);
|
||||
|
||||
try {
|
||||
const payload = {
|
||||
job_id: jobId,
|
||||
clip_index: index,
|
||||
api_key: uploadPostKey,
|
||||
user_id: uploadUserId,
|
||||
platforms: selectedPlatforms,
|
||||
title: postTitle,
|
||||
description: postDescription
|
||||
};
|
||||
|
||||
if (isScheduling && scheduleDate) {
|
||||
// Convert to ISO-8601
|
||||
payload.scheduled_date = new Date(scheduleDate).toISOString();
|
||||
// Optional: pass timezone if needed, backend defaults to UTC or we can send user's timezone
|
||||
payload.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
}
|
||||
|
||||
const res = await fetch(getApiUrl('/api/social/post'), {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
job_id: jobId,
|
||||
clip_index: index,
|
||||
api_key: uploadPostKey,
|
||||
user_id: uploadUserId,
|
||||
platforms: selectedPlatforms
|
||||
})
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
|
|
@ -148,7 +180,7 @@ export default function ResultCard({ clip, index, jobId, uploadPostKey, uploadUs
|
|||
}
|
||||
}
|
||||
|
||||
setPostResult({ success: true, msg: "Posted successfully!" });
|
||||
setPostResult({ success: true, msg: isScheduling ? "Scheduled successfully!" : "Posted successfully!" });
|
||||
setTimeout(() => {
|
||||
setShowModal(false);
|
||||
setPostResult(null);
|
||||
|
|
@ -303,7 +335,7 @@ export default function ResultCard({ clip, index, jobId, uploadPostKey, uploadUs
|
|||
{/* Post Modal */}
|
||||
{showModal && (
|
||||
<div className="fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/80 backdrop-blur-sm animate-[fadeIn_0.2s_ease-out]">
|
||||
<div className="bg-[#121214] border border-white/10 p-6 rounded-2xl w-full max-w-sm shadow-2xl relative">
|
||||
<div className="bg-[#121214] border border-white/10 p-6 rounded-2xl w-full max-w-md shadow-2xl relative max-h-[90vh] overflow-y-auto custom-scrollbar">
|
||||
<button
|
||||
onClick={() => setShowModal(false)}
|
||||
className="absolute top-4 right-4 text-zinc-500 hover:text-white"
|
||||
|
|
@ -311,7 +343,7 @@ export default function ResultCard({ clip, index, jobId, uploadPostKey, uploadUs
|
|||
<X size={20} />
|
||||
</button>
|
||||
|
||||
<h3 className="text-lg font-bold text-white mb-4">Post to Socials</h3>
|
||||
<h3 className="text-lg font-bold text-white mb-4">Post / Schedule</h3>
|
||||
|
||||
{!uploadPostKey && (
|
||||
<div className="mb-4 p-3 bg-yellow-500/10 border border-yellow-500/20 text-yellow-200 text-xs rounded-lg flex items-start gap-2">
|
||||
|
|
@ -320,19 +352,76 @@ export default function ResultCard({ clip, index, jobId, uploadPostKey, uploadUs
|
|||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-2 mb-6">
|
||||
<label className="flex items-center gap-3 p-3 bg-white/5 rounded-lg cursor-pointer hover:bg-white/10 transition-colors border border-white/5">
|
||||
<input type="checkbox" checked={platforms.tiktok} onChange={e => setPlatforms({ ...platforms, tiktok: e.target.checked })} className="w-4 h-4 rounded border-zinc-600 bg-black/50 text-primary focus:ring-primary" />
|
||||
<div className="flex items-center gap-2 text-sm text-white"><Video size={16} className="text-cyan-400" /> TikTok</div>
|
||||
</label>
|
||||
<label className="flex items-center gap-3 p-3 bg-white/5 rounded-lg cursor-pointer hover:bg-white/10 transition-colors border border-white/5">
|
||||
<input type="checkbox" checked={platforms.instagram} onChange={e => setPlatforms({ ...platforms, instagram: e.target.checked })} className="w-4 h-4 rounded border-zinc-600 bg-black/50 text-primary focus:ring-primary" />
|
||||
<div className="flex items-center gap-2 text-sm text-white"><Instagram size={16} className="text-pink-400" /> Instagram</div>
|
||||
</label>
|
||||
<label className="flex items-center gap-3 p-3 bg-white/5 rounded-lg cursor-pointer hover:bg-white/10 transition-colors border border-white/5">
|
||||
<input type="checkbox" checked={platforms.youtube} onChange={e => setPlatforms({ ...platforms, youtube: e.target.checked })} className="w-4 h-4 rounded border-zinc-600 bg-black/50 text-primary focus:ring-primary" />
|
||||
<div className="flex items-center gap-2 text-sm text-white"><Youtube size={16} className="text-red-400" /> YouTube Shorts</div>
|
||||
</label>
|
||||
<div className="space-y-4 mb-6">
|
||||
{/* Title & Description */}
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-zinc-400 mb-1">Video Title</label>
|
||||
<input
|
||||
type="text"
|
||||
value={postTitle}
|
||||
onChange={(e) => setPostTitle(e.target.value)}
|
||||
className="w-full bg-black/40 border border-white/10 rounded-lg p-2 text-sm text-white focus:outline-none focus:border-primary/50 placeholder-zinc-600"
|
||||
placeholder="Enter a catchy title..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-zinc-400 mb-1">Caption / Description</label>
|
||||
<textarea
|
||||
value={postDescription}
|
||||
onChange={(e) => setPostDescription(e.target.value)}
|
||||
rows={4}
|
||||
className="w-full bg-black/40 border border-white/10 rounded-lg p-2 text-sm text-white focus:outline-none focus:border-primary/50 placeholder-zinc-600 resize-none"
|
||||
placeholder="Write a caption for your post..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Scheduling */}
|
||||
<div className="p-3 bg-white/5 rounded-lg border border-white/5">
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<div className="flex items-center gap-2 text-sm text-white font-medium">
|
||||
<Calendar size={16} className="text-purple-400" /> Schedule Post
|
||||
</div>
|
||||
<label className="relative inline-flex items-center cursor-pointer">
|
||||
<input type="checkbox" checked={isScheduling} onChange={(e) => setIsScheduling(e.target.checked)} className="sr-only peer" />
|
||||
<div className="w-9 h-5 bg-zinc-700 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-purple-600"></div>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{isScheduling && (
|
||||
<div className="mt-3 animate-[fadeIn_0.2s_ease-out]">
|
||||
<label className="block text-xs text-zinc-400 mb-1">Select Date & Time</label>
|
||||
<div className="relative">
|
||||
<input
|
||||
type="datetime-local"
|
||||
value={scheduleDate}
|
||||
onChange={(e) => setScheduleDate(e.target.value)}
|
||||
className="w-full bg-black/40 border border-white/10 rounded-lg p-2 pl-9 text-sm text-white focus:outline-none focus:border-purple-500/50 [color-scheme:dark]"
|
||||
/>
|
||||
<Clock size={14} className="absolute left-3 top-2.5 text-zinc-500" />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Platforms */}
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-zinc-400 mb-2">Select Platforms</label>
|
||||
<div className="grid grid-cols-1 gap-2">
|
||||
<label className="flex items-center gap-3 p-3 bg-white/5 rounded-lg cursor-pointer hover:bg-white/10 transition-colors border border-white/5">
|
||||
<input type="checkbox" checked={platforms.tiktok} onChange={e => setPlatforms({ ...platforms, tiktok: e.target.checked })} className="w-4 h-4 rounded border-zinc-600 bg-black/50 text-primary focus:ring-primary" />
|
||||
<div className="flex items-center gap-2 text-sm text-white"><Video size={16} className="text-cyan-400" /> TikTok</div>
|
||||
</label>
|
||||
<label className="flex items-center gap-3 p-3 bg-white/5 rounded-lg cursor-pointer hover:bg-white/10 transition-colors border border-white/5">
|
||||
<input type="checkbox" checked={platforms.instagram} onChange={e => setPlatforms({ ...platforms, instagram: e.target.checked })} className="w-4 h-4 rounded border-zinc-600 bg-black/50 text-primary focus:ring-primary" />
|
||||
<div className="flex items-center gap-2 text-sm text-white"><Instagram size={16} className="text-pink-400" /> Instagram</div>
|
||||
</label>
|
||||
<label className="flex items-center gap-3 p-3 bg-white/5 rounded-lg cursor-pointer hover:bg-white/10 transition-colors border border-white/5">
|
||||
<input type="checkbox" checked={platforms.youtube} onChange={e => setPlatforms({ ...platforms, youtube: e.target.checked })} className="w-4 h-4 rounded border-zinc-600 bg-black/50 text-primary focus:ring-primary" />
|
||||
<div className="flex items-center gap-2 text-sm text-white"><Youtube size={16} className="text-red-400" /> YouTube Shorts</div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{postResult && (
|
||||
|
|
@ -347,7 +436,7 @@ export default function ResultCard({ clip, index, jobId, uploadPostKey, uploadUs
|
|||
disabled={posting || !uploadPostKey}
|
||||
className="w-full py-3 bg-primary hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed rounded-xl text-white font-bold transition-all flex items-center justify-center gap-2"
|
||||
>
|
||||
{posting ? <><Loader2 size={16} className="animate-spin" /> Publishing...</> : <><Share2 size={16} /> Publish Now</>}
|
||||
{posting ? <><Loader2 size={16} className="animate-spin" /> {isScheduling ? 'Scheduling...' : 'Publishing...'}</> : <><Share2 size={16} /> {isScheduling ? 'Schedule Post' : 'Publish Now'}</>}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,84 +0,0 @@
|
|||
1
|
||||
00:00:00,260 --> 00:00:01,859
|
||||
Hoy o a partir
|
||||
|
||||
2
|
||||
00:00:01,859 --> 00:00:02,940
|
||||
de hoy
|
||||
|
||||
3
|
||||
00:00:02,940 --> 00:00:04,540
|
||||
Extremadura tiene
|
||||
|
||||
4
|
||||
00:00:04,540 --> 00:00:06,140
|
||||
mayor bloqueo y
|
||||
|
||||
5
|
||||
00:00:06,140 --> 00:00:06,460
|
||||
mayor
|
||||
|
||||
6
|
||||
00:00:06,460 --> 00:00:07,200
|
||||
inestabilidad.
|
||||
|
||||
7
|
||||
00:00:08,120 --> 00:00:09,520
|
||||
A Extremadura no
|
||||
|
||||
8
|
||||
00:00:09,520 --> 00:00:10,280
|
||||
ha llegado la
|
||||
|
||||
9
|
||||
00:00:10,280 --> 00:00:10,820
|
||||
estabilidad
|
||||
|
||||
10
|
||||
00:00:10,820 --> 00:00:11,820
|
||||
política sino
|
||||
|
||||
11
|
||||
00:00:11,820 --> 00:00:12,320
|
||||
todo lo
|
||||
|
||||
12
|
||||
00:00:12,320 --> 00:00:14,120
|
||||
contrario. Con
|
||||
|
||||
13
|
||||
00:00:14,120 --> 00:00:15,359
|
||||
estas elecciones
|
||||
|
||||
14
|
||||
00:00:15,359 --> 00:00:16,140
|
||||
lo que se ha
|
||||
|
||||
15
|
||||
00:00:16,140 --> 00:00:17,900
|
||||
producido es
|
||||
|
||||
16
|
||||
00:00:17,900 --> 00:00:19,380
|
||||
un engorde de la
|
||||
|
||||
17
|
||||
00:00:19,380 --> 00:00:20,100
|
||||
ultra derecho y,
|
||||
|
||||
18
|
||||
00:00:20,100 --> 00:00:20,500
|
||||
por lo tanto,
|
||||
|
||||
19
|
||||
00:00:20,880 --> 00:00:21,880
|
||||
hay más bloqueo
|
||||
|
||||
20
|
||||
00:00:21,880 --> 00:00:22,440
|
||||
y más
|
||||
|
||||
21
|
||||
00:00:22,440 --> 00:00:23,240
|
||||
inestabilidad.
|
||||
|
||||
Loading…
Reference in a new issue