Update main.lua
This commit is contained in:
		
							parent
							
								
									227068560a
								
							
						
					
					
						commit
						9a29e35e64
					
				
					 1 changed files with 75 additions and 1 deletions
				
			
		|  | @ -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) | ||||
| 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 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Nordi98
						Nordi98