├── README.md └── copy-paste-url.lua /README.md: -------------------------------------------------------------------------------- 1 | # **copy-paste-url** 2 | 3 | Like its name suggests - copy and paste links into mpv with `ctrl + v` to start playback of a video. This needs an open mpv window like `mpv --idle --force-window` or a window already playing a video. Also the script utilizes *powershell* (for windows) or *xclip* (for linux), so that needs to be installed as well. 4 | 5 | ## Disclaimer 6 | 7 | this is a *fork* of [copy-paste-URL](https://github.com/zenyd/mpv-scripts.git) that a add support for **LINUX**. 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /copy-paste-url.lua: -------------------------------------------------------------------------------- 1 | function trim(s) 2 | return (s:gsub("^%s*(%S+)%s*", "%1")) 3 | end 4 | 5 | function check_os() 6 | local os_path = package.config:sub(1,1) 7 | 8 | if os_path == '\\' then 9 | return 'windows' 10 | elseif os_path == '/' then 11 | return 'linux' 12 | end 13 | 14 | end 15 | 16 | function openURL() 17 | 18 | local g = check_os() 19 | if g == 'linux' then 20 | subprocess = { 21 | name = "subprocess", 22 | args = { "xclip", "-o","-selection","clipboard"}, 23 | playback_only = false, 24 | capture_stdout = true, 25 | capture_stderr = true 26 | } 27 | elseif g == 'windows' then 28 | subprocess = { 29 | name = "subprocess", 30 | args = { "powershell", "-Command", "Get-Clipboard", "-Raw" }, 31 | playback_only = false, 32 | capture_stdout = true, 33 | capture_stderr = true 34 | } 35 | end 36 | 37 | mp.osd_message("Getting URL from clipboard...") 38 | 39 | r = mp.command_native(subprocess) 40 | 41 | --failed getting clipboard data for some reason 42 | if r.status < 0 then 43 | mp.osd_message("Failed getting clipboard data!") 44 | print("Error(string): "..r.error_string) 45 | print("Error(stderr): "..r.stderr) 46 | end 47 | 48 | url = r.stdout 49 | 50 | if not url then 51 | return 52 | end 53 | 54 | --trim whitespace from string 55 | url=trim(url) 56 | 57 | if not url then 58 | mp.osd_message("clipboard empty") 59 | return 60 | end 61 | 62 | --immediately resume playback after loading URL 63 | if mp.get_property_bool("core-idle") then 64 | if not mp.get_property_bool("idle-active") then 65 | mp.command("keypress space") 66 | end 67 | end 68 | 69 | --try opening url 70 | --will fail if url is not valid 71 | mp.osd_message("Try Opening URL:\n"..url) 72 | mp.commandv("loadfile", url, "replace") 73 | end 74 | 75 | mp.add_key_binding("ctrl+v", openURL) 76 | --------------------------------------------------------------------------------