-- 14/10/2025 by jokel local url = arg[1] if not url then print("⚠️ Bitte gib eine .m3u8-Master-URL an.") return nil end local baseurl = url:match("^(.-)/[^/]*$") local name = url:match("([^/]+)$") local file = "/tmp/" .. name -- Playlist holen local playlist = {} local handle = io.popen("wget -q -O - '" .. url .. "'") for line in handle:lines() do table.insert(playlist, line) end handle:close() -- Beste Videoauflösung finden local maxsize = 0 local bestres = "" local bestvideo = "" for i = 1, #playlist do local line = playlist[i] if line:find("RESOLUTION=") then local res = line:match("RESOLUTION=(%d+x%d+)") local width, height = res:match("(%d+)x(%d+)") local size = tonumber(width) * tonumber(height) local nextline = playlist[i + 1] if size > maxsize then maxsize = size bestres = res bestvideo = nextline end end end -- Audio extrahieren (Deutsch) local audio = "" for _, line in ipairs(playlist) do if line:find('EXT%-X%-MEDIA:TYPE=AUDIO') and line:find('LANGUAGE="de"') then audio = line:match('URI="([^"]+)"') break end end -- Master-Playlist erzeugen local output = io.open(file , "w") output:write("#EXTM3U\n") output:write("#EXT-X-VERSION:3\n\n") if audio > "" then output:write('#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",NAME="Deutsch",LANGUAGE="de",DEFAULT=YES,AUTOSELECT=YES,URI="' .. baseurl .. "/" .. audio .. '"\n\n') else output:write('#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",NAME="Deutsch",LANGUAGE="de",DEFAULT=YES,AUTOSELECT=YES,URI="' .. bestvideo .. '"\n\n') end output:write('#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=' .. bestres .. ',CODECS="avc1.4D4020,mp4a.40.2",AUDIO="audio"\n') output:write(baseurl .. "/" .. bestvideo .. "\n") output:close() print("✅ Master-Playlist gespeichert unter " ..file) entry = {} json = require "json" entry['url'] = file return json:encode(entry)