// Variáveis Globais let videoQueue = []; let currentIndex = -1; let isPlaying = false; let playLog = []; let vinhetaQueuePredefined = []; let saveHistory = []; let currentSaveIndex = -1; let player = null; // Referência para o elemento de vídeo // Funções para lidar com a playlist function extractVideoId(url) { // Regular expression para extrair o ID do YouTube const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/; const match = url.match(regExp); return (match && match[2].length === 11) ? match[2] : null; } function addVideo(source, type = 'youtube') { if (type === 'youtube') { const videoId = extractVideoId(source); if (videoId) { const tempIndex = videoQueue.length; videoQueue.push({ id: videoId, title: 'Carregando...', type: 'youtube' }); updatePlaylist(); $(`#playlist li:eq(${tempIndex})`).addClass('loading'); getVideoDetails(videoId) .then(details => { videoQueue[tempIndex].title = details.title; updatePlaylist(); }) .catch(error => { console.error('Erro ao obter detalhes do vídeo:', error); videoQueue[tempIndex].title = `YouTube Video ${videoId}`; updatePlaylist(); }); } } else if (type === 'local') { const file = source; const url = URL.createObjectURL(file); videoQueue.push({ id: url, title: file.name, type: 'local' }); updatePlaylist(); } } function updatePlaylist() { const $playlist = $('#playlist').empty(); videoQueue.forEach((video, index) => { const $item = $('
  • ') .addClass('list-group-item d-flex justify-content-between align-items-center draggable-item') .text(video.title) .data('index', index) .appendTo($playlist); if (index === currentIndex) { $item.addClass('active'); } if (video.title === 'Carregando...') { $item.addClass('loading'); } $('