-
-
Save olejorgenb/a5194d9bc183dbe0bfb02aac18fe37f9 to your computer and use it in GitHub Desktop.
-- 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 | |
-- mp.register_script_message("copy-permalink", copyPermalink) | |
mp.add_key_binding("ctrl+SPACE", "copy-permalink", copyPermalink) |
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)
xclip alternative on Windows anyone?
xclip alternative on Windows anyone?
https://stackoverflow.com/a/11546439/1701567
first result in google
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
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.
@sergeevabc please take a look at my script , my addition from above is working!
@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.
@sergeevabc could you please try again now ?
@elig0n, still does not work.
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
@NothingSpecialOne, thank you! It works as expected.
-- for MacOS