Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
mpv user script: copy a command that will resume video at current position
@Justsoos

This comment has been minimized.

Copy link

@Justsoos Justsoos commented Jan 16, 2020

-- for MacOS

function copyPermalink()
  local pos = mp.get_property_number("time-pos")
  local uri = mp.get_property("path")
  local bookmark = string.format("mpv --start=%s %q", pos, uri)
  local pipe = io.popen("pbcopy", "w")
  pipe:write(bookmark)
  pipe:close()
  mp.osd_message("Link to position copied to clipboard")
end

mp.add_key_binding("ctrl+SPACE", "copy-permalink", copyPermalink)
@sigboe

This comment has been minimized.

Copy link

@sigboe sigboe commented Jan 23, 2020

Hei Ole, if you want to add a sharable link function to your script, I did it like below.
This adds a shift+space key binding that copies a youtube link with the time stamp in the link.

-- Author: Ole Jørgen Brønner (olejorgenb@yahoo.no)
-- Requirement: xclip
-- Installation: 
-- 'mkdir -p ~/.config/mpv/scripts && cp -i copy-permalink.lua ~/.config/mpv/scripts'

function copyPermalink()
  local pos = mp.get_property_number("time-pos")
  local uri = mp.get_property("path")
  -- %q might not be fully robust
  local bookmark = string.format("mpv --start=%s %q", pos, uri)
  local pipe = io.popen("xclip -silent -in -selection clipboard", "w")
  pipe:write(bookmark)
  pipe:close()
  mp.osd_message("Link to position copied to clipboard")
end

function sharePermalink()
  local pos = mp.get_property_number("time-pos")
  local uri = mp.get_property("path")
  -- %q might not be fully robust
  -- local bookmark = string.format("mpv --start=%s %q", pos, uri)
  local bookmark = string.format("%s&t=%i", uri, pos)
  local pipe = io.popen("xclip -silent -in -selection clipboard", "w")
  pipe:write(bookmark)
  pipe:close()
  mp.osd_message("Shareable link with position copied to clipboard")
end

-- mp.register_script_message("copy-permalink", copyPermalink)
mp.add_key_binding("ctrl+SPACE", "copy-permalink", copyPermalink)
mp.add_key_binding("shift+SPACE", "share-permalink", sharePermalink)
@phanirithvij

This comment has been minimized.

Copy link

@phanirithvij phanirithvij commented Mar 10, 2020

xclip alternative on Windows anyone?

@sigboe

This comment has been minimized.

Copy link

@sigboe sigboe commented Mar 10, 2020

@phanirithvij

xclip alternative on Windows anyone?

https://stackoverflow.com/a/11546439/1701567
first result in google

@elig0n

This comment has been minimized.

Copy link

@elig0n elig0n commented Mar 28, 2020

xclip alternative on Windows anyone?

Here's a Powershell alternative off copyTime.lua:

require 'mp'

local function set_clipboard(text)
    mp.commandv("run", "powershell", "set-clipboard", text);
end
@sergeevabc

This comment has been minimized.

Copy link

@sergeevabc sergeevabc commented Jun 13, 2020

Full working script is provided for Linux by @olejorgenb and for Mac OS by @Justsoos, whereas Windows version is still in DIY state. We need a hero here.

@elig0n

This comment has been minimized.

Copy link

@elig0n elig0n commented Jun 18, 2020

@sergeevabc please take a look at my script , my addition from above is working!

@sergeevabc

This comment has been minimized.

Copy link

@sergeevabc sergeevabc commented Jun 18, 2020

@elig0n, it does not work for me on Windows 7. Placed your copy-permalink.lua to mpv/scripts/, then opened a video from Youtube, pressed ctrl+space, got on-screen message “… copied to clipboard", but there clipboard is still empty, alas.

@elig0n

This comment has been minimized.

Copy link

@elig0n elig0n commented Jun 18, 2020

@sergeevabc could you please try again now ?

@sergeevabc

This comment has been minimized.

Copy link

@sergeevabc sergeevabc commented Jun 20, 2020

@elig0n, still does not work.

@NothingSpecialOne

This comment has been minimized.

Copy link

@NothingSpecialOne NothingSpecialOne commented Feb 6, 2021

We need a hero here.

Here i am, @sergeevabc
You have to add just a single line into input.conf file, to make the magic happen
Shift+c run "cmd.exe" "/d" "/c" "echo mpv --start=${time-pos} ${path}|clip"
That's it, no scripts have been used
And the cherry on the cake - youtube timestamp link
Ctrl+c run "cmd.exe" "/d" "/c" "echo ${path}^^^&t=${=time-pos}|clip"
but it sux, because of milliseconds at the timestamp (416.280000 for example), and link would not work properly until you delete them (416 is what we need, in this case) manually, also link ends with new line (\n) symbol
I have no idea - is this even possible to get seconds only, from current playback time, or needs a feature request, probably
Anyway, the trick is - NO scripts
Windows only solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment