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.

Revisions

  1. michaelmrose created this gist Sep 24, 2024.
    24 changes: 24 additions & 0 deletions rickroll.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    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)