Skip to content

Instantly share code, notes, and snippets.

@michaelmrose
Created September 24, 2024 20:08
Show Gist options
  • Save michaelmrose/19ab09d9756a573490c906a92d04b803 to your computer and use it in GitHub Desktop.
Save michaelmrose/19ab09d9756a573490c906a92d04b803 to your computer and use it in GitHub Desktop.
script when placed in ~/.config/mpv/scripts rick rolls user every time they play a video
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment