Advertisement
Guest User

Untitled

a guest
Jun 15th, 2022
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.19 KB | None | 0 0
  1. -- Script will pause at the beginning of each new subtitle for the amount of time that
  2. -- the subtitle would normally appear on the screen, multiplied by FACTOR.
  3. -- So if a sub was going to appear for 4 seconds and you have a FACTOR of 0.5 then
  4. -- then there will be a 2 second pause when that subtitle appears.
  5. local FACTOR = 0.9
  6. -- Set to true if you only want the subs displayed during the automatic pause
  7. local HIDE_SUB_AFTER_PAUSE = true
  8. -- Set to true if you want to anime to stay paused when you press spacebar or whatever
  9. -- during one of the auto-pauses. Normal behavior is that pressing space would unpause
  10. -- rather than switch into a permanently paused state that you must manually unpause.
  11. local ENABLE_PERMA_PAUSE = true
  12.  
  13. local pause_disease = false
  14. local auto_paused = true
  15. local function unpause()
  16.   if auto_paused then
  17.     mp.set_property_native("pause", false)
  18.     auto_paused = false
  19.     if HIDE_SUB_AFTER_PAUSE then
  20.       mp.set_property_bool("sub-visibility", false)
  21.     end
  22.   end
  23. end
  24.  
  25. local function pause(_, subtxt)
  26.   if not pause_disease or mp.get_property_number('sub-end') == nil or mp.get_property_bool("pause") then
  27.     return
  28.   end
  29.  
  30.   mp.set_property_bool("sub-visibility", true)
  31.   if subtxt ~= "" then
  32.     mp.set_property_native("pause", true)
  33.     local pause_length = FACTOR * (mp.get_property_number('sub-end') - mp.get_property_number('sub-start'))
  34.     auto_paused = true
  35.     mp.add_timeout(pause_length, unpause)
  36.   end
  37. end
  38.  
  39.  
  40. local function toggle_pause_disease()
  41.   pause_disease = not pause_disease
  42.   mp.osd_message("Pause disease " .. (pause_disease and "activated" or "deactived"), 3)
  43. end
  44.  
  45. local function handle_pause_req(_, val)
  46.   -- user is trying to "resume" during an auto-pause, switch modes to a regular pause
  47.   if ENABLE_PERMA_PAUSE and val == false then
  48.     if HIDE_SUB_AFTER_PAUSE and auto_paused == false then
  49.       mp.set_property_bool("sub-visibility", false)
  50.     end
  51.     if auto_paused then
  52.       auto_paused = false
  53.       mp.set_property_native("pause", true)
  54.     end
  55.   end
  56. end
  57.  
  58. mp.add_key_binding("ctrl+p", toggle_pause_disease)
  59. mp.observe_property("sub-text", 'string', pause)
  60. mp.observe_property("pause", "bool", handle_pause_req)
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement