Update: 2026-07-04 20:53:30

This commit is contained in:
Hamza-Ayed
2026-07-04 20:53:30 +03:00
parent 3c06b3624b
commit df4af1ac2b
15 changed files with 493 additions and 64 deletions
@@ -0,0 +1,59 @@
<?php
// ============================================================
// marketing_engine/services/AIVideoGenerator.php
// Wrapper and Abstract Interfaces for AI Generation APIs
// ============================================================
class AIVideoGenerator {
private $elevenLabsApiKey;
private $creatomateApiKey;
private $geminiApiKey;
public function __construct() {
$this->elevenLabsApiKey = getenv('ELEVENLABS_API_KEY');
$this->creatomateApiKey = getenv('CREATOMATE_API_KEY');
$this->geminiApiKey = getenv('GEMINI_API_KEY');
}
// Abstracted text generation
public function generateScript($topic) {
// Here you would call Gemini API to generate a video script about the topic
// For example: "Write a 30 second TikTok script about how ride hailing drivers lose too much commission, and how Siro fixes this."
// Mock implementation
$prompt = "Write a short 20-word script about: " . $topic;
$mockScript = "Drivers are tired of high commissions. Siro is the solution with 0% commission forever. Join Siro today!";
return [
'status' => 'success',
'script' => $mockScript
];
}
// Abstracted voice generation
public function generateVoice($scriptText) {
// Here you would call ElevenLabs API (or similar) to convert text to speech
// It returns an MP3 file or URL
// Mock implementation
$mockAudioUrl = "https://example.com/audio_mock_".time().".mp3";
return [
'status' => 'success',
'audio_url' => $mockAudioUrl
];
}
// Abstracted video rendering
public function renderVideo($scriptText, $audioUrl, $backgroundVideoUrl = null) {
// Here you would call Creatomate or HeyGen to render the final MP4
// Combining the audio, background, and burning the captions on screen
// Mock implementation
$mockVideoUrl = "https://example.com/rendered_video_".time().".mp4";
return [
'status' => 'success',
'video_url' => $mockVideoUrl
];
}
}
@@ -0,0 +1,105 @@
<?php
// ============================================================
// marketing_engine/services/ContentWorkflow.php
// Orchestrates the entire content generation pipeline
// ============================================================
require_once __DIR__ . '/AIVideoGenerator.php';
require_once __DIR__ . '/../../core/bootstrap.php';
class ContentWorkflow {
private $generator;
private $con;
public function __construct() {
$this->generator = new AIVideoGenerator();
$this->con = Database::get('main');
}
/**
* Executes the next pending step in the content pipeline
*/
public function processPipeline() {
// 1. Check for pending topics to generate scripts
$this->processPendingScripts();
// 2. Check for generated scripts to create voice
$this->processPendingVoices();
// 3. Check for generated voices to render video
$this->processPendingVideos();
// 4. Check for rendered videos to queue marketing tasks
$this->queueUploadTasks();
}
private function processPendingScripts() {
$stmt = $this->con->prepare("SELECT * FROM content_pipeline WHERE status = 'pending' LIMIT 1");
$stmt->execute();
$job = $stmt->fetch(PDO::FETCH_ASSOC);
if ($job) {
$result = $this->generator->generateScript($job['topic']);
if ($result['status'] === 'success') {
$update = $this->con->prepare("UPDATE content_pipeline SET script_text = ?, status = 'script_generated' WHERE id = ?");
$update->execute([$result['script'], $job['id']]);
}
}
}
private function processPendingVoices() {
$stmt = $this->con->prepare("SELECT * FROM content_pipeline WHERE status = 'script_generated' LIMIT 1");
$stmt->execute();
$job = $stmt->fetch(PDO::FETCH_ASSOC);
if ($job) {
$result = $this->generator->generateVoice($job['script_text']);
if ($result['status'] === 'success') {
$update = $this->con->prepare("UPDATE content_pipeline SET voice_url = ?, status = 'voice_generated' WHERE id = ?");
$update->execute([$result['audio_url'], $job['id']]);
}
}
}
private function processPendingVideos() {
$stmt = $this->con->prepare("SELECT * FROM content_pipeline WHERE status = 'voice_generated' LIMIT 1");
$stmt->execute();
$job = $stmt->fetch(PDO::FETCH_ASSOC);
if ($job) {
$result = $this->generator->renderVideo($job['script_text'], $job['voice_url']);
if ($result['status'] === 'success') {
$update = $this->con->prepare("UPDATE content_pipeline SET video_url = ?, status = 'video_rendered' WHERE id = ?");
$update->execute([$result['video_url'], $job['id']]);
}
}
}
private function queueUploadTasks() {
$stmt = $this->con->prepare("SELECT * FROM content_pipeline WHERE status = 'video_rendered' LIMIT 1");
$stmt->execute();
$job = $stmt->fetch(PDO::FETCH_ASSOC);
if ($job) {
// Create upload tasks for TikTok and YouTube Shorts
$insert = $this->con->prepare("
INSERT INTO marketing_tasks (platform, type, content_text, media_url, status)
VALUES
('tiktok', 'upload_video', ?, ?, 'pending'),
('youtube', 'upload_video', ?, ?, 'pending')
");
// Provide a short caption based on the script
$caption = substr($job['script_text'], 0, 100) . "... #Siro #RideHailing";
$insert->execute([
$caption, $job['video_url'],
$caption, $job['video_url']
]);
// Mark job as published (or handed off to bots)
$update = $this->con->prepare("UPDATE content_pipeline SET status = 'published' WHERE id = ?");
$update->execute([$job['id']]);
}
}
}