diff --git a/resources/[tools]/nordi_dj/client/main.lua b/resources/[tools]/nordi_dj/client/main.lua index c2c60231a..f94ec0982 100644 --- a/resources/[tools]/nordi_dj/client/main.lua +++ b/resources/[tools]/nordi_dj/client/main.lua @@ -584,4 +584,78 @@ RegisterNUICallback('songProgress', function(data, cb) -- Du kannst hier Song-Progress verarbeiten -- z.B. für eine Progress-Bar im Menü cb('ok') -end) \ No newline at end of file +end) + +-- Füge diese Funktionen zu deiner client/main.lua hinzu: + +local function cleanYouTubeUrl(url) + -- Entferne Playlist-Parameter und andere Parameter + local patterns = { + "(https://www%.youtube%.com/watch%?v=[^&]+)", + "(https://youtu%.be/[^?]+)" + } + + for _, pattern in ipairs(patterns) do + local cleanUrl = string.match(url, pattern) + if cleanUrl then + return cleanUrl + end + end + + return url +end + +local function extractVideoId(url) + local patterns = { + "youtube%.com/watch%?v=([^&]+)", + "youtu%.be/([^?]+)", + "youtube%.com/embed/([^?]+)" + } + + for _, pattern in ipairs(patterns) do + local videoId = string.match(url, pattern) + if videoId then + return videoId + end + end + + return nil +end + +-- Aktualisiere die PlayMusic Funktion +function PlayMusic(title, url, volume) + if not title or not url then + lib.notify({ + title = 'DJ System', + description = 'Titel und URL sind erforderlich', + type = 'error' + }) + return + end + + -- Bereinige YouTube URL + local cleanedUrl = cleanYouTubeUrl(url) + local videoId = extractVideoId(cleanedUrl) + + if videoId then + lib.notify({ + title = 'DJ System', + description = 'YouTube Video wird geladen: ' .. title, + type = 'info' + }) + + print('[DJ System] YouTube Video ID: ' .. videoId) + print('[DJ System] Bereinigte URL: ' .. cleanedUrl) + end + + -- Sende an Server + TriggerServerEvent('dj:playMusic', title, cleanedUrl, volume or 50) + + -- Update lokale Variablen + isPlaying = true + currentSong = { + title = title, + url = cleanedUrl, + volume = volume or 50 + } +end