Spaces:
Sleeping

File size: 3,189 Bytes
9713441
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import fs from 'node:fs';
import path from 'node:path';
import { PROJECTS_DIR } from '../db/database.js';
import type { Project } from '@olokaflow/shared';

export interface BgmTrackSpec {
  id: string;
  name: string;
  mood: string;
  bpm: number;
  description: string;
}

export const BGM_CATALOG: BgmTrackSpec[] = [
  {
    id: 'upbeat-tech',
    name: 'Upbeat Future Tech (124 BPM)',
    mood: 'Năng lượng, Hiện đại, AI & SaaS',
    bpm: 124,
    description: 'Nhịp synth hiện đại kèm sub-bass rõ nét, tự động Ducking khi có giọng đọc',
  },
  {
    id: 'tiktok-viral-pop',
    name: 'TikTok Viral Hook Beat (128 BPM)',
    mood: 'Sôi động, Bắt tai, Review & Bán hàng',
    bpm: 128,
    description: 'Nhịp trống dồn dập giữ chân người xem trong 3 giây đầu tiên',
  },
  {
    id: 'corporate-clean',
    name: 'Enterprise Vision (112 BPM)',
    mood: 'Chuyên nghiệp, Uy tín, B2B & Tài chính',
    bpm: 112,
    description: 'Tiết tấu piano kết hợp đệm điện tử tinh tế cho giới thiệu doanh nghiệp',
  },
  {
    id: 'luxury-ambient',
    name: 'Obsidian Gold Luxury (96 BPM)',
    mood: 'Sang trọng, Mỹ phẩm, Thời trang & Bất động sản',
    bpm: 96,
    description: 'Không gian âm thanh sâu lắng, tôn vinh hình ảnh sản phẩm cao cấp',
  },
  {
    id: 'lofi-focus',
    name: 'Warm Storytelling Lo-Fi (88 BPM)',
    mood: 'Gần gũi, Kể chuyện, Giáo dục & Podcast',
    bpm: 88,
    description: 'Giai điệu ấm áp không lấn át tần số giọng nói tiếng Việt',
  },
];

export const SFX_CATALOG = [
  { id: 'whoosh-soft', name: 'Soft Air Whoosh', trigger: 'scene-transition' },
  { id: 'pop-spring', name: 'Elastic UI Pop', trigger: 'card-entrance' },
  { id: 'click-ui', name: 'Tactile Cursor Click', trigger: 'button-press' },
  { id: 'riser-hit', name: 'Cinematic Sub Riser', trigger: 'hook-reveal' },
  { id: 'ding-success', name: 'Crystal Notification Ding', trigger: 'cta-lockup' },
];

function formatSrtTime(sec: number): string {
  const hrs = Math.floor(sec / 3600);
  const mins = Math.floor((sec % 3600) / 60);
  const secs = Math.floor(sec % 60);
  const ms = Math.round((sec - Math.floor(sec)) * 1000);
  const pad = (n: number, len = 2) => String(n).padStart(len, '0');
  return `${pad(hrs)}:${pad(mins)}:${pad(secs)},${pad(ms, 3)}`;
}

/**
 * Generates an `.srt` subtitle file for the project's Social Publish Kit.
 */
export function generateProjectSrtFile(project: Project): string {
  const projectDir = path.join(PROJECTS_DIR, project.id);
  fs.mkdirSync(projectDir, { recursive: true });

  let cursor = 0;
  const blocks: string[] = [];
  let idx = 1;

  for (const scene of project.scenes) {
    const start = cursor;
    const end = cursor + (scene.durationSec || 4);
    cursor = end;

    blocks.push(
      `${idx}\n${formatSrtTime(start)} --> ${formatSrtTime(end)}\n${scene.narrationText.trim()}\n`
    );
    idx++;
  }

  const srtContent = blocks.join('\n');
  const srtPath = path.join(projectDir, 'subtitles.srt');
  fs.writeFileSync(srtPath, srtContent, 'utf8');
  return `/api/projects/${project.id}/srt`;
}