Skip to content

Commit c810c77

Browse files
Initial commit
0 parents  commit c810c77

File tree

11 files changed

+428
-0
lines changed

11 files changed

+428
-0
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!--- Provide a general summary of the issue in the Title above. -->
2+
3+
## Script
4+
<!-- Select the script(s) this issue applies to by marking the box with an x. -->
5+
* [ ] `clipshot.lua`
6+
* [ ] `misc.lua`
7+
* [ ] `open-dialog/kdialog.lua`
8+
* [ ] `open-dialog/zenity.lua`
9+
10+
## Description
11+
<!--- Provide a detailed description of the issue. -->
12+
13+
## Possible Fix
14+
<!--- Not obligatory, but suggest a fix or reason for the bug. -->
15+
<!--- If requesting a feature, suggest a way to implement it. -->
16+
17+
## Steps to Reproduce
18+
<!--- Provide a link to a live example, or an unambiguous set of steps to reproduce this bug. -->
19+
20+
## Environment Info
21+
<!-- Include as many relevant details about your environment as possible. -->
22+
* OS and version:
23+
* mpv version:
24+
* mpv Lua version:

.github/workflows/projects.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Add issue to the appropriate project
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
7+
jobs:
8+
add-to-project:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Add to Clipshot project
12+
if: |
13+
contains(github.event.issue.body, '[x] `clipshot.lua`)'
14+
uses: alex-page/[email protected]
15+
with:
16+
project: Clipshot
17+
column: To do
18+
repo-token: ${{secrets.GITHUB_TOKEN}}
19+
20+
- name: Add to Misc project
21+
if: |
22+
contains(github.event.issue.body, '[x] `misc.lua`)'
23+
uses: alex-page/[email protected]
24+
with:
25+
project: Misc
26+
column: To do
27+
repo-token: ${{secrets.GITHUB_TOKEN}}
28+
29+
- name: Add to Open Dialog (KDialog) project
30+
if: |
31+
contains(github.event.issue.body, '[x] `open-dialog/kdialog.lua`)'
32+
uses: alex-page/[email protected]
33+
with:
34+
project: Open Dialog (KDialog)
35+
column: To do
36+
repo-token: ${{secrets.GITHUB_TOKEN}}
37+
38+
- name: Add to Open Dialog (Zenity) project
39+
if: |
40+
contains(github.event.issue.body, '[x] `open-dialog/zenity.lua`)'
41+
uses: alex-page/[email protected]
42+
with:
43+
project: Open Dialog (Zenity)
44+
column: To do
45+
repo-token: ${{secrets.GITHUB_TOKEN}}

.luacheckrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- luacheck: ignore 131
2+
3+
std = 'lua52'
4+
5+
globals = {'mp'}
6+
7+
allow_defined_top = true
8+
9+
max_line_length = 80
10+
11+
max_comment_line_length = false
12+
13+
files['open-dialog/zenity.lua'] = {
14+
globals = {'table.merge'}
15+
}
16+
17+
-- vim: ft=lua

LICENSE.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Copyright (c) 2019 ObserverOfTime
2+
3+
Permission to use, copy, modify, and/or distribute this software
4+
for any purpose with or without fee is hereby granted.
5+
6+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
7+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
8+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
9+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
10+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
11+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
12+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## mpv scripts
2+
3+
[![LICENSE](https://img.shields.io/badge/license-BSD0-red.svg)](LICENSE.txt "BSD Zero Clause License")
4+
5+
My collection of cross-platform scripts for [mpv][mpv].
6+
7+
Feel free to edit and adapt them however you like
8+
and if you think your changes should be merged,
9+
don't hesitate to submit a pull request.
10+
11+
### [open-dialog](open-dialog)
12+
13+
Scripts that launch a dialog for opening files or URLs.
14+
<br>Follow the link for details.
15+
16+
### [clipshot.lua](clipshot.lua)
17+
18+
#### `clipshot-subs`
19+
20+
Screenshot the video (with subs) and copy it to the clipboard.
21+
<br>Default key binding: `c`
22+
23+
#### `clipshot-video`
24+
25+
Screenshot the video (w/o subs) and copy it to the clipboard.
26+
<br>Default key binding: `C`
27+
28+
#### `clipshot-window`
29+
30+
Screenshot the full window and copy it to the clipboard.
31+
<br>Default key binding: `Alt+c`
32+
33+
### [misc.lua](misc.lua)
34+
35+
Miscellaneous simple functions.
36+
37+
#### `show-time`
38+
39+
Show the current time (`HH:MM`) on the OSD.
40+
<br>Default key binding: `Ctrl+t`
41+
42+
[mpv]: https://github.com/mpv-player/mpv

_config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
theme: jekyll-theme-leap-day
2+
title: mpv scripts
3+
description: My personal mpv scripts
4+
show_downloads: false

clipshot.lua

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
utils = require 'mp.utils'
2+
3+
NAME = 'mpv-screenshot.png'
4+
5+
if package.config:sub(1, 1) ~= '/' then -- Windows
6+
SHOT = os.getenv('TEMP')..'\\'..NAME
7+
CMD = {
8+
'powershell', '-NoProfile', '-Command', string.format([[& {
9+
Add-Type -Assembly System.Windows.Forms;
10+
Add-Type -Assembly System.Drawing;
11+
$shot = [Drawing.Image]::FromFile(%q);
12+
[Windows.Forms.Clipboard]::SetImage($shot);
13+
}]], SHOT)
14+
}
15+
else -- Unix
16+
SHOT = '/tmp/'..NAME
17+
-- os.getenv('OSTYPE') doesn't work
18+
local ostype = io.popen('printf "$OSTYPE"', 'r'):read()
19+
if ostype:sub(1, 6) == 'darwin' then -- MacOS
20+
CMD = {
21+
'osascript', '-e', string.format([[¬
22+
set the clipboard to ( ¬
23+
read (POSIX file %q) as «class PNG» ¬
24+
) ¬
25+
]], SHOT)
26+
}
27+
else -- Linux/BSD
28+
CMD = {'xclip', '-sel', 'c', '-t', 'image/png', '-i', SHOT}
29+
end
30+
end
31+
32+
function clipshot(arg)
33+
return function()
34+
mp.commandv('screenshot-to-file', SHOT, arg)
35+
utils.subprocess_detached({args = CMD})
36+
mp.osd_message('Copied screenshot to clipboard')
37+
-- TODO: switch to new API when it's in stable
38+
-- mp.command_native_async({'run', unpack(CMD)}, function(suc, res, err)
39+
-- mp.osd_message(suc and 'Copied screenshot to clipboard' or err)
40+
-- end)
41+
end
42+
end
43+
44+
mp.add_key_binding('c', 'clipshot-subs', clipshot('subtitles'))
45+
mp.add_key_binding('C', 'clipshot-video', clipshot('video'))
46+
mp.add_key_binding('Alt+c', 'clipshot-window', clipshot('window'))

misc.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
TIME_FORMAT = '%H:%M'
2+
3+
mp.add_key_binding('Ctrl+t', 'show-time', function()
4+
mp.osd_message(os.date(TIME_FORMAT), 2)
5+
end)

open-dialog/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
## Open Dialog
2+
3+
Rather than write a single cross-platform script, which would be
4+
too complicated, I opted for separate scripts for each platform.
5+
6+
All scripts provide the following functions:
7+
8+
#### `open-files`
9+
10+
Open one or more media files in mpv.
11+
<br>Default key binding: `Ctrl+f`
12+
13+
#### `open-url`
14+
15+
Open a URL in mpv.
16+
<br>Default key binding: `Ctrl+F`
17+
18+
#### `open-subs`
19+
20+
Open one or more subtitle files in mpv.
21+
<br>Default key binding: `Alt+f`
22+
23+
---
24+
25+
### Linux
26+
27+
If you're on KDE, you should download
28+
[kdialog.lua](kdialog.lua) which uses [KDialog][kdialog].
29+
30+
If not, you should download
31+
[zenity.lua](zenity.lua) which uses [Zenity][zenity].
32+
33+
[xdotool][xdotool] is required for both scripts.
34+
35+
### MacOS
36+
37+
You can install Zenity from [MacPorts][ports]
38+
or [Homebrew][brew] and download [zenity_nox.lua][zenity-nox].
39+
40+
**TODO**: Write an AppleScript version.
41+
42+
### Windows
43+
44+
You can install Zenity from [zenity-windows][windows]
45+
or [WinZenity][winzenity] and download [zenity_nox.lua][zenity-nox].
46+
47+
**TODO**: Write a PowerShell version.
48+
49+
[kdialog]: https://github.com/KDE/kdialog
50+
[zenity]: https://github.com/GNOME/zenity
51+
[xdotool]: https://github.com/jordansissel/xdotool
52+
[zenity-nox]: https://git.io/zenity_nox.lua
53+
[brew]: https://formulae.brew.sh/formula/zenity
54+
[ports]: https://ports.macports.org/port/zenity/summary
55+
[windows]: https://github.com/kvaps/zenity-windows
56+
[winzenity]: https://github.com/maravento/winzenity

open-dialog/kdialog.lua

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
utils = require 'mp.utils'
2+
3+
MULTIMEDIA = table.concat({
4+
'*.aac',
5+
'*.avi',
6+
'*.flac',
7+
'*.flv',
8+
'*.m3u',
9+
'*.m3u8',
10+
'*.m4v',
11+
'*.mkv',
12+
'*.mov',
13+
'*.mp3',
14+
'*.mp4',
15+
'*.mpeg',
16+
'*.mpg',
17+
'*.oga',
18+
'*.ogg',
19+
'*.ogv',
20+
'*.opus',
21+
'*.wav',
22+
'*.webm',
23+
'*.wmv',
24+
}, ' ')
25+
26+
SUBTITLES = table.concat({
27+
'*.ass',
28+
'*.srt',
29+
'*.ssa',
30+
'*.sub',
31+
'*.txt',
32+
}, ' ')
33+
34+
ICON = 'mpv'
35+
36+
function KDialog(opts)
37+
return function()
38+
local path = mp.get_property('path')
39+
path = path == nil and '' or utils.split_path(
40+
utils.join_path(mp.getcwd(), path)
41+
)
42+
local ontop = mp.get_property_native('ontop')
43+
local focus = utils.subprocess {
44+
args = {'xdotool', 'getwindowfocus'}
45+
}.stdout:gsub('\n$', '')
46+
mp.set_property_native('ontop', false)
47+
local kdialog = utils.subprocess {
48+
args = {
49+
'kdialog', opts.default or path,
50+
'--title', opts.title,
51+
'--attach', focus,
52+
'--icon', ICON,
53+
'--multiple', '--separate-output',
54+
opts.type or '--getopenfilename', opts.text,
55+
}, cancellable = false,
56+
}
57+
mp.set_property_native('ontop', ontop)
58+
if kdialog.status ~= 0 then return end
59+
for file in string.gmatch(kdialog.stdout, '[^\n]+') do
60+
mp.commandv(opts.args[1], file, opts.args[2])
61+
end
62+
end
63+
end
64+
65+
mp.add_key_binding('Ctrl+f', 'open-files', KDialog {
66+
title = 'Select Files',
67+
text = 'Multimedia Files ('..MULTIMEDIA..')',
68+
args = {'loadfile', 'append-play'},
69+
})
70+
mp.add_key_binding('Ctrl+F', 'open-url', KDialog {
71+
title = 'Open URL',
72+
text = 'Enter the URL to open:',
73+
default = '',
74+
type = '--inputbox',
75+
args = {'loadfile', 'replace'},
76+
})
77+
mp.add_key_binding('Alt+f', 'open-subs', KDialog {
78+
title = 'Select Subs',
79+
text = 'Subtitle Files ('..SUBTITLES..')',
80+
args = {'sub-add', 'select'},
81+
})

0 commit comments

Comments
 (0)