function openModalLink() { modalMode = 'link'; modalContent.innerHTML = `
`; modalSaveBtn.disabled = true; modalOverlay.classList.remove('hidden'); modalLinkInput = document.getElementById('musicUrl'); modalNameInput = document.getElementById('musicName'); const modalLinkError = document.getElementById('modalLinkError'); function extractYouTubeId(url) { const ytRegex = /(?:youtube\.com\/(?:watch\?v=|embed\/|v\/|shorts\/)|youtu\.be\/)([a-zA-Z0-9_-]{11})/; const match = url.match(ytRegex); return match ? match[1] : null; } function validateLink() { const url = modalLinkInput.value.trim(); modalLinkError.classList.add('hidden'); modalSaveBtn.disabled = true; if (!url) return; const lowerUrl = url.toLowerCase(); const youTubeId = extractYouTubeId(url); if (youTubeId) { modalSaveBtn.disabled = false; return; } if ( lowerUrl.endsWith('.mp3') || lowerUrl.endsWith('.mpeg') || lowerUrl.endsWith('.wav') || lowerUrl.endsWith('.ogg') || lowerUrl.endsWith('.mp4') ) { modalSaveBtn.disabled = false; } else { modalLinkError.textContent = 'Geçersiz link. Desteklenen: mp3, mp4 veya YouTube linki.'; modalLinkError.classList.remove('hidden'); modalSaveBtn.disabled = true; } } modalLinkInput.addEventListener('input', validateLink); modalNameInput.addEventListener('input', () => { // İsim boş olsa bile kabul et, zorunlu değil }); modalSaveBtn.onclick = () => { const url = modalLinkInput.value.trim(); if (!url) return; const youTubeId = extractYouTubeId(url); let name = modalNameInput.value.trim(); if (youTubeId) { playlist.push({ id: crypto.randomUUID(), name: name || `YouTube Video - ${youTubeId}`, url: null, type: null, isObjectURL: false, isYouTube: true, youTubeId: youTubeId, }); } else { const lowerUrl = url.toLowerCase(); let type = ''; if ( lowerUrl.endsWith('.mp3') || lowerUrl.endsWith('.mpeg') || lowerUrl.endsWith('.wav') || lowerUrl.endsWith('.ogg') ) { type = 'audio/mpeg'; } else if (lowerUrl.endsWith('.mp4')) { type = 'video/mp4'; } else { alert('Desteklenmeyen dosya türü.'); return; } playlist.push({ id: crypto.randomUUID(), name: name || url, url, type, isObjectURL: false, isYouTube: false, youTubeId: null, }); } saveState(); renderPlaylist(); closeModal(); }; }