mpv2oboeru

mpv helpers to create flashcards from movies and TV shows
git clone anongit@rnpnr.xyz:mpv2oboeru.git
Log | Files | Refs | Feed | README | LICENSE

Commit: fc7e71af42e5feccd6b0b0d4b5fa587aab0e77cd
Parent: 969881237c88b1d6a5acd3bbcdd38739e1167995
Author: Ren Tatsumoto
Date:   Mon, 21 Dec 2020 22:41:37 +0300

new action: sub replay

Diffstat:
MREADME.md | 2++
Msubs2srs.lua | 41++++++++++++++++++++++++++++++++++++++++-
2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md @@ -275,6 +275,7 @@ Default bindings: Ctrl+c script-binding mpvacious-copy-sub-to-clipboard Ctrl+e script-binding mpvacious-export-note Ctrl+h script-binding mpvacious-sub-rewind +Ctrl+Shift+h script-binding mpvacious-sub-replay a script-binding mpvacious-menu-open H script-binding mpvacious-sub-seek-back L script-binding mpvacious-sub-seek-forward @@ -299,6 +300,7 @@ These bindings work everywhere, even if the menu (covered later) is closed. * `Shift+h` and `Shift+l` - Seek to the previous or the next subtitle. * `Alt+h` and `Alt+l` - Seek to the previous or the next subtitle, and pause. * `Ctrl+h` - Seek to the start of the currently visible subtitle. Use it if you missed something. +* `Ctrl+Shift+h` - Replay current subtitle line, and pause. * `Ctrl+e` - Export a card with the currently visible subtitle line on the front. Use this when your subs are perfectly timed and the target sentence doesn't span multiple subs. * `Ctrl+c` - Copy current subtitle string to the system clipboard. For automatic copying see diff --git a/subs2srs.lua b/subs2srs.lua @@ -544,23 +544,58 @@ local function update_last_note(overwrite) end ------------------------------------------------------------ --- seeking: sub seek, sub rewind +-- seeking: sub replay, sub seek, sub rewind local function _(params) local unpack = unpack and unpack or table.unpack return function() return pcall(unpack(params)) end end +local pause_timer = (function() + local stop_time = -1 + local check_stop + local set_stop_time = function(time) + stop_time = time + end + local stop = function() + mp.unobserve_property(check_stop) + stop_time = -1 + end + check_stop = function(_, time) + if time > stop_time then + stop() + mp.set_property("pause", "yes") + else + notify('Timer: ' .. human_readable_time(stop_time - time)) + end + end + return { + set_stop_time = set_stop_time, + check_stop = check_stop, + stop = stop, + } +end)() + +local function sub_replay() + local sub = subs.get_current() + pause_timer.set_stop_time(sub['end'] - 0.050) + mp.commandv('seek', sub['start'], 'absolute') + mp.set_property("pause", "no") + mp.observe_property("time-pos", "number", pause_timer.check_stop) +end + local function sub_seek(direction, pause) mp.commandv("sub_seek", direction == 'backward' and '-1' or '1') mp.commandv("seek", "0.015", "relative+exact") if pause then mp.set_property("pause", "yes") end + pause_timer.stop() end local function sub_rewind() mp.commandv('seek', subs.get_current()['start'] + 0.015, 'absolute') + pause_timer.stop() end ------------------------------------------------------------ @@ -1255,6 +1290,7 @@ menu.update = function() osd:submenu('Global bindings'):newline() osd:tab():item('ctrl+c: '):text('Copy current subtitle to clipboard'):newline() osd:tab():item('ctrl+h: '):text('Seek to the start of the line'):newline() + osd:tab():item('ctrl+shift+h: '):text('Replay current subtitle'):newline() osd:tab():item('shift+h/l: '):text('Seek to the previous/next subtitle'):newline() osd:tab():item('alt+h/l: '):text('Seek to the previous/next subtitle and pause'):newline() osd:italics("Press "):item('i'):italics(" to hide bindings."):newline() @@ -1398,9 +1434,12 @@ do -- Vim-like seeking between subtitle lines mp.add_key_binding("H", "mpvacious-sub-seek-back", _ { sub_seek, 'backward' }) mp.add_key_binding("L", "mpvacious-sub-seek-forward", _ { sub_seek, 'forward' }) + mp.add_key_binding("Alt+h", "mpvacious-sub-seek-back-pause", _ { sub_seek, 'backward', true }) mp.add_key_binding("Alt+l", "mpvacious-sub-seek-forward-pause", _ { sub_seek, 'forward', true }) + mp.add_key_binding("ctrl+h", "mpvacious-sub-rewind", _ { sub_rewind }) + mp.add_key_binding("ctrl+H", "mpvacious-sub-replay", _ { sub_replay }) -- Unset by default mp.add_key_binding(nil, "mpvacious-set-starting-line", subs.set_starting_line)