"use strict"; // A guia Projeto mantém a seleção da sequência, faixas e clipes fora das // regras específicas de edição. O estado definitivo será persistido pelo // repositório SQLite na próxima etapa da integração. var projetoSequencias = []; var projetoAtual = null; function projetoListarSequencias() { var botao = document.getElementById("btnProjetoCarregar"); if (botao) botao.disabled = true; var select = document.getElementById("projetoSequenciaSelect"); var info = document.getElementById("projetoInfo"); info.textContent = "Lendo sequências, faixas e clipes do Premiere…"; cs.evalScript( "(function(){try{" + "if(!app.project)return JSON.stringify({ok:false,error:'Nenhum projeto aberto.'});" + "var saida=[];" + "for(var i=0;i= 0 ? ativa : 0; projetoSelecionarSequencia(); } else { info.textContent = "Nenhuma sequência encontrada no projeto do Premiere."; } } ); } function projetoSelecionarSequencia() { var select = document.getElementById("projetoSequenciaSelect"); projetoAtual = projetoSequencias.find(function (item) { return item.id === select.value; }) || null; if (!projetoAtual) return; document.getElementById("projetoTimelineCard").hidden = false; document.getElementById("projetoStatus").textContent = "Sequência selecionada"; document.getElementById("projetoTimelineStatus").textContent = projetoAtual.nome; document.getElementById("projetoDuracao").textContent = formatSequenceDuration(projetoAtual.duracao); document.getElementById("projetoResolucao").textContent = projetoAtual.largura && projetoAtual.altura ? projetoAtual.largura + " × " + projetoAtual.altura : "Não informada"; document.getElementById("projetoTotalFaixas").textContent = projetoAtual.faixas.length; document.getElementById("projetoTotalClipes").textContent = projetoAtual.faixas.reduce(function (total, faixa) { return total + faixa.clipes.length; }, 0); var container = document.getElementById("projetoFaixas"); container.innerHTML = ""; projetoAtual.faixas.forEach(function (faixa) { var bloco = document.createElement("div"); bloco.className = "scanner-subsection"; bloco.innerHTML = '"; faixa.clipes.forEach(function (clipe) { bloco.innerHTML += '"; }); container.appendChild(bloco); }); document.getElementById("btnProjetoContinuar").disabled = false; document.getElementById("btnProjetoSalvar").disabled = false; projetoCarregarTipoDeVideo(); document.getElementById("projetoInfo").textContent = "A sequência foi carregada. Selecione as faixas e clipes que participarão do plano."; } function projetoCarregarTipoDeVideo() { var select = document.getElementById("projetoTipoVideoSelect"); var info = document.getElementById("projetoTipoVideoInfo"); select.disabled = true; runStreamed(SCANNER_PYTHON_BIN, [CONSULTAR_EDICAO_SCRIPT, projetoAtual.id, "--banco", ANALISES_DB_PATH], function () {}, function (codigo, ultimoErro, ultimaSaida) { if (codigo !== 0) { info.textContent = ultimoErro || "Nenhum tipo de vídeo salvo para esta sequência."; return; } try { var edicao = JSON.parse(ultimaSaida).edicao; var tipos = tiposVideoLer().filter(function (item) { return item.ativo !== false; }); var tipo = tipos.filter(function (item) { return item.id === edicao.tipo_de_video; })[0]; select.innerHTML = ""; tipos.forEach(function (item) { var opcao = document.createElement("option"); opcao.value = item.id; opcao.textContent = item.nome; select.appendChild(opcao); }); if (!tipo) { var tipoDesconhecido = document.createElement("option"); tipoDesconhecido.value = edicao.tipo_de_video; tipoDesconhecido.textContent = edicao.tipo_de_video; select.appendChild(tipoDesconhecido); } select.value = edicao.tipo_de_video; select.disabled = false; silenceState.tipoVideoId = edicao.tipo_de_video; silenceState.tipoVideo = tipo || null; info.textContent = "Tipo carregado da edição concluída mais recente."; } catch (erro) { info.textContent = "Não foi possível interpretar o tipo salvo: " + erro.message; } }); } function projetoSelecionarTipoVideo() { var tipo = tiposVideoLer().filter(function (item) { return item.id === document.getElementById("projetoTipoVideoSelect").value; })[0] || null; silenceState.tipoVideoId = tipo ? tipo.id : null; silenceState.tipoVideo = tipo; document.getElementById("projetoTipoVideoInfo").textContent = tipo ? tipo.nome + " · disponível para a edição." : "Nenhum tipo selecionado."; } function projetoSalvar() { if (!projetoAtual) return; var faixas = Array.prototype.slice.call(document.querySelectorAll("[data-projeto-faixa]:checked")).map(function (item) { return item.getAttribute("data-projeto-faixa"); }); var clipes = Array.prototype.slice.call(document.querySelectorAll("[data-projeto-clipe]:checked")).map(function (item) { return item.getAttribute("data-projeto-clipe"); }); var pedido = path.join(os.tmpdir(), "pedido-projeto-edicao-" + Date.now() + ".json"); fs.writeFileSync(pedido, JSON.stringify({ nome: projetoAtual.nome, video_id: projetoAtual.id, faixas: faixas, clipes: clipes, }, null, 2), "utf-8"); setBusy("btnProjetoSalvar", true); runStreamed(SCANNER_PYTHON_BIN, [REGISTRAR_PROJETO_SCRIPT, pedido, "--banco", ANALISES_DB_PATH], function (linha) { silenceLog(linha); }, function (codigo, ultimoErro) { setBusy("btnProjetoSalvar", false); if (codigo !== 0) { showToast("err", ultimoErro || "Não foi possível salvar o projeto."); return; } document.getElementById("projetoStatus").textContent = "Projeto salvo no banco"; showToast("ok", "Projeto salvo com " + faixas.length + " faixa(s) e " + clipes.length + " clipe(s)."); }); } function projetoContinuarEdicao() { if (!projetoAtual) return; switchTab("silence"); silenceListSequences(); }