Advertisement
Guest User

Untitled

a guest
Sep 24th, 2015
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.44 KB | None | 0 0
  1. local assdraw = require "mp.assdraw"
  2. local options = require "mp.options"
  3.  
  4. local info_active = false
  5. local o = {
  6.     font_size = 10,
  7.     font_color = "00FFFF",
  8.     border_size = 1.0,
  9.     border_color = "000000",
  10. }
  11. options.read_options(o)
  12.  
  13. function get_formatting()
  14.     return string.format(
  15.         "{\\fs%d}{\\1c&H%s&}{\\bord%f}{\\3c&H%s&}",
  16.         o.font_size, o.font_color,
  17.         o.border_size, o.border_color
  18.     )
  19. end
  20.  
  21. function timestamp(duration)
  22.     local hours = duration / 3600
  23.     local minutes = duration % 3600 / 60
  24.     local seconds = duration % 60
  25.     local ts = string.format("%02d:%02d:%02.03f", hours, minutes, seconds)
  26.     return ts
  27. end
  28.  
  29. function get_info()
  30.     return string.format(
  31.         "%sName: %s\\NTime: %s",
  32.         get_formatting(),
  33.         mp.get_property("filename"),
  34.         timestamp(mp.get_property_native("time-pos"))
  35.     )
  36. end
  37.  
  38. function render_info()
  39.     ass = assdraw.ass_new()
  40.     ass:pos(0, 0)
  41.     ass:append(get_info())
  42.     mp.set_osd_ass(0, 0, ass.text)
  43. end
  44.  
  45. function clear_info()
  46.     mp.set_osd_ass(0, 0, "")
  47. end
  48.  
  49. function toggle_info()
  50.     if info_active then
  51.         mp.unregister_event(render_info)
  52.         clear_info()
  53.     else
  54.         -- TODO: Rewrite to timer + pause/unpause handlers.
  55.         mp.register_event("tick", render_info)
  56.         render_info()
  57.     end
  58.     info_active = not info_active
  59. end
  60.  
  61. mp.add_key_binding("i", mp.get_script_name(), toggle_info)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement