File size: 2,585 Bytes
8fb6238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using ClipForge.Core.Interfaces.Services;
using Microsoft.Extensions.Logging;

namespace ClipForge.Workers.Jobs;

public class FullPipelineJob
{
    private readonly IIdeaGenerationService _ideaService;
    private readonly IScriptGenerationService _scriptService;
    private readonly IVoiceGenerationService _voiceService;
    private readonly IVideoAssemblyService _assemblyService;
    private readonly ILogger<FullPipelineJob> _logger;

    public FullPipelineJob(
        IIdeaGenerationService ideaService,
        IScriptGenerationService scriptService,
        IVoiceGenerationService voiceService,
        IVideoAssemblyService assemblyService,
        ILogger<FullPipelineJob> logger)
    {
        _ideaService = ideaService;
        _scriptService = scriptService;
        _voiceService = voiceService;
        _assemblyService = assemblyService;
        _logger = logger;
    }

    public async Task ExecuteAsync(string niche, string platform = "tiktok", string voiceId = "alloy")
    {
        _logger.LogInformation("Starting full pipeline for niche '{Niche}' on {Platform}", niche, platform);

        try
        {
            // Step 1: Generate idea
            _logger.LogInformation("Step 1: Generating idea...");
            var idea = await _ideaService.GenerateIdeaAsync(niche, platform);
            _logger.LogInformation("Idea generated: {Title}", idea.Title);

            // Step 2: Generate script
            _logger.LogInformation("Step 2: Generating script...");
            var script = await _scriptService.GenerateScriptAsync(idea.Id);
            _logger.LogInformation("Script generated, duration: {Duration}s", script.EstimatedDurationSeconds);

            // Step 3: Generate voice
            _logger.LogInformation("Step 3: Generating voice...");
            var voice = await _voiceService.GenerateVoiceAsync(script.Id, voiceId);
            _logger.LogInformation("Voice generated: {Duration}s", voice.DurationSeconds);

            // Step 4: Assemble video (includes subtitles)
            _logger.LogInformation("Step 4: Assembling video...");
            var video = await _assemblyService.AssembleVideoAsync(script.Id);
            _logger.LogInformation("Video assembled: {FilePath}, size: {Size}MB", video.FilePath, video.FileSizeBytes / 1024.0 / 1024.0);

            _logger.LogInformation("Full pipeline completed successfully for niche '{Niche}'", niche);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Full pipeline failed for niche '{Niche}'", niche);
            throw;
        }
    }
}