local intro_video_url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ" local has_prepended = false -- A flag to prevent repeated prepending mp.register_event("file-loaded", function() -- Check if we've already prepended the URL if not has_prepended then -- Insert the YouTube video at the beginning of the playlist mp.commandv("loadfile", intro_video_url, "append-play") -- Wait for the video to be properly appended mp.add_timeout(1, function() local playlist_count = mp.get_property_number("playlist-count", 1) -- Move the newly added video to the front mp.command("playlist-move " .. (playlist_count - 1) .. " 0") -- Switch to the first playlist entry (the prepended YouTube URL) mp.set_property("playlist-pos", 0) -- Mark that the URL has been prepended to avoid repeating has_prepended = true end) end end)