From 54a74c44416668085bd33df2d6aa32887cbaa5fb Mon Sep 17 00:00:00 2001 From: zenyd <30322274+zenyd@users.noreply.github.com> Date: Tue, 9 Mar 2021 01:57:39 +0100 Subject: [PATCH] add script copy-paste-URL --- README.md | 12 ++++++++--- copy-paste-URL.lua | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 copy-paste-URL.lua diff --git a/README.md b/README.md index 537535a..862a1f2 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,12 @@ First invoke the script using `alt + u`, input a movie name, or use the one prov ## delete-file As the name suggests this is a small script for deleting files played through mpv. You can mark a file to be deleted and can unmark it if desired. Once quitting mpv, the script starts the deletion process. This is platform-agnostic so should work everywhere. -`ctrl + DEL`: mark/unmark file to be deleted -`alt + DEL`: show the list of files marked for deletion -`ctrl + shift + DEL`: clear the list of marks +Key Bind|Effect +--------|------ +`ctrl + DEL`|mark/unmark file to be deleted +`alt + DEL`|show the list of files marked for deletion +`ctrl + shift + DEL`|clear the list of marked files + + +## copy-paste-URL +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, so that needs to be installed as well. diff --git a/copy-paste-URL.lua b/copy-paste-URL.lua new file mode 100644 index 0000000..d0ac3f1 --- /dev/null +++ b/copy-paste-URL.lua @@ -0,0 +1,53 @@ +function trim(s) + return (s:gsub("^%s*(%S+)%s*", "%1")) +end + +function openURL() + + subprocess = { + name = "subprocess", + args = { "powershell", "-Command", "Get-Clipboard", "-Raw" }, + playback_only = false, + capture_stdout = true, + capture_stderr = true + } + + mp.osd_message("Getting URL from clipboard...") + + r = mp.command_native(subprocess) + + --failed getting clipboard data for some reason + if r.status < 0 then + mp.osd_message("Failed getting clipboard data!") + print("Error(string): "..r.error_string) + print("Error(stderr): "..r.stderr) + end + + url = r.stdout + + if not url then + return + end + + --trim whitespace from string + url=trim(url) + + if not url then + mp.osd_message("clipboard empty") + return + end + + --immediately resume playback after loading URL + if mp.get_property_bool("core-idle") then + if not mp.get_property_bool("idle-active") then + mp.command("keypress space") + end + end + + --try opening url + --will fail if url is not valid + mp.osd_message("Try Opening URL:\n"..url) + mp.commandv("loadfile", url, "replace") +end + +mp.add_key_binding("ctrl+v", openURL)