.
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # mpv-copyStuff
2 |
3 | This script copies to clipboard the:
4 | - Filename (With Extension) or URL Link
5 | - Full Filename Path
6 | - Current Video Time (HH:MM:SS.MS)
7 | - Current Displayed Subtitle Text
8 | - Video Metadata
9 |
10 | ## Installation
11 |
12 | Put the script `copyStuff.lua` in your scripts folder, usually in:
13 | - Windows: `"C:\Users\Username\AppData\Roaming\mpv\scripts"`.
14 | - Linux and MacOS: `"~/.config/mpv/scripts/"`.
15 |
16 | To work, the script needs:
17 | - Windows: `Powershell`.
18 | - Linux/X11: `xclip`.
19 | - Linux/Wayland : `xclip` or `wl-clipboard`.
20 | - MacOS: `pbcopy` (not tested).
21 |
22 | ## Hotkeys
23 |
24 |
25 |
26 | | What is Copied | Hotkey |
27 | | ------------------------------------ | ---------- |
28 | | **Filename or URL Link** | **CTRL+f** |
29 | | **Full Filename Path** | **CTRL+p** |
30 | | **Current Video Time (HH:MM:SS.MS)** | **CTRL+t** |
31 | | **Current Displayed Subtitle Text** | **CTRL+s** |
32 | | **Video Duration** | **CTRL+d** |
33 | | **Video Metadata** | **CTRL+m** |
34 |
35 |
36 |
37 | # Screenshots
38 |
39 | 
40 | 
41 | 
42 | 
43 |
--------------------------------------------------------------------------------
/copyStuff.lua:
--------------------------------------------------------------------------------
1 | require 'mp'
2 | require 'mp.msg'
3 |
4 | -- Copy:
5 | -- Filename or URL (CTRL+f)
6 | -- Full Filename Path (CTRL+p)
7 | -- Current Video Time (CTRL+t)
8 | -- Current Video Duration (CTRL+d)
9 | -- Current Displayed Subtitle (CTRL+s)
10 | -- Video Metadata (CTRL+m)
11 |
12 | WINDOWS = 2
13 | UNIX = 3
14 |
15 | local function platform_type()
16 | local utils = require 'mp.utils'
17 | local workdir = utils.to_string(mp.get_property_native("working-directory"))
18 | if string.find(workdir, "\\") then
19 | return WINDOWS
20 | else
21 | return UNIX
22 | end
23 | end
24 |
25 | local function command_exists(cmd)
26 | local pipe = io.popen("type " .. cmd .. " > /dev/null 2> /dev/null; printf \"$?\"", "r")
27 | exists = pipe:read() == "0"
28 | pipe:close()
29 | return exists
30 | end
31 |
32 | local function get_clipboard_cmd()
33 | if command_exists("xclip") then
34 | return "xclip -silent -in -selection clipboard"
35 | elseif command_exists("wl-copy") then
36 | return "wl-copy"
37 | elseif command_exists("pbcopy") then
38 | return "pbcopy"
39 | else
40 | mp.msg.error("No supported clipboard command found")
41 | return false
42 | end
43 | end
44 |
45 | local function divmod(a, b)
46 | return a / b, a % b
47 | end
48 |
49 | local function set_clipboard(text)
50 | if platform == WINDOWS then
51 | mp.commandv("run", "powershell", "set-clipboard", table.concat({'"', text, '"'}))
52 | return true
53 | elseif (platform == UNIX and clipboard_cmd) then
54 | local pipe = io.popen(clipboard_cmd, "w")
55 | pipe:write(text)
56 | pipe:close()
57 | return true
58 | else
59 | mp.msg.error("Set_clipboard error")
60 | return false
61 | end
62 | end
63 |
64 | -- Copy Time
65 | local function copyTime()
66 | local time_pos = mp.get_property_number("time-pos")
67 | local minutes, remainder = divmod(time_pos, 60)
68 | local hours, minutes = divmod(minutes, 60)
69 | local seconds = math.floor(remainder)
70 | local milliseconds = math.floor((remainder - seconds) * 1000)
71 | local time = string.format("%02d:%02d:%02d.%03d", hours, minutes, seconds, milliseconds)
72 | if set_clipboard(time) then
73 | mp.osd_message(string.format("Time Copied to Clipboard: %s", time))
74 | else
75 | mp.osd_message("Failed to copy time to clipboard")
76 | end
77 | end
78 |
79 | -- Copy Filename with Extension
80 | local function copyFilename()
81 | local filename = string.format("%s", mp.get_property_osd("filename"))
82 | local extension = string.match(filename, "%.(%w+)$")
83 |
84 | local succ_message = "Filename Copied to Clipboard"
85 | local fail_message = "Failed to copy filename to clipboard"
86 |
87 | -- If filename doesn't have an extension then it is a URL.
88 | if not extension then
89 | filename = mp.get_property_osd("path")
90 |
91 | succ_message = "URL Copied to Clipboard"
92 | fail_message = "Failed to copy URL to clipboard"
93 | end
94 |
95 | if set_clipboard(filename) then
96 | mp.osd_message(string.format("%s: %s", succ_message, filename))
97 | else
98 | mp.osd_message(string.format("%s", fail_message))
99 | end
100 | end
101 |
102 | -- Copy Full Filename Path
103 | local function copyFullPath()
104 | if platform == WINDOWS then
105 | full_path = string.format("%s\\%s", mp.get_property_osd("working-directory"), mp.get_property_osd("path"))
106 | else
107 | full_path = string.format("%s/%s", mp.get_property_osd("working-directory"), mp.get_property_osd("path"))
108 | end
109 |
110 | if set_clipboard(full_path) then
111 | mp.osd_message(string.format("Full Filename Path Copied to Clipboard: %s", full_path))
112 | else
113 | mp.osd_message("Failed to copy full filename path to clipboard")
114 | end
115 | end
116 |
117 | -- Copy Current Displayed Subtitle
118 | local function copySubtitle()
119 | local subtitle = string.format("%s", mp.get_property_osd("sub-text"))
120 |
121 | if subtitle == "" then
122 | mp.osd_message("There are no displayed subtitles.")
123 | return
124 | end
125 |
126 | if set_clipboard(subtitle) then
127 | mp.osd_message(string.format("Displayed Subtitle Copied to Clipboard: %s", subtitle))
128 | else
129 | mp.osd_message("Failed to copy displayed subtitle to clipboard")
130 | end
131 | end
132 |
133 | -- Copy Current Video Duration
134 | local function copyDuration()
135 | local duration = string.format("%s", mp.get_property_osd("duration"))
136 |
137 | if set_clipboard(duration) then
138 | mp.osd_message(string.format("Video Duration Copied to Clipboard: %s", duration))
139 | else
140 | mp.osd_message("Failed to copy video duration to clipboard")
141 | end
142 | end
143 |
144 | -- Copy Current Video Metadata
145 | local function copyMetadata()
146 | local metadata = string.format("%s", mp.get_property_osd("metadata"))
147 |
148 | if set_clipboard(metadata) then
149 | mp.osd_message(string.format("Video Metadata Copied to Clipboard: %s", metadata))
150 | else
151 | mp.osd_message("Failed to copy metadata to clipboard")
152 | end
153 | end
154 |
155 | platform = platform_type()
156 | if platform == UNIX then
157 | clipboard_cmd = get_clipboard_cmd()
158 | end
159 |
160 | -- Key-Bindings
161 | mp.add_key_binding("Ctrl+t", "copyTime", copyTime)
162 | mp.add_key_binding("Ctrl+f", "copyFilename", copyFilename)
163 | mp.add_key_binding("Ctrl+p", "copyFullPath", copyFullPath)
164 | mp.add_key_binding("Ctrl+s", "copySubtitle", copySubtitle)
165 | mp.add_key_binding("Ctrl+d", "copyDuration", copyDuration)
166 | mp.add_key_binding("Ctrl+m", "copyMetadata", copyMetadata)
167 |
--------------------------------------------------------------------------------