1126 lines
53 KiB
HTML
1126 lines
53 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="id">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Drama AI Cina — Generator Drama Pendek Vertikal</title>
|
||
<style>
|
||
:root{
|
||
--bg:#0b0b12; --card:#161624; --card2:#1e1e30; --line:#2c2c44;
|
||
--text:#f2f2f8; --muted:#9a9ab2; --gold:#f5b942; --red:#e5484d;
|
||
--green:#34d399; --blue:#5aa9ff; --radius:14px;
|
||
}
|
||
*{box-sizing:border-box}
|
||
body{margin:0;background:var(--bg);color:var(--text);
|
||
font-family:system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;line-height:1.5}
|
||
header{position:sticky;top:0;z-index:10;background:rgba(11,11,18,.92);backdrop-filter:blur(8px);
|
||
border-bottom:1px solid var(--line);padding:12px 16px;display:flex;gap:12px;align-items:center;flex-wrap:wrap}
|
||
header h1{font-size:19px;margin:0;letter-spacing:.3px}
|
||
header h1 span{color:var(--gold)}
|
||
header .sub{color:var(--muted);font-size:12px;width:100%;margin-top:-8px}
|
||
.pill{margin-left:auto;padding:5px 12px;border-radius:999px;font-size:13px;font-weight:600;background:#333;color:#ccc}
|
||
.pill.on{background:#0d3b2e;color:var(--green)}
|
||
.pill.off{background:#3b1d1d;color:var(--red)}
|
||
main{max-width:860px;margin:0 auto;padding:16px 14px 60px}
|
||
section{background:var(--card);border:1px solid var(--line);border-radius:var(--radius);padding:16px;margin-bottom:16px}
|
||
h2{font-size:16px;margin:0 0 4px}
|
||
h2 .num{display:inline-block;background:var(--gold);color:#111;border-radius:50%;width:22px;height:22px;
|
||
text-align:center;line-height:22px;font-size:13px;margin-right:6px}
|
||
.desc{color:var(--muted);font-size:13px;margin:0 0 12px}
|
||
label{display:block;font-size:13px;font-weight:600;margin:10px 0 4px}
|
||
input[type=text],input[type=url],input[type=number],select,textarea{
|
||
width:100%;background:var(--card2);border:1px solid var(--line);color:var(--text);
|
||
border-radius:9px;padding:9px 10px;font-size:14px;font-family:inherit}
|
||
textarea{resize:vertical;min-height:56px}
|
||
input:focus,select:focus,textarea:focus{outline:2px solid var(--gold);outline-offset:0;border-color:var(--gold)}
|
||
.row{display:flex;gap:10px;flex-wrap:wrap}
|
||
.row>*{flex:1;min-width:140px}
|
||
button{cursor:pointer;border:0;border-radius:10px;padding:10px 16px;font-size:14px;font-weight:700;
|
||
background:var(--gold);color:#111}
|
||
button:hover{filter:brightness(1.08)}
|
||
button.secondary{background:var(--card2);color:var(--text);border:1px solid var(--line)}
|
||
button.danger{background:#3b1d1d;color:#ff9a9a;border:1px solid #5c2a2a}
|
||
button.green{background:var(--green);color:#06281c}
|
||
button:disabled{opacity:.45;cursor:not-allowed}
|
||
.btnrow{display:flex;gap:8px;flex-wrap:wrap;margin-top:12px}
|
||
.note{font-size:12px;color:var(--muted);background:var(--card2);border:1px dashed var(--line);
|
||
border-radius:9px;padding:8px 10px;margin-top:12px}
|
||
.note b{color:var(--gold)}
|
||
.card{background:var(--card2);border:1px solid var(--line);border-radius:11px;padding:12px;margin-top:10px}
|
||
.card h3{margin:0 0 6px;font-size:14px}
|
||
.char-grid{display:grid;grid-template-columns:1fr 1fr;gap:8px}
|
||
.dlg-row{display:flex;gap:8px;margin-top:8px;align-items:flex-start}
|
||
.dlg-row select{flex:0 0 150px}
|
||
.dlg-row textarea{flex:1;min-height:44px}
|
||
.dlg-row button{flex:0 0 auto;padding:8px 10px}
|
||
.job{border:1px solid var(--line);border-radius:11px;padding:10px 12px;margin-top:10px;background:var(--card2)}
|
||
.job .top{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
|
||
.job .top b{font-size:14px}
|
||
.status{font-size:12px;font-weight:700;padding:3px 9px;border-radius:999px;background:#333;color:#ccc}
|
||
.status.antri{background:#333;color:#bbb}
|
||
.status.berjalan{background:#3a2f07;color:var(--gold)}
|
||
.status.selesai{background:#0d3b2e;color:var(--green)}
|
||
.status.gagal{background:#3b1d1d;color:var(--red)}
|
||
.bar{height:8px;background:#26263a;border-radius:99px;margin:8px 0;overflow:hidden}
|
||
.bar i{display:block;height:100%;background:var(--gold);width:0%;transition:width .4s}
|
||
.job video{width:100%;max-width:270px;border-radius:10px;margin-top:8px;background:#000;display:block}
|
||
.err{color:#ff9a9a;font-size:13px;white-space:pre-wrap}
|
||
.ok{color:var(--green);font-size:13px}
|
||
/* preview panggung 9:16 */
|
||
.stage-wrap{display:flex;gap:16px;flex-wrap:wrap;align-items:flex-start}
|
||
.stage{position:relative;width:270px;height:480px;border-radius:14px;overflow:hidden;flex:0 0 auto;
|
||
background:linear-gradient(180deg,#2b1a4d,#12081f);border:1px solid var(--line)}
|
||
.stage .scene-label{position:absolute;top:10px;left:10px;right:10px;font-size:12px;color:#ffffffcc;
|
||
text-shadow:0 1px 4px #000}
|
||
.stage .subtitle{position:absolute;left:12px;right:12px;text-align:center;
|
||
padding:6px 8px;border-radius:6px;white-space:pre-line;word-wrap:break-word}
|
||
.stage .subtitle.bottom{bottom:18px}
|
||
.stage .subtitle.middle{top:50%;transform:translateY(-50%)}
|
||
.stage .aura{position:absolute;inset:0;pointer-events:none;
|
||
background:radial-gradient(circle at 50% 65%,rgba(245,185,66,.35),transparent 60%)}
|
||
.tag{display:inline-block;background:#26263a;border:1px solid var(--line);border-radius:999px;
|
||
padding:4px 10px;font-size:12px;margin:2px;cursor:pointer}
|
||
.tag:hover{border-color:var(--gold)}
|
||
.titles li{margin:6px 0;cursor:pointer}
|
||
.titles li:hover{color:var(--gold)}
|
||
.seg{display:flex;border:1px solid var(--line);border-radius:10px;overflow:hidden}
|
||
.seg button{flex:1;border-radius:0;background:var(--card2);color:var(--muted);padding:9px 6px;font-size:13px}
|
||
.seg button.active{background:var(--gold);color:#111}
|
||
.warn{color:#ffb86b;font-size:12px}
|
||
footer{color:var(--muted);font-size:12px;text-align:center;padding:20px}
|
||
@media (max-width:600px){ .char-grid{grid-template-columns:1fr} .stage{width:100%;height:480px} }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<header>
|
||
<h1>🎬 Drama AI <span>Cina</span></h1>
|
||
<span class="pill off" id="enginePill">● Engine offline</span>
|
||
<div class="sub">Generator drama pendek vertikal ala C-drama — naskah, video, suara & subtitle Indonesia. GPU gratis via Kaggle / Colab.</div>
|
||
</header>
|
||
<main>
|
||
|
||
<!-- 1. KONEKSI -->
|
||
<section>
|
||
<h2><span class="num">1</span>Koneksi Engine (GPU)</h2>
|
||
<p class="desc">Jalankan notebook Kaggle / Colab dulu, lalu paste URL tunnel-nya di sini. URL berubah tiap sesi. URL hanya disimpan di memori halaman ini (tidak tersimpan permanen).</p>
|
||
<label for="engineUrl">URL Engine (contoh: https://xxxx.trycloudflare.com)</label>
|
||
<input type="url" id="engineUrl" placeholder="https://xxxx.trycloudflare.com" autocomplete="off">
|
||
<div class="btnrow">
|
||
<button id="btnTest">Test Koneksi</button>
|
||
<button class="secondary" id="btnDemo">▶ Coba Mode Demo (tanpa GPU)</button>
|
||
</div>
|
||
<div id="engineInfo" class="note" style="display:none"></div>
|
||
</section>
|
||
|
||
<!-- 2. PROYEK -->
|
||
<section>
|
||
<h2><span class="num">2</span>Proyek & Judul</h2>
|
||
<label for="title">Judul drama</label>
|
||
<div class="row" style="align-items:flex-end">
|
||
<div style="flex:3"><input type="text" id="title" placeholder="cth: Adik Perempuan Turun Gunung"></div>
|
||
<button id="btnTitle" class="secondary" style="flex:1">✨ Buatkan Judul</button>
|
||
</div>
|
||
<div id="titleBox" style="display:none;margin-top:10px">
|
||
<label>Ketuk judul untuk memakai:</label>
|
||
<ol class="titles" id="titleList"></ol>
|
||
<label>Hashtag YouTube (ketuk untuk salin):</label>
|
||
<div id="tagBox"></div>
|
||
</div>
|
||
<div class="row">
|
||
<div>
|
||
<label for="genre">Genre (unggulan: Xianxia · Sistem)</label>
|
||
<select id="genre">
|
||
<option>Xianxia · Sistem · Turun Gunung</option>
|
||
<option>Kultivasi Perkotaan</option>
|
||
<option>Perang Dewa-Iblis</option>
|
||
<option>Kembali ke Masa Lalu</option>
|
||
<option>Wuxia/Xianxia</option>
|
||
<option>Romansa CEO</option>
|
||
<option>Balas Dendam</option>
|
||
<option>Fantasi</option>
|
||
<option>Keluarga</option>
|
||
<option>Komedi</option>
|
||
<option>Kostum Sejarah</option>
|
||
</select>
|
||
</div>
|
||
<div>
|
||
<label for="mode">Mode</label>
|
||
<div class="seg" id="modeSeg">
|
||
<button data-mode="episode" class="active">📺 Episode (gabung jadi 1 video)</button>
|
||
<button data-mode="satuan">🎞 Adegan satuan</button>
|
||
</div>
|
||
<div class="note" id="modeNote" style="margin-top:8px">Mode Episode: semua adegan digabung jadi satu video panjang — format kompilasi untuk update harian, seperti channel drama Cina.</div>
|
||
</div>
|
||
</div>
|
||
<div class="row">
|
||
<div>
|
||
<label for="numScenes">Jumlah adegan (1–10)</label>
|
||
<input type="number" id="numScenes" min="1" max="10" value="3">
|
||
</div>
|
||
<div>
|
||
<label for="duration">Durasi per adegan (3–8 detik)</label>
|
||
<input type="number" id="duration" min="3" max="8" value="5">
|
||
</div>
|
||
<div>
|
||
<label for="resolution">Resolusi (9:16)</label>
|
||
<select id="resolution">
|
||
<option value="480">480×832 (asli, cepat)</option>
|
||
<option value="720">720×1280 (upscale dari 480p)</option>
|
||
</select>
|
||
</div>
|
||
<div>
|
||
<label for="narrVoice">Suara narasi</label>
|
||
<select id="narrVoice">
|
||
<option value="id-ID-GadisNeural">id-ID-GadisNeural (cewek)</option>
|
||
<option value="id-ID-ArdiNeural">id-ID-ArdiNeural (cowok)</option>
|
||
<option value="zh-CN-XiaoxiaoNeural">zh-CN-XiaoxiaoNeural (cewek Cina)</option>
|
||
<option value="zh-CN-YunxiNeural">zh-CN-YunxiNeural (cowok Cina)</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="note">Total durasi episode ≈ <b id="totalDur">15 detik</b> (3 adegan × 5 detik). Render GPU gratis di T4: klip 5 detik 480p sekitar 1–3 menit — episode 10 adegan bisa 10–30 menit.</div>
|
||
<div class="btnrow">
|
||
<button id="btnSample">📋 Isi Contoh: Adik Perempuan Turun Gunung</button>
|
||
<button class="secondary" id="btnReset">Reset Proyek</button>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- 3. KARAKTER -->
|
||
<section>
|
||
<h2><span class="num">3</span>Karakter</h2>
|
||
<p class="desc">Deskripsi visual dipakai agar karakter konsisten di semua adegan. Pilih suara dialog per karakter (Cina untuk dialog Mandarin).</p>
|
||
<div id="charList"></div>
|
||
<div class="btnrow"><button class="secondary" id="btnAddChar">+ Tambah Karakter</button></div>
|
||
</section>
|
||
|
||
<!-- 4. NASKAH -->
|
||
<section>
|
||
<h2><span class="num">4</span>Naskah per Adegan</h2>
|
||
<p class="desc">Tiap adegan: setting visual, narasi, dan dialog per karakter. Dialog ditulis Mandarin + terjemahan Indonesia (otomatis diisi saat "Buatkan Naskah").</p>
|
||
<div class="btnrow" style="margin-top:0;margin-bottom:6px">
|
||
<button id="btnScript">✨ Buatkan Naskah Otomatis</button>
|
||
<button class="secondary" id="btnAddScene">+ Tambah Adegan</button>
|
||
</div>
|
||
<div id="sceneList"></div>
|
||
</section>
|
||
|
||
<!-- 5. SUBTITLE -->
|
||
<section>
|
||
<h2><span class="num">5</span>Subtitle Custom</h2>
|
||
<p class="desc">Subtitle default Bahasa Indonesia (seperti dubbing/subtitle channel drama Cina). Bilingual menampilkan Cina + Indonesia dua baris.</p>
|
||
<div class="stage-wrap">
|
||
<div>
|
||
<div class="row">
|
||
<div>
|
||
<label for="subLang">Bahasa subtitle</label>
|
||
<select id="subLang">
|
||
<option value="id" selected>Indonesia</option>
|
||
<option value="bilingual">Bilingual (中文 + Indonesia)</option>
|
||
<option value="zh">中文 (Mandarin)</option>
|
||
<option value="en">English</option>
|
||
</select>
|
||
</div>
|
||
<div>
|
||
<label for="subSize">Ukuran font (px)</label>
|
||
<input type="number" id="subSize" min="16" max="48" value="28">
|
||
</div>
|
||
<div>
|
||
<label for="subPos">Posisi</label>
|
||
<select id="subPos">
|
||
<option value="bottom">Bawah</option>
|
||
<option value="middle">Tengah</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="row">
|
||
<div><label for="subColor">Warna teks</label><input type="color" id="subColor" value="#FFFFFF" style="height:38px;padding:2px"></div>
|
||
<div><label for="subBg">Warna kotak subtitle</label><input type="color" id="subBg" value="#000000" style="height:38px;padding:2px"></div>
|
||
<div><label for="subOpacity">Kotak transparan (0–1)</label><input type="number" id="subOpacity" min="0" max="1" step="0.1" value="0.6"></div>
|
||
</div>
|
||
<div class="row">
|
||
<label style="display:flex;gap:6px;align-items:center"><input type="checkbox" id="subBold" checked style="width:auto"> Tebal (bold)</label>
|
||
<label style="display:flex;gap:6px;align-items:center"><input type="checkbox" id="subOutline" checked style="width:auto"> Outline</label>
|
||
</div>
|
||
<div class="note">Preview di kanan memakai adegan pertama. Subtitle final dibakar ke video via ffmpeg (libass) — gayanya sama seperti preview ini.</div>
|
||
</div>
|
||
<div class="stage" id="stage">
|
||
<div class="aura"></div>
|
||
<div class="scene-label" id="stageLabel">Adegan 1</div>
|
||
<div class="subtitle bottom" id="stageSub">Subtitle preview</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- 6. RENDER -->
|
||
<section>
|
||
<h2><span class="num">6</span>Render & Gabung</h2>
|
||
<p class="desc">Render tiap adegan jadi video (GPU), lalu gabungkan jadi satu video episode lengkap + file SRT. Di Mode Demo, render disimulasikan di browser (tanpa suara).</p>
|
||
<div class="btnrow" style="margin-top:0">
|
||
<button id="btnRender" class="green">🎬 Render Semua Adegan</button>
|
||
<button id="btnAssemble">📺 Gabung & Download Video Final</button>
|
||
</div>
|
||
<div id="jobList"></div>
|
||
<div id="finalBox" style="display:none;margin-top:12px" class="card">
|
||
<h3>✅ Video Final Siap</h3>
|
||
<video id="finalVideo" controls style="width:100%;max-width:270px;background:#000;border-radius:10px"></video>
|
||
<div class="btnrow">
|
||
<a id="dlMp4" href="#" download="drama-final.mp4"><button>⬇ Download MP4</button></a>
|
||
<a id="dlSrt" href="#" download="drama-final.srt"><button class="secondary">⬇ Download SRT</button></a>
|
||
</div>
|
||
<div id="finalWarn" class="warn"></div>
|
||
</div>
|
||
</section>
|
||
|
||
<section>
|
||
<h2>ℹ️ Batas jujur (baca dulu)</h2>
|
||
<p class="desc" style="margin:0">
|
||
• Render gratis di T4 itu <b>lambat</b>: klip 5 detik 480p sekitar 1–3 menit; episode 10 adegan bisa 10–30 menit.<br>
|
||
• Kualitas video <b>tidak setara tool komersial</b> (Kling / Runway) — model Wan2.1 1.3B gratis, 480p, dan adegan di atas ±5 detik di-freeze frame terakhirnya.<br>
|
||
• Suara dialog/narasi memakai <b>TTS gratis</b> (Edge-TTS), bukan dubber manusia.<br>
|
||
• Subtitle dibakar ke video via ffmpeg (libass); file SRT terpisah juga disediakan.<br>
|
||
• URL engine berubah tiap sesi Kaggle/Colab — paste ulang tiap kali notebook di-Run All.<br>
|
||
• Mode Demo hanya simulasi visual di browser (tanpa suara, tanpa GPU) untuk mencoba alur & subtitle.
|
||
</p>
|
||
</section>
|
||
</main>
|
||
<footer>Drama AI Cina — naskah Qwen 2.5 · video Wan2.1 · suara Edge-TTS · GPU Kaggle/Colab</footer>
|
||
|
||
<script>
|
||
"use strict";
|
||
/* ================= STATE ================= */
|
||
let engineUrl = ""; // HANYA di memori halaman (tidak disimpan)
|
||
let engineOnline = false;
|
||
let demoMode = false;
|
||
let pollTimer = null;
|
||
const LS_KEY = "dramaAI.project.v1";
|
||
|
||
const VOICES = [
|
||
{v:"zh-CN-XiaoxiaoNeural", label:"Xiaoxiao (cewek Cina)"},
|
||
{v:"zh-CN-YunxiNeural", label:"Yunxi (cowok Cina)"},
|
||
{v:"id-ID-GadisNeural", label:"Gadis (cewek Indo)"},
|
||
{v:"id-ID-ArdiNeural", label:"Ardi (cowok Indo)"},
|
||
];
|
||
|
||
const DEFAULT_SUB = {language:"id", fontSize:28, fontColor:"#FFFFFF", bgColor:"#000000",
|
||
bgOpacity:0.6, position:"bottom", bold:true, outline:true};
|
||
|
||
let state = {
|
||
title:"Adik Perempuan Turun Gunung",
|
||
genre:"Xianxia · Sistem · Turun Gunung",
|
||
mode:"episode",
|
||
numScenes:3, duration:5, resolution:480, narrVoice:"id-ID-GadisNeural",
|
||
characters:[],
|
||
scenes:[],
|
||
subtitle:{...DEFAULT_SUB},
|
||
jobs:{},
|
||
finalJobId:null,
|
||
};
|
||
|
||
/* ============ DATA DEMO — "Adik Perempuan Turun Gunung" ============
|
||
Meniru referensi: channel Teater Bangkit Balik — adik 6 tahun turun gunung,
|
||
kakak senior level maksimal panik. Beat: diremehkan -> kekuatan terungkap ->
|
||
semua panik -> pembalasan memuaskan. */
|
||
const DEMO_CHARS = [
|
||
{id:"c1", name:"Xiao Ling (Adik)", role:"Adik perempuan, 6 tahun",
|
||
desc:"Anak perempuan 6 tahun, jubah putih kecil, rambut dikuncir dua, wajah polos, menyimpan kekuatan dewa",
|
||
voice:"zh-CN-XiaoxiaoNeural"},
|
||
{id:"c2", name:"Kakak Chen", role:"Kakak senior 1, level maksimal",
|
||
desc:"Pria muda berjubah biru sekte, pedang di punggung, sombong lalu panik",
|
||
voice:"zh-CN-YunxiNeural"},
|
||
{id:"c3", name:"Kakak Mei", role:"Kakak senior 2, level maksimal",
|
||
desc:"Wanita muda berjubah ungu sekte, sinis lalu ketakutan",
|
||
voice:"zh-CN-XiaoxiaoNeural"},
|
||
{id:"c4", name:"Guru", role:"Guru sekte",
|
||
desc:"Pria tua berjubah putih, janggut putih, tenang dan bijak",
|
||
voice:"zh-CN-YunxiNeural"},
|
||
];
|
||
const DEMO_SCENES = [
|
||
{visual:"Anak perempuan kecil berjubah putih menuruni tangga batu sekte di gunung berkabut saat matahari terbit, pedang kayu di punggung.",
|
||
visual_en:"A small little girl in a white robe walks down the stone stairs of a mountain sect in mist at sunrise, a wooden sword on her back.",
|
||
narration:"Enam tahun berlatih di gunung, hari ini Xiao Ling akhirnya turun gunung.",
|
||
narration_zh:"六年苦修,今日小玲终于下山。",
|
||
narration_en:"After six years training on the mountain, Xiao Ling finally descends today.",
|
||
dialogues:[
|
||
{character:"Guru", text_zh:"小玲,记住,要隐藏你的实力。", text_id:"Xiao Ling, ingatlah, sembunyikan kekuatanmu.", text_en:"Xiao Ling, remember, hide your true power.", voice:"zh-CN-YunxiNeural"},
|
||
{character:"Xiao Ling (Adik)", text_zh:"师父放心,我只是个小孩子。", text_id:"Guru tenang saja, aku hanya anak kecil.", text_en:"Don't worry, Master, I'm just a little kid.", voice:"zh-CN-XiaoxiaoNeural"},
|
||
]},
|
||
{visual:"Aula sekte megah, dua kakak senior level maksimal mengejek adik kecil itu, lalu wajah mereka berubah panik saat aura emas menyala dari tubuh sang adik.",
|
||
visual_en:"A grand sect hall, two max-level senior disciples mock the little girl, then their faces turn to panic as a golden aura blazes from her body.",
|
||
narration:"Kakak senior menertawakan adik kecil itu. Sampai aura emasnya menyala.",
|
||
narration_zh:"师兄师姐们嘲笑这个小女孩,直到她身上金光亮起。",
|
||
narration_en:"The senior disciples laughed at the little girl. Until her golden aura blazed.",
|
||
dialogues:[
|
||
{character:"Kakak Chen", text_zh:"小孩子也敢进我们宗门?", text_id:"Anak kecil sepertimu berani masuk sekte kami?", text_en:"A little kid dares to enter our sect?", voice:"zh-CN-YunxiNeural"},
|
||
{character:"Kakak Mei", text_zh:"哈哈,木剑?真是好笑。", text_id:"Haha, pedang kayu? Lucu sekali.", text_en:"Haha, a wooden sword? How funny.", voice:"zh-CN-XiaoxiaoNeural"},
|
||
{character:"Xiao Ling (Adik)", text_zh:"师兄……别后悔哦。", text_id:"Kakak... jangan menyesal nanti.", text_en:"Senior... don't regret this later.", voice:"zh-CN-XiaoxiaoNeural"},
|
||
]},
|
||
{visual:"Adik kecil mengangkat satu tangan, aura emas dan merah menyala membara, pedang terbang berputar di udara, para kakak senior berlutut ketakutan.",
|
||
visual_en:"The little girl raises one hand, golden and red aura blazing, flying swords spinning in the air, the senior disciples kneeling in fear.",
|
||
narration:"Satu gerakan tangan. Seluruh aula pun terdiam.",
|
||
narration_zh:"只一抬手,整个大殿鸦雀无声。",
|
||
narration_en:"One hand raised. The entire hall fell silent.",
|
||
dialogues:[
|
||
{character:"Kakak Chen", text_zh:"不可能!这力量……是神级!", text_id:"Tidak mungkin! Kekuatan ini... level dewa!", text_en:"Impossible! This power... god level!", voice:"zh-CN-YunxiNeural"},
|
||
{character:"Xiao Ling (Adik)", text_zh:"我说了,别小看我。", text_id:"Sudah kubilang, jangan remehkan aku.", text_en:"I told you, don't underestimate me.", voice:"zh-CN-XiaoxiaoNeural"},
|
||
{character:"Guru", text_zh:"果然……她就是天选之人。", text_id:"Seperti yang kuduga... dia memang yang terpilih.", text_en:"As I expected... she is the chosen one.", voice:"zh-CN-YunxiNeural"},
|
||
]},
|
||
];
|
||
const DEMO_TITLES = [
|
||
"🔥Adik perempuan berusia enam tahun turun gunung, semua kakak senior level maksimal panik",
|
||
"Tubuhnya tak terkalahkan, ia turun gunung untuk menyembunyikan kekuatan aslinya!",
|
||
"Dihina sebagai anak kecil, ternyata dia dewa pedang yang bereinkarnasi!",
|
||
"Anak kecil berusia 6 tahun turun gunung, seluruh sekte gempar!",
|
||
"Sistem bangkit! Adik kecil yang diremehkan kini tak terkalahkan!",
|
||
];
|
||
const DEMO_TAGS = ["#DramaPendek","#DramaChina","#Xianxia","#Sistem","#BangkitBalik",
|
||
"#DramaChinaSubIndo","#TurunGunung","#Cultivation"];
|
||
|
||
/* ================= PERSISTENSI ================= */
|
||
function save(){
|
||
try{
|
||
const {jobs, finalJobId, ...rest} = state;
|
||
localStorage.setItem(LS_KEY, JSON.stringify(rest));
|
||
}catch(e){}
|
||
}
|
||
function load(){
|
||
try{
|
||
const raw = localStorage.getItem(LS_KEY);
|
||
if(!raw) return false;
|
||
const d = JSON.parse(raw);
|
||
Object.assign(state, d);
|
||
state.subtitle = {...DEFAULT_SUB, ...(d.subtitle||{})};
|
||
state.jobs = {}; state.finalJobId = null;
|
||
return true;
|
||
}catch(e){ return false; }
|
||
}
|
||
|
||
/* ================= HELPERS ================= */
|
||
const $ = id => document.getElementById(id);
|
||
const esc = s => String(s ?? "").replace(/[&<>"]/g, c => ({"&":"&","<":"<",">":">",'"':"""}[c]));
|
||
function uid(){ return "x" + Math.random().toString(36).slice(2, 9); }
|
||
function charByName(name){ return state.characters.find(c => c.name === name); }
|
||
function voiceOf(name){
|
||
const c = charByName(name);
|
||
return c ? c.voice : "zh-CN-XiaoxiaoNeural";
|
||
}
|
||
function subTextFor(scene, dlg){
|
||
const lang = state.subtitle.language;
|
||
if(!dlg){
|
||
if(lang === "zh") return scene.narration_zh || scene.narration || "";
|
||
if(lang === "en") return scene.narration_en || scene.narration || "";
|
||
if(lang === "bilingual"){
|
||
const zh = scene.narration_zh || "", id = scene.narration || "";
|
||
return (zh && id) ? zh + "\n" + id : (zh || id);
|
||
}
|
||
return scene.narration || "";
|
||
}
|
||
if(lang === "zh") return dlg.text_zh || dlg.text_id || "";
|
||
if(lang === "en") return dlg.text_en || dlg.text_id || "";
|
||
if(lang === "bilingual"){
|
||
const zh = dlg.text_zh || "", id = dlg.text_id || "";
|
||
return (zh && id) ? zh + "\n" + id : (zh || id);
|
||
}
|
||
return dlg.text_id || dlg.text_zh || "";
|
||
}
|
||
|
||
/* ================= RENDER UI: KARAKTER ================= */
|
||
function renderChars(){
|
||
$("charList").innerHTML = state.characters.map((c, i) => `
|
||
<div class="card">
|
||
<div class="row">
|
||
<div><label>Nama</label><input type="text" value="${esc(c.name)}" data-c="${i}" data-f="name"></div>
|
||
<div><label>Peran</label><input type="text" value="${esc(c.role)}" data-c="${i}" data-f="role"></div>
|
||
</div>
|
||
<label>Deskripsi visual (agar konsisten antar adegan)</label>
|
||
<input type="text" value="${esc(c.desc)}" data-c="${i}" data-f="desc">
|
||
<div class="row">
|
||
<div><label>Suara dialog</label>
|
||
<select data-c="${i}" data-f="voice">${VOICES.map(v =>
|
||
`<option value="${v.v}" ${c.voice===v.v?"selected":""}>${v.label}</option>`).join("")}</select></div>
|
||
<div style="flex:0 0 auto;align-self:flex-end"><button class="danger" data-delchar="${i}">Hapus</button></div>
|
||
</div>
|
||
</div>`).join("") || `<p class="desc">Belum ada karakter. Tambahkan minimal 1.</p>`;
|
||
$("charList").querySelectorAll("[data-c]").forEach(el => {
|
||
el.addEventListener("input", () => {
|
||
const i = +el.dataset.c, f = el.dataset.f;
|
||
state.characters[i][f] = el.value;
|
||
if(f === "name") renderScenes();
|
||
save();
|
||
});
|
||
});
|
||
$("charList").querySelectorAll("[data-delchar]").forEach(b =>
|
||
b.addEventListener("click", () => { state.characters.splice(+b.dataset.delchar, 1); renderChars(); renderScenes(); save(); }));
|
||
}
|
||
|
||
/* ================= RENDER UI: ADEGAN ================= */
|
||
function renderScenes(){
|
||
$("sceneList").innerHTML = state.scenes.map((s, i) => `
|
||
<div class="card">
|
||
<h3>Adegan ${i+1}</h3>
|
||
<label>Setting visual</label>
|
||
<textarea data-s="${i}" data-f="visual" placeholder="cth: Aula sekte megah, kakak senior mengejek adik kecil...">${esc(s.visual)}</textarea>
|
||
<label>Narasi (Indonesia)</label>
|
||
<textarea data-s="${i}" data-f="narration" style="min-height:40px">${esc(s.narration)}</textarea>
|
||
<label>Dialog</label>
|
||
${(s.dialogues||[]).map((d, j) => `
|
||
<div class="dlg-row">
|
||
<select data-s="${i}" data-d="${j}" data-f="character">
|
||
${state.characters.map(c => `<option ${c.name===d.character?"selected":""}>${esc(c.name)}</option>`).join("")}
|
||
${!charByName(d.character) ? `<option selected>${esc(d.character)}</option>` : ""}
|
||
</select>
|
||
<textarea data-s="${i}" data-d="${j}" data-f="text_id" placeholder="Dialog Indonesia...">${esc(d.text_id)}</textarea>
|
||
<textarea data-s="${i}" data-d="${j}" data-f="text_zh" placeholder="Dialog Mandarin...">${esc(d.text_zh)}</textarea>
|
||
<button class="danger" data-deldlg="${i}:${j}">✕</button>
|
||
</div>`).join("")}
|
||
<div class="btnrow">
|
||
<button class="secondary" data-adddlg="${i}">+ Dialog</button>
|
||
<button class="secondary" data-speak="${i}">🔊 Dengar Dialog</button>
|
||
<button class="danger" data-delscene="${i}">Hapus Adegan</button>
|
||
</div>
|
||
</div>`).join("") || `<p class="desc">Belum ada adegan. Klik "Buatkan Naskah Otomatis" atau "Tambah Adegan".</p>`;
|
||
$("sceneList").querySelectorAll("[data-s]").forEach(el => {
|
||
el.addEventListener("input", () => {
|
||
const i = +el.dataset.s, f = el.dataset.f;
|
||
if(el.dataset.d !== undefined){
|
||
state.scenes[i].dialogues[+el.dataset.d][f] = el.value;
|
||
} else {
|
||
state.scenes[i][f] = el.value;
|
||
}
|
||
save(); updatePreview();
|
||
});
|
||
});
|
||
$("sceneList").querySelectorAll("[data-adddlg]").forEach(b =>
|
||
b.addEventListener("click", () => {
|
||
const i = +b.dataset.adddlg;
|
||
const first = state.characters[0];
|
||
state.scenes[i].dialogues.push({character: first ? first.name : "Tokoh", text_zh:"", text_id:"", text_en:"", voice: first ? first.voice : "zh-CN-XiaoxiaoNeural"});
|
||
renderScenes(); save();
|
||
}));
|
||
$("sceneList").querySelectorAll("[data-deldlg]").forEach(b =>
|
||
b.addEventListener("click", () => {
|
||
const [i, j] = b.dataset.deldlg.split(":").map(Number);
|
||
state.scenes[i].dialogues.splice(j, 1); renderScenes(); save();
|
||
}));
|
||
$("sceneList").querySelectorAll("[data-delscene]").forEach(b =>
|
||
b.addEventListener("click", () => { state.scenes.splice(+b.dataset.delscene, 1); syncSceneCount(); renderScenes(); renderJobs(); save(); updatePreview(); }));
|
||
$("sceneList").querySelectorAll("[data-speak]").forEach(b =>
|
||
b.addEventListener("click", () => speakScene(+b.dataset.speak)));
|
||
updatePreview();
|
||
}
|
||
|
||
function syncSceneCount(){
|
||
const n = Math.max(1, Math.min(10, +$("numScenes").value || 3));
|
||
state.numScenes = n;
|
||
while(state.scenes.length < n)
|
||
state.scenes.push({visual:"", visual_en:"", narration:"", narration_zh:"", narration_en:"", dialogues:[]});
|
||
if(state.scenes.length > n) state.scenes.length = n;
|
||
}
|
||
|
||
/* ================= PREVIEW SUBTITLE ================= */
|
||
function subStyle(){
|
||
const s = state.subtitle;
|
||
const hexA = h => {
|
||
const n = parseInt(h.slice(1), 16);
|
||
return `rgba(${(n>>16)&255},${(n>>8)&255},${n&255},${s.bgOpacity})`;
|
||
};
|
||
return {
|
||
fontSize: s.fontSize + "px",
|
||
color: s.fontColor,
|
||
background: s.bgOpacity > 0 ? hexA(s.bgColor) : "transparent",
|
||
fontWeight: s.bold ? "700" : "400",
|
||
textShadow: s.outline ? "2px 0 #000,-2px 0 #000,0 2px #000,0 -2px #000,1px 1px #000" : "0 1px 4px #000",
|
||
lineHeight: "1.35",
|
||
};
|
||
}
|
||
function updatePreview(){
|
||
const st = $("stageSub");
|
||
const sc = state.scenes[0];
|
||
let txt = "Subtitle preview — isi adegan pertama dulu.";
|
||
if(sc){
|
||
txt = subTextFor(sc, null) || (sc.dialogues[0] ? subTextFor(sc, sc.dialogues[0]) : txt);
|
||
}
|
||
st.textContent = txt;
|
||
Object.assign(st.style, subStyle());
|
||
st.className = "subtitle " + state.subtitle.position;
|
||
$("stageLabel").textContent = (state.title || "Drama Tanpa Judul") + " — Adegan 1";
|
||
const g = state.genre || "";
|
||
const bg = (g.includes("Xianxia") || g.includes("Kultivasi") || g.includes("Dewa"))
|
||
? "linear-gradient(180deg,#3d1a05,#12081f)" : "linear-gradient(180deg,#1a2340,#0b0b12)";
|
||
$("stage").style.background = bg;
|
||
$("totalDur").textContent = `${state.scenes.length * state.duration} detik (${state.scenes.length} adegan × ${state.duration} detik)`;
|
||
}
|
||
|
||
/* ================= SUARA (browser, demo) ================= */
|
||
function speakScene(i){
|
||
if(!("speechSynthesis" in window)){ alert("Browser ini tidak mendukung suara."); return; }
|
||
const sc = state.scenes[i];
|
||
if(!sc) return;
|
||
speechSynthesis.cancel();
|
||
const lines = [];
|
||
if(sc.narration) lines.push({text: sc.narration, lang:"id-ID"});
|
||
(sc.dialogues||[]).forEach(d => {
|
||
const t = d.text_zh || d.text_id;
|
||
if(t) lines.push({text: t, lang: d.text_zh ? "zh-CN" : "id-ID"});
|
||
});
|
||
if(!lines.length){ alert("Adegan ini belum ada narasi/dialog."); return; }
|
||
lines.forEach(l => {
|
||
const u = new SpeechSynthesisUtterance(l.text);
|
||
u.lang = l.lang;
|
||
const v = speechSynthesis.getVoices().find(v => v.lang && v.lang.toLowerCase().startsWith(l.lang.slice(0,2)));
|
||
if(v) u.voice = v;
|
||
speechSynthesis.speak(u);
|
||
});
|
||
}
|
||
|
||
/* ================= API ENGINE ================= */
|
||
async function api(path, method, body){
|
||
if(!engineUrl) throw new Error("URL Engine belum diisi. Jalankan notebook dulu, lalu paste URL-nya.");
|
||
const r = await fetch(engineUrl.replace(/\/$/, "") + path, {
|
||
method: method || "GET",
|
||
headers: {"Content-Type":"application/json"},
|
||
body: body ? JSON.stringify(body) : undefined,
|
||
});
|
||
const data = await r.json().catch(() => ({}));
|
||
if(!r.ok) throw new Error(data.error || ("HTTP " + r.status));
|
||
return data;
|
||
}
|
||
function setPill(on, text){
|
||
const p = $("enginePill");
|
||
p.className = "pill " + (on ? "on" : "off");
|
||
p.textContent = text;
|
||
}
|
||
async function testConnection(){
|
||
engineUrl = $("engineUrl").value.trim();
|
||
if(!engineUrl){ alert("Isi URL Engine dulu (dari output notebook)."); return; }
|
||
setPill(false, "● Mengecek...");
|
||
try{
|
||
const h = await api("/health");
|
||
engineOnline = true; demoMode = false;
|
||
setPill(true, "● Engine online (" + (h.platform || "?") + ")");
|
||
$("engineInfo").style.display = "block";
|
||
$("engineInfo").innerHTML = `✅ Terhubung! Model naskah: <b>${esc(h.model||"")}</b> · Video: <b>${esc(h.video_model||"")}</b> · GPU: <b>${esc(h.gpu||"—")}</b> · Video model ${h.video_loaded ? "sudah dimuat" : "akan dimuat saat render pertama"}.`;
|
||
}catch(e){
|
||
engineOnline = false;
|
||
setPill(false, "● Engine offline");
|
||
$("engineInfo").style.display = "block";
|
||
$("engineInfo").innerHTML = `❌ Gagal terhubung: ${esc(e.message)}<br>Cek: notebook masih running? URL sudah benar (tanpa garis miring di akhir)? Coba buka <b>${esc(engineUrl)}/health</b> di tab baru.`;
|
||
}
|
||
}
|
||
|
||
/* ================= JUDUL ================= */
|
||
function localTitles(){
|
||
const t = (state.title || "Drama Tanpa Judul").trim();
|
||
const mc = (state.characters[0] && state.characters[0].name.split(" ")[0]) || "Dia";
|
||
return {titles:[
|
||
`🔥${t}, semua kakak senior level maksimal panik`,
|
||
"Tubuhnya tak terkalahkan, ia turun gunung untuk menyembunyikan kekuatan aslinya!",
|
||
"Dihina sebagai sampah sekte, ternyata dia dewa pedang yang bereinkarnasi!",
|
||
`${t} — episode paling panas minggu ini!`,
|
||
`Sistem bangkit! ${mc} yang diremehkan kini tak terkalahkan!`,
|
||
], hashtags: DEMO_TAGS};
|
||
}
|
||
async function genTitles(){
|
||
$("btnTitle").disabled = true;
|
||
try{
|
||
let data;
|
||
if(engineOnline){
|
||
data = await api("/title", "POST", {title_hint: state.title, genre: state.genre,
|
||
characters: state.characters.map(c => ({name:c.name, role:c.role, desc:c.desc}))});
|
||
} else {
|
||
data = localTitles();
|
||
alert("Engine offline — judul dibuat dari template lokal. Hubungkan engine untuk judul AI.");
|
||
}
|
||
showTitles(data);
|
||
}catch(e){ alert("Gagal membuat judul: " + e.message); }
|
||
$("btnTitle").disabled = false;
|
||
}
|
||
function showTitles(data){
|
||
$("titleBox").style.display = "block";
|
||
$("titleList").innerHTML = (data.titles||[]).map(t => `<li data-t="${esc(t)}">${esc(t)}</li>`).join("");
|
||
$("tagBox").innerHTML = (data.hashtags||[]).map(t => `<span class="tag" data-tag="${esc(t)}">${esc(t)}</span>`).join("");
|
||
$("titleList").querySelectorAll("[data-t]").forEach(li =>
|
||
li.addEventListener("click", () => {
|
||
state.title = li.dataset.t; $("title").value = state.title;
|
||
save(); updatePreview();
|
||
}));
|
||
$("tagBox").querySelectorAll("[data-tag]").forEach(sp =>
|
||
sp.addEventListener("click", async () => {
|
||
try{ await navigator.clipboard.writeText(sp.dataset.tag); sp.textContent = sp.dataset.tag + " ✓"; }
|
||
catch(e){ alert(sp.dataset.tag); }
|
||
}));
|
||
}
|
||
|
||
/* ================= NASKAH ================= */
|
||
async function genScript(){
|
||
if(!engineOnline){
|
||
alert("Hubungkan engine dulu (Test Koneksi) — atau klik 'Isi Contoh' untuk memakai naskah demo.");
|
||
return;
|
||
}
|
||
$("btnScript").disabled = true;
|
||
$("btnScript").textContent = "⏳ AI menulis naskah...";
|
||
try{
|
||
const data = await api("/script", "POST", {
|
||
title: state.title, genre: state.genre, num_scenes: state.numScenes,
|
||
duration: state.duration,
|
||
characters: state.characters.map(c => ({name:c.name, role:c.role, desc:c.desc})),
|
||
});
|
||
state.scenes = (data.scenes||[]).map(s => ({
|
||
visual: s.visual||"", visual_en: s.visual_en||"",
|
||
narration: s.narration||"", narration_zh: s.narration_zh||"", narration_en: s.narration_en||"",
|
||
dialogues: (s.dialogues||[]).map(d => ({...d, voice: voiceOf(d.character)})),
|
||
}));
|
||
syncSceneCountKeep();
|
||
renderScenes(); save();
|
||
alert("Naskah selesai dibuat AI — cek dan edit tiap adegan sebelum render.");
|
||
}catch(e){ alert("Gagal membuat naskah: " + e.message); }
|
||
$("btnScript").disabled = false;
|
||
$("btnScript").textContent = "✨ Buatkan Naskah Otomatis";
|
||
}
|
||
function syncSceneCountKeep(){
|
||
// samakan jumlah adegan dengan input, tanpa menghapus isi yang sudah ada
|
||
const n = Math.max(1, Math.min(10, +$("numScenes").value || state.scenes.length));
|
||
state.numScenes = n;
|
||
while(state.scenes.length < n)
|
||
state.scenes.push({visual:"", visual_en:"", narration:"", narration_zh:"", narration_en:"", dialogues:[]});
|
||
if(state.scenes.length > n) state.scenes.length = n;
|
||
}
|
||
|
||
/* ================= RENDER & ANTRIAN ================= */
|
||
function renderJobs(){
|
||
$("jobList").innerHTML = state.scenes.map((s, i) => {
|
||
const j = state.jobs[i] || {status:"antri", progress:0};
|
||
const label = {antri:"Antri", berjalan:"Berjalan", selesai:"Selesai", gagal:"Gagal"}[j.status] || j.status;
|
||
return `<div class="job">
|
||
<div class="top"><b>Adegan ${i+1}</b>
|
||
<span class="status ${j.status}">${label}</span>
|
||
<span style="color:var(--muted);font-size:12px">${j.progress||0}%</span>
|
||
${j.videoUrl ? `<button class="secondary" data-dl="${i}">⬇ Video adegan</button>` : ""}
|
||
</div>
|
||
<div class="bar"><i style="width:${j.progress||0}%"></i></div>
|
||
${j.error ? `<div class="err">❌ ${esc(j.error)}</div>` : ""}
|
||
${j.videoUrl ? `<video src="${j.videoUrl}" controls playsinline></video>` : ""}
|
||
</div>`;
|
||
}).join("");
|
||
$("jobList").querySelectorAll("[data-dl]").forEach(b =>
|
||
b.addEventListener("click", () => {
|
||
const a = document.createElement("a");
|
||
a.href = state.jobs[+b.dataset.dl].videoUrl;
|
||
a.download = `drama-adegan-${+b.dataset.dl + 1}.mp4`;
|
||
a.click();
|
||
}));
|
||
}
|
||
function setJob(i, patch){
|
||
state.jobs[i] = {...(state.jobs[i] || {status:"antri", progress:0}), ...patch};
|
||
renderJobs();
|
||
}
|
||
|
||
async function renderAll(){
|
||
if(!state.scenes.length){ alert("Belum ada adegan."); return; }
|
||
if(demoMode || !engineOnline){
|
||
if(!engineOnline && !demoMode){
|
||
if(!confirm("Engine belum terhubung. Render pakai Mode Demo (simulasi di browser, tanpa suara)?")) return;
|
||
demoMode = true; setPill(false, "● Mode Demo (browser)");
|
||
}
|
||
await demoRenderAll();
|
||
return;
|
||
}
|
||
$("btnRender").disabled = true;
|
||
try{
|
||
for(let i = 0; i < state.scenes.length; i++){
|
||
const s = state.scenes[i];
|
||
setJob(i, {status:"berjalan", progress:2});
|
||
const res = await api("/render", "POST", {
|
||
scene_index: i, visual: s.visual, visual_en: s.visual_en || "",
|
||
genre: state.genre,
|
||
characters: state.characters.map(c => ({name:c.name, desc:c.desc})),
|
||
duration: state.duration, width: state.resolution, height: state.resolution === 720 ? 1280 : 832,
|
||
seed: Math.floor(Math.random()*999999),
|
||
});
|
||
setJob(i, {jobId: res.job_id, status:"berjalan", progress:5});
|
||
}
|
||
startPolling();
|
||
}catch(e){ alert("Gagal memulai render: " + e.message); }
|
||
$("btnRender").disabled = false;
|
||
}
|
||
function startPolling(){
|
||
if(pollTimer) clearInterval(pollTimer);
|
||
pollTimer = setInterval(async () => {
|
||
try{
|
||
const st = await api("/status");
|
||
let allDone = true;
|
||
for(let i = 0; i < state.scenes.length; i++){
|
||
const j = state.jobs[i];
|
||
if(!j || !j.jobId) continue;
|
||
const info = st.jobs[j.jobId];
|
||
if(!info) continue;
|
||
if(info.status === "done"){
|
||
setJob(i, {status:"selesai", progress:100, videoUrl: engineUrl.replace(/\/$/,"") + info.video_url});
|
||
} else if(info.status === "error"){
|
||
setJob(i, {status:"gagal", progress:0, error: info.error || "Render gagal"});
|
||
} else {
|
||
allDone = false;
|
||
setJob(i, {status:"berjalan", progress: info.progress || 5});
|
||
}
|
||
}
|
||
// final job
|
||
if(state.finalJobId){
|
||
const fin = st.jobs[state.finalJobId];
|
||
if(fin){
|
||
if(fin.status === "done"){
|
||
showFinal(fin); clearInterval(pollTimer); pollTimer = null;
|
||
} else if(fin.status === "error"){
|
||
alert("Gabung video gagal: " + (fin.error || "unknown"));
|
||
clearInterval(pollTimer); pollTimer = null;
|
||
}
|
||
}
|
||
} else if(allDone){
|
||
clearInterval(pollTimer); pollTimer = null;
|
||
}
|
||
}catch(e){ /* biarkan polling jalan terus; error jaringan sementara */ }
|
||
}, 3000);
|
||
}
|
||
function showFinal(info){
|
||
$("finalBox").style.display = "block";
|
||
const base = engineUrl.replace(/\/$/,"");
|
||
$("finalVideo").src = base + info.video_url;
|
||
$("dlMp4").href = base + info.video_url;
|
||
$("dlSrt").href = base + (info.srt_url || "");
|
||
$("finalWarn").textContent = (info.warnings||[]).join(" ");
|
||
}
|
||
|
||
async function assemble(){
|
||
if(demoMode || !engineOnline){
|
||
if(!engineOnline && !demoMode){
|
||
if(!confirm("Engine belum terhubung. Gabung video pakai Mode Demo?")) return;
|
||
demoMode = true; setPill(false, "● Mode Demo (browser)");
|
||
}
|
||
await demoAssemble();
|
||
return;
|
||
}
|
||
const missing = state.scenes.findIndex((s, i) => !state.jobs[i] || state.jobs[i].status !== "selesai");
|
||
if(missing >= 0){ alert(`Adegan ${missing+1} belum selesai di-render. Render semua adegan dulu.`); return; }
|
||
$("btnAssemble").disabled = true;
|
||
try{
|
||
const payload = {
|
||
title: state.title,
|
||
scenes: state.scenes.map((s, i) => ({
|
||
job_id: state.jobs[i].jobId,
|
||
narration: s.narration, narration_zh: s.narration_zh, narration_en: s.narration_en,
|
||
narration_voice: state.narrVoice,
|
||
dialogues: (s.dialogues||[]).map(d => ({...d, voice: voiceOf(d.character)})),
|
||
})),
|
||
subtitle: state.subtitle,
|
||
width: state.resolution, height: state.resolution === 720 ? 1280 : 832,
|
||
};
|
||
const res = await api("/assemble", "POST", payload);
|
||
state.finalJobId = res.job_id;
|
||
alert("Penggabungan dimulai — video final + SRT akan muncul di bawah saat selesai.");
|
||
startPolling();
|
||
}catch(e){ alert("Gagal menggabung: " + e.message); }
|
||
$("btnAssemble").disabled = false;
|
||
}
|
||
|
||
/* ================= MODE DEMO (canvas, tanpa GPU/suara) ================= */
|
||
function fmtSrt(sec){
|
||
const ms = Math.round(sec * 1000);
|
||
const h = String(Math.floor(ms/3600000)).padStart(2,"0");
|
||
const m = String(Math.floor(ms/60000)%60).padStart(2,"0");
|
||
const s = String(Math.floor(ms/1000)%60).padStart(2,"0");
|
||
return `${h}:${m}:${s},${String(ms%1000).padStart(3,"0")}`;
|
||
}
|
||
function sceneLines(sc){
|
||
const lines = [];
|
||
if(sc.narration) lines.push(subTextFor(sc, null));
|
||
(sc.dialogues||[]).forEach(d => { const t = subTextFor(sc, d); if(t) lines.push(t); });
|
||
return lines;
|
||
}
|
||
function buildSRT(){
|
||
let out = "", idx = 1, t = 0;
|
||
state.scenes.forEach(sc => {
|
||
const lines = sceneLines(sc);
|
||
const total = lines.reduce((a, x) => a + Math.max(8, x.length), 0) || 1;
|
||
lines.forEach(txt => {
|
||
const share = state.duration * Math.max(8, txt.length) / total;
|
||
out += `${idx++}\n${fmtSrt(t)} --> ${fmtSrt(t+share)}\n${txt}\n\n`;
|
||
t += share;
|
||
});
|
||
});
|
||
return out;
|
||
}
|
||
function wrapText(ctx, text, maxW){
|
||
const lines = [];
|
||
String(text).split("\n").forEach(part => {
|
||
const words = part.split(/\s+/);
|
||
let cur = "";
|
||
words.forEach(w => {
|
||
const test = cur ? cur + " " + w : w;
|
||
if(ctx.measureText(test).width > maxW && cur){ lines.push(cur); cur = w; }
|
||
else cur = test;
|
||
});
|
||
if(cur) lines.push(cur);
|
||
});
|
||
return lines;
|
||
}
|
||
function drawDemoFrame(ctx, W, H, si, t, dur){
|
||
const grads = [
|
||
["#ff9a5c","#7b2d8b","#1a1033"],
|
||
["#2b2a55","#14122e","#0b0b12"],
|
||
["#ff3b30","#7a0e0e","#12060a"],
|
||
];
|
||
const g = grads[si % 3];
|
||
const bg = ctx.createLinearGradient(0, 0, 0, H);
|
||
bg.addColorStop(0, g[0]); bg.addColorStop(0.55, g[1]); bg.addColorStop(1, g[2]);
|
||
ctx.fillStyle = bg; ctx.fillRect(0, 0, W, H);
|
||
const z = 1 + 0.06 * (t / dur);
|
||
ctx.save();
|
||
ctx.translate(W/2, H/2); ctx.scale(z, z); ctx.translate(-W/2, -H/2);
|
||
if(si % 3 === 0){
|
||
ctx.fillStyle = "#ffd76a";
|
||
ctx.beginPath(); ctx.arc(W*0.5, H*0.30, 46, 0, 7); ctx.fill();
|
||
ctx.fillStyle = "rgba(20,10,40,.85)";
|
||
ctx.beginPath(); ctx.moveTo(0, H*0.62); ctx.lineTo(W*0.3, H*0.42); ctx.lineTo(W*0.55, H*0.62); ctx.closePath(); ctx.fill();
|
||
ctx.beginPath(); ctx.moveTo(W*0.4, H*0.66); ctx.lineTo(W*0.75, H*0.44); ctx.lineTo(W, H*0.66); ctx.closePath(); ctx.fill();
|
||
ctx.strokeStyle = "rgba(255,255,255,.5)"; ctx.lineWidth = 3;
|
||
for(let k = 0; k < 6; k++){
|
||
const y = H*0.66 + k*26;
|
||
ctx.beginPath(); ctx.moveTo(W*0.5 - 40 - k*8, y); ctx.lineTo(W*0.5 + 40 + k*8, y); ctx.stroke();
|
||
}
|
||
ctx.fillStyle = "#fff";
|
||
ctx.beginPath(); ctx.arc(W*0.5, H*0.60, 14, 0, 7); ctx.fill();
|
||
ctx.beginPath(); ctx.moveTo(W*0.5 - 20, H*0.78); ctx.lineTo(W*0.5, H*0.62); ctx.lineTo(W*0.5 + 20, H*0.78); ctx.closePath(); ctx.fill();
|
||
} else if(si % 3 === 1){
|
||
ctx.fillStyle = "rgba(0,0,0,.35)";
|
||
[40, 180, 320, 400].forEach(x => ctx.fillRect(x - 14, 0, 28, H));
|
||
const glow = ctx.createRadialGradient(W/2, H*0.62, 10, W/2, H*0.62, 180);
|
||
glow.addColorStop(0, "rgba(245,185,66,.9)"); glow.addColorStop(1, "rgba(245,185,66,0)");
|
||
ctx.fillStyle = glow; ctx.beginPath(); ctx.arc(W/2, H*0.62, 180, 0, 7); ctx.fill();
|
||
ctx.fillStyle = "#fff";
|
||
ctx.beginPath(); ctx.arc(W/2, H*0.62, 14, 0, 7); ctx.fill();
|
||
ctx.beginPath(); ctx.moveTo(W/2 - 20, H*0.78); ctx.lineTo(W/2, H*0.62); ctx.lineTo(W/2 + 20, H*0.78); ctx.closePath(); ctx.fill();
|
||
} else {
|
||
const pulse = 0.6 + 0.4 * Math.sin(t * 4);
|
||
const glow = ctx.createRadialGradient(W/2, H*0.55, 10, W/2, H*0.55, 260);
|
||
glow.addColorStop(0, `rgba(255,200,80,${0.95*pulse})`); glow.addColorStop(1, "rgba(255,60,40,0)");
|
||
ctx.fillStyle = glow; ctx.beginPath(); ctx.arc(W/2, H*0.55, 260, 0, 7); ctx.fill();
|
||
ctx.strokeStyle = "#ffe9a8"; ctx.lineWidth = 5;
|
||
for(let k = 0; k < 3; k++){
|
||
const a = t * 1.2 + k * 2.1, r = 120 + k * 30;
|
||
const x = W/2 + Math.cos(a) * r, y = H*0.55 + Math.sin(a) * r * 0.7;
|
||
ctx.save(); ctx.translate(x, y); ctx.rotate(a);
|
||
ctx.beginPath(); ctx.moveTo(-34, 0); ctx.lineTo(34, 0); ctx.stroke(); ctx.restore();
|
||
}
|
||
ctx.fillStyle = "#fff";
|
||
ctx.beginPath(); ctx.arc(W/2, H*0.55, 15, 0, 7); ctx.fill();
|
||
ctx.beginPath(); ctx.moveTo(W/2 - 22, H*0.74); ctx.lineTo(W/2, H*0.56); ctx.lineTo(W/2 + 22, H*0.74); ctx.closePath(); ctx.fill();
|
||
}
|
||
ctx.restore();
|
||
const vg = ctx.createRadialGradient(W/2, H/2, H*0.3, W/2, H/2, H*0.75);
|
||
vg.addColorStop(0, "rgba(0,0,0,0)"); vg.addColorStop(1, "rgba(0,0,0,.45)");
|
||
ctx.fillStyle = vg; ctx.fillRect(0, 0, W, H);
|
||
// subtitle aktif pada detik t (dibagi rata sesuai panjang teks)
|
||
const sc = state.scenes[si];
|
||
const lines = sc ? sceneLines(sc) : [];
|
||
if(lines.length){
|
||
const total = lines.reduce((a, x) => a + Math.max(8, x.length), 0);
|
||
let acc = 0, active = lines[0];
|
||
for(const txt of lines){
|
||
const share = dur * Math.max(8, txt.length) / total;
|
||
if(t < acc + share){ active = txt; break; }
|
||
acc += share; active = txt;
|
||
}
|
||
const s = state.subtitle;
|
||
const fs = s.fontSize;
|
||
ctx.font = `${s.bold ? "700 " : ""}${fs}px system-ui, sans-serif`;
|
||
ctx.textAlign = "center"; ctx.textBaseline = "middle";
|
||
const wrapped = wrapText(ctx, active, W - 48);
|
||
const lh = fs * 1.35;
|
||
const boxH = wrapped.length * lh + 16;
|
||
const y0 = s.position === "middle" ? H/2 - boxH/2 : H - 60 - boxH;
|
||
if(s.bgOpacity > 0){
|
||
const n = parseInt(s.bgColor.slice(1), 16);
|
||
ctx.fillStyle = `rgba(${(n>>16)&255},${(n>>8)&255},${n&255},${s.bgOpacity})`;
|
||
ctx.fillRect(12, y0, W - 24, boxH);
|
||
}
|
||
wrapped.forEach((ln, k) => {
|
||
const y = y0 + 8 + lh * k + lh / 2;
|
||
if(s.outline){ ctx.strokeStyle = "#000"; ctx.lineWidth = 4; ctx.strokeText(ln, W/2, y); }
|
||
ctx.fillStyle = s.fontColor;
|
||
ctx.fillText(ln, W/2, y);
|
||
});
|
||
}
|
||
// label adegan
|
||
ctx.fillStyle = "rgba(255,255,255,.85)";
|
||
ctx.font = "600 20px system-ui, sans-serif";
|
||
ctx.textAlign = "left";
|
||
ctx.fillText(`Adegan ${si + 1} · ${state.title}`, 16, 36);
|
||
}
|
||
async function recordCanvas(canvas, durSec, drawFn){
|
||
const stream = canvas.captureStream(16);
|
||
let mime = "video/webm;codecs=vp9";
|
||
if(!MediaRecorder.isTypeSupported(mime)) mime = "video/webm";
|
||
const rec = new MediaRecorder(stream, {mimeType: mime, videoBitsPerSecond: 2_500_000});
|
||
const chunks = [];
|
||
rec.ondataavailable = e => { if(e.data.size) chunks.push(e.data); };
|
||
const done = new Promise(res => rec.onstop = res);
|
||
rec.start();
|
||
const t0 = performance.now();
|
||
await new Promise(resolve => {
|
||
(function frame(){
|
||
const t = (performance.now() - t0) / 1000;
|
||
drawFn(Math.min(t, durSec));
|
||
if(t < durSec) requestAnimationFrame(frame);
|
||
else resolve();
|
||
})();
|
||
});
|
||
rec.stop();
|
||
await done;
|
||
return new Blob(chunks, {type: "video/webm"});
|
||
}
|
||
async function demoRenderAll(){
|
||
const canvas = document.createElement("canvas");
|
||
canvas.width = 480; canvas.height = 832;
|
||
const ctx = canvas.getContext("2d");
|
||
for(let i = 0; i < state.scenes.length; i++){
|
||
setJob(i, {status:"berjalan", progress:10});
|
||
const blob = await recordCanvas(canvas, state.duration, t => drawDemoFrame(ctx, 480, 832, i, t, state.duration));
|
||
setJob(i, {status:"selesai", progress:100, videoUrl: URL.createObjectURL(blob)});
|
||
}
|
||
alert("Render demo selesai (simulasi visual di browser, tanpa suara). Klik 'Gabung & Download Video Final' untuk video episode demo.");
|
||
}
|
||
async function demoAssemble(){
|
||
const canvas = document.createElement("canvas");
|
||
canvas.width = 480; canvas.height = 832;
|
||
const ctx = canvas.getContext("2d");
|
||
const total = state.scenes.length * state.duration;
|
||
const stream = canvas.captureStream(16);
|
||
let mime = "video/webm;codecs=vp9";
|
||
if(!MediaRecorder.isTypeSupported(mime)) mime = "video/webm";
|
||
const rec = new MediaRecorder(stream, {mimeType: mime, videoBitsPerSecond: 2_500_000});
|
||
const chunks = [];
|
||
rec.ondataavailable = e => { if(e.data.size) chunks.push(e.data); };
|
||
const done = new Promise(res => rec.onstop = res);
|
||
rec.start();
|
||
const t0 = performance.now();
|
||
await new Promise(resolve => {
|
||
(function frame(){
|
||
const t = (performance.now() - t0) / 1000;
|
||
if(t >= total){ resolve(); return; }
|
||
const si = Math.min(state.scenes.length - 1, Math.floor(t / state.duration));
|
||
drawDemoFrame(ctx, 480, 832, si, t - si * state.duration, state.duration);
|
||
requestAnimationFrame(frame);
|
||
})();
|
||
});
|
||
rec.stop();
|
||
await done;
|
||
const blob = new Blob(chunks, {type: "video/webm"});
|
||
const srt = new Blob([buildSRT()], {type: "text/plain"});
|
||
$("finalBox").style.display = "block";
|
||
$("finalVideo").src = URL.createObjectURL(blob);
|
||
$("dlMp4").href = $("finalVideo").src;
|
||
$("dlMp4").setAttribute("download", "drama-demo-final.webm");
|
||
$("dlSrt").href = URL.createObjectURL(srt);
|
||
$("finalWarn").textContent = "Mode Demo: video simulasi tanpa suara (format .webm). Video asli dari GPU berformat .mp4 dengan suara + subtitle terbakar.";
|
||
$("finalVideo").scrollIntoView({behavior:"smooth", block:"center"});
|
||
}
|
||
|
||
/* ================= CONTOH / RESET ================= */
|
||
function loadDemo(){
|
||
state.title = "Adik Perempuan Turun Gunung";
|
||
state.genre = "Xianxia · Sistem · Turun Gunung";
|
||
state.mode = "episode";
|
||
state.numScenes = 3; state.duration = 5; state.resolution = 480;
|
||
state.narrVoice = "id-ID-GadisNeural";
|
||
state.characters = JSON.parse(JSON.stringify(DEMO_CHARS));
|
||
state.scenes = JSON.parse(JSON.stringify(DEMO_SCENES));
|
||
state.subtitle = {...DEFAULT_SUB};
|
||
state.jobs = {}; state.finalJobId = null;
|
||
syncForm(); renderChars(); renderScenes(); renderJobs(); save();
|
||
}
|
||
function syncForm(){
|
||
$("title").value = state.title;
|
||
$("genre").value = state.genre;
|
||
$("numScenes").value = state.numScenes;
|
||
$("duration").value = state.duration;
|
||
$("resolution").value = String(state.resolution);
|
||
$("narrVoice").value = state.narrVoice;
|
||
$("subLang").value = state.subtitle.language;
|
||
$("subSize").value = state.subtitle.fontSize;
|
||
$("subPos").value = state.subtitle.position;
|
||
$("subColor").value = state.subtitle.fontColor;
|
||
$("subBg").value = state.subtitle.bgColor;
|
||
$("subOpacity").value = state.subtitle.bgOpacity;
|
||
$("subBold").checked = state.subtitle.bold;
|
||
$("subOutline").checked = state.subtitle.outline;
|
||
document.querySelectorAll("#modeSeg button").forEach(b =>
|
||
b.classList.toggle("active", b.dataset.mode === state.mode));
|
||
}
|
||
|
||
/* ================= EVENTS & INIT ================= */
|
||
function bindEvents(){
|
||
$("btnTest").addEventListener("click", testConnection);
|
||
$("btnDemo").addEventListener("click", () => {
|
||
demoMode = true; engineOnline = false;
|
||
setPill(false, "● Mode Demo (browser)");
|
||
if(!state.scenes.length) loadDemo();
|
||
alert("Mode Demo aktif: drama contoh 'Adik Perempuan Turun Gunung' sudah dimuat. Klik 'Render Semua Adegan' untuk mencoba.");
|
||
});
|
||
$("btnTitle").addEventListener("click", genTitles);
|
||
$("btnSample").addEventListener("click", () => { loadDemo(); alert("Drama contoh dimuat: Adik Perempuan Turun Gunung (3 adegan)."); });
|
||
$("btnReset").addEventListener("click", () => {
|
||
if(!confirm("Reset semua isi proyek?")) return;
|
||
localStorage.removeItem(LS_KEY);
|
||
state.characters = []; state.scenes = []; state.jobs = {}; state.finalJobId = null;
|
||
state.title = ""; state.subtitle = {...DEFAULT_SUB};
|
||
syncForm(); renderChars(); renderScenes(); renderJobs(); save();
|
||
});
|
||
$("btnAddChar").addEventListener("click", () => {
|
||
state.characters.push({id: uid(), name:"Tokoh Baru", role:"", desc:"", voice:"zh-CN-XiaoxiaoNeural"});
|
||
renderChars(); save();
|
||
});
|
||
$("btnScript").addEventListener("click", genScript);
|
||
$("btnAddScene").addEventListener("click", () => {
|
||
state.scenes.push({visual:"", visual_en:"", narration:"", narration_zh:"", narration_en:"", dialogues:[]});
|
||
$("numScenes").value = state.scenes.length; state.numScenes = state.scenes.length;
|
||
renderScenes(); renderJobs(); save();
|
||
});
|
||
$("btnRender").addEventListener("click", renderAll);
|
||
$("btnAssemble").addEventListener("click", assemble);
|
||
document.querySelectorAll("#modeSeg button").forEach(b =>
|
||
b.addEventListener("click", () => {
|
||
state.mode = b.dataset.mode;
|
||
document.querySelectorAll("#modeSeg button").forEach(x => x.classList.toggle("active", x === b));
|
||
$("modeNote").textContent = state.mode === "episode"
|
||
? "Mode Episode: semua adegan digabung jadi satu video panjang — format kompilasi untuk update harian, seperti channel drama Cina."
|
||
: "Mode Satuan: tiap adegan di-render dan di-download terpisah — cocok untuk klip pendek / Shorts / Reels.";
|
||
save();
|
||
}));
|
||
$("title").addEventListener("input", e => { state.title = e.target.value; save(); updatePreview(); });
|
||
$("genre").addEventListener("change", e => { state.genre = e.target.value; save(); updatePreview(); });
|
||
$("numScenes").addEventListener("change", () => { syncSceneCount(); renderScenes(); renderJobs(); save(); updatePreview(); });
|
||
$("duration").addEventListener("change", e => { state.duration = Math.max(3, Math.min(8, +e.target.value || 5)); save(); updatePreview(); });
|
||
$("resolution").addEventListener("change", e => { state.resolution = +e.target.value; save(); });
|
||
$("narrVoice").addEventListener("change", e => { state.narrVoice = e.target.value; save(); });
|
||
const subBind = (id, key, parse) => $(id).addEventListener("input", e => {
|
||
state.subtitle[key] = parse ? parse(e.target.value) : e.target.value;
|
||
save(); updatePreview();
|
||
});
|
||
subBind("subLang", "language"); subBind("subSize", "fontSize", v => +v || 28);
|
||
subBind("subPos", "position"); subBind("subColor", "fontColor"); subBind("subBg", "bgColor");
|
||
subBind("subOpacity", "bgOpacity", v => Math.max(0, Math.min(1, +v || 0)));
|
||
$("subBold").addEventListener("change", e => { state.subtitle.bold = e.target.checked; save(); updatePreview(); });
|
||
$("subOutline").addEventListener("change", e => { state.subtitle.outline = e.target.checked; save(); updatePreview(); });
|
||
$("engineUrl").addEventListener("input", () => { engineOnline = false; setPill(false, "● Engine offline"); });
|
||
}
|
||
|
||
(function init(){
|
||
const had = load();
|
||
if(!had || !state.scenes.length) loadDemo();
|
||
syncForm();
|
||
renderChars(); renderScenes(); renderJobs();
|
||
bindEvents();
|
||
updatePreview();
|
||
})();
|
||
</script>
|
||
</body>
|
||
</html>
|