Commit: 31a515996d55cf2a7dcf85023a05dbe2b58d144f
Parent: a1c52cb60acae653774493c7b061683b6fc936f3
Author: Ren Tatsumoto
Date: Fri, 24 Sep 2021 04:26:00 +0000
Merge pull request #51 from nbelikov/master
Add a command to play until the end of the next sub
Diffstat:
2 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
@@ -235,6 +235,8 @@ Alt+l script-binding mpvacious-sub-seek-forward-pause
Ctrl+h script-binding mpvacious-sub-rewind
Ctrl+H script-binding mpvacious-sub-replay
+
+P script-binding mpvacious-sub-play-up-to-next
```
**Note:** A capital letter means that you need to press Shift in order to activate the corresponding binding.
@@ -266,6 +268,8 @@ Seeking:
* `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.
+* `Shift-p` - Play until the end of the next subtitle, and pause. Useful for beginners who need
+to look up words in each and every dialogue line.
### Menu options
diff --git a/subs2srs.lua b/subs2srs.lua
@@ -826,12 +826,16 @@ local pause_timer = (function()
}
end)()
+local function sub_stop_at_the_end(sub)
+ pause_timer.set_stop_time(sub['end'] - 0.050)
+ mp.observe_property("time-pos", "number", pause_timer.check_stop)
+end
+
local function sub_replay()
local sub = subs.get_current()
- pause_timer.set_stop_time(sub['end'] - 0.050 + mp.get_property_native("sub-delay"))
mp.commandv('seek', sub['start'], 'absolute')
mp.set_property("pause", "no")
- mp.observe_property("time-pos", "number", pause_timer.check_stop)
+ sub_stop_at_the_end(sub)
end
local function sub_seek(direction, pause)
@@ -848,6 +852,40 @@ local function sub_rewind()
pause_timer.stop()
end
+local sub_play_up_to_next = {
+ deadzone_end_time,
+}
+
+sub_play_up_to_next.check_sub = function()
+ local sub = subs.get_current()
+ if sub then
+ mp.unobserve_property(sub_play_up_to_next.check_sub)
+ sub_stop_at_the_end(sub)
+ end
+end
+
+sub_play_up_to_next.check_deadzone_timer = function(_, time)
+ if time > sub_play_up_to_next.deadzone_end_time then
+ mp.unobserve_property(sub_play_up_to_next.check_deadzone_timer)
+ local sub = subs.get_current()
+ if sub then
+ sub_stop_at_the_end(sub)
+ else
+ mp.observe_property("sub-text", "string", sub_play_up_to_next.check_sub)
+ end
+ end
+end
+
+sub_play_up_to_next.arm = function()
+ -- When this feature is used, the player is usually stopped few tens of milliseconds before the end time of a sub,
+ -- so "sub-text" change event will occur almost immediately after unpausing. Often this would make the player
+ -- to pause again in just few frames after keypress. To avoid this, a small delay ("deadzone") is applied before
+ -- subscribing to "sub-text" change event.
+ sub_play_up_to_next.deadzone_end_time = mp.get_property_number('time-pos') + 0.300
+ mp.observe_property("time-pos", "number", sub_play_up_to_next.check_deadzone_timer)
+ mp.set_property("pause", "no")
+end
+
------------------------------------------------------------
-- platform specific
@@ -1678,6 +1716,7 @@ local main = (function()
mp.add_key_binding("Ctrl+h", "mpvacious-sub-rewind", _ { sub_rewind })
mp.add_key_binding("Ctrl+H", "mpvacious-sub-replay", _ { sub_replay })
+ mp.add_key_binding("P", "mpvacious-sub-play-up-to-next", _ { sub_play_up_to_next.arm })
end
end)()