-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathmodernz.lua
More file actions
4205 lines (3693 loc) · 179 KB
/
modernz.lua
File metadata and controls
4205 lines (3693 loc) · 179 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- ModernZ v0.3.2rc (https://github.com/Samillion/ModernZ)
--
-- This script is a derivative of the original mpv-osc-modern by maoiscat
-- and subsequent forks:
-- * cyl0/ModernX
-- * dexeonify/ModernX
--
-- It is based on the official osc.lua from mpv, licensed under the
-- GNU Lesser General Public License v2.1 (LGPLv2.1).
-- Full license: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
local assdraw = require "mp.assdraw"
local msg = require "mp.msg"
local opt = require "mp.options"
local utils = require "mp.utils"
mp.set_property("osc", "no")
-- Parameters
-- default user option values
-- do not touch, change them in modernz.conf
local user_opts = {
-- Language and display
language = "default", -- set language (for available options, see: https://github.com/Samillion/ModernZ/blob/main/docs/TRANSLATIONS.md)
layout = "modern", -- set layout: "modern" or "modern-compact"
icon_theme = "fluent", -- set icon theme. accepts "fluent" or "material"
icon_style = "mixed", -- "mixed", "filled", "outline"
font = "mpv-osd-symbols", -- font for the OSC (default: mpv-osd-symbols or the one set in mpv.conf)
idlescreen = true, -- show mpv logo when idle
window_top_bar = "auto", -- show OSC window top bar: "auto", "yes", or "no" (borderless/fullscreen)
showwindowed = true, -- show OSC when windowed
showfullscreen = true, -- show OSC when fullscreen
showonselect = false, -- show OSC when a select menu is open
showonpause = true, -- show OSC when paused
keeponpause = "no", -- keep OSC visible while paused: "no", "bottombar", "both"
greenandgrumpy = false, -- disable Santa hat in December
-- OSC behaviour and scaling
hidetimeout = 1500, -- time (in ms) before OSC hides if no mouse movement
keep_with_cursor = true, -- keep OSC visible while cursor hovers over bottom or top bar
fadeduration = 200, -- fade-out duration (in ms), set to 0 for no fade
fadein = true, -- whether to enable fade-in effect
minmousemove = 0, -- minimum mouse movement (in pixels) required to show OSC
deadzonesize = 0.75, -- size of the deadzone (0.0 = whole screen, 1.0 = no deadzone)
deadzone_hide = "instant", -- hide behavior when cursor enters deadzone or leaves window: "instant" or "timeout"
osc_on_seek = true, -- show OSC when seeking
osc_on_start = "both", -- show OSC on start of every file ("no", "bottom", "top", "both")
mouse_seek_pause = true, -- pause video while seeking with mouse move (on button hold)
force_seek_tooltip = false, -- force show seekbar tooltip on mouse drag, even if not hovering seekbar
vidscale = "auto", -- scale osc with the video
scalewindowed = 1.0, -- osc scale factor when windowed
scalefullscreen = 1.0, -- osc scale factor when fullscreen
-- Elements display
show_title = true, -- show title in the OSC (above seekbar)
title = "${media-title}", -- title above seekbar: "${media-title}" or "${filename}"
title_font_size = 24, -- title font size (above seekbar)
chapter_title_font_size = 16, -- chapter title font size
cache_info = false, -- show cached time information
cache_info_speed = false, -- show cache speed per second
cache_info_font_size = 12, -- font size of the cache information
show_chapter_title = true, -- show chapter title (above seekbar)
chapter_above_title = false, -- show chapter above title
chapter_fmt = "%s", -- format for chapter display on seekbar hover (set to "no" to disable)
timecurrent = true, -- show current time instead of remaining time
timems = false, -- show timecodes with milliseconds
unicodeminus = false, -- use the Unicode minus sign in remaining time
time_format = "dynamic", -- "dynamic" or "fixed". dynamic shows MM:SS when possible, fixed always shows HH:MM:SS
time_font_size = 16, -- font size of the time display
tooltip_font_size = 14, -- tooltips font size
speed_font_size = 16, -- speed button font size
-- Title bar settings
show_window_title = false, -- show window title in borderless/fullscreen mode
window_title_font_size = 26, -- window title font size
window_controls = true, -- show window controls (close, minimize, maximize) in borderless/fullscreen
windowcontrols_independent = true, -- show window controls (top bar) and bottom bar independently on hover
-- Subtitle and OSD display settings
sub_margins = true, -- raise subtitles above the OSC when shown
osd_margins = false, -- adjust OSD to not overlap with OSC
dynamic_margins = true, -- update margins dynamically with OSC visibility
-- Buttons display and functionality
subtitles_button = true, -- show the subtitles menu button
audio_tracks_button = true, -- show the audio tracks menu button
jump_buttons = true, -- show the jump backward and forward buttons
jump_amount = 10, -- change the jump amount in seconds
jump_more_amount = 60, -- change the jump amount in seconds on right click
jump_icon_number = true, -- show different icon when jump_amount is set to 5, 10, or 30
jump_mode = "relative", -- seek mode for jump buttons: "relative" or "exact"
jump_softrepeat = true, -- enable continuous jumping when holding down seek buttons
chapter_skip_buttons = false, -- show the chapter skip backward and forward buttons
chapter_softrepeat = true, -- enable continuous skipping when holding down chapter skip buttons
track_nextprev_buttons = true, -- show next/previous playlist track buttons
volume_control = true, -- show mute button and volume slider
volume_control_type = "linear", -- volume scale type: "linear" or "logarithmic"
volumebar_unmute_on_click = false, -- unmute audio when adjusting volume slider with left click
playlist_button = true, -- show playlist button
hide_empty_playlist_button = false, -- hide playlist button when no playlist exists
gray_empty_playlist_button = false, -- gray out the playlist button when no playlist exists
fullscreen_button = true, -- show fullscreen toggle button
info_button = true, -- show info button
ontop_button = true, -- show window on top button
ontop_in_topbar = false, -- move ontop button to top bar when ontop is active
screenshot_button = true, -- show screenshot button
download_button = true, -- show download button on web videos (requires yt-dlp and ffmpeg)
download_path = "~~desktop/mpv", -- default download directory for videos (https://mpv.io/manual/master/#paths)
loop_button = true, -- show file loop button
shuffle_button = false, -- show shuffle button
speed_button = true, -- show speed control button
buttons_always_active = "none", -- force buttons to always be active. can add: playlist_prev, playlist_next
playpause_size = 28, -- icon size for the play/pause button
midbuttons_size = 24, -- icon size for the middle buttons
sidebuttons_size = 24, -- icon size for the side buttons
zoom_control = true, -- show zoom controls in image viewer mode
zoom_in_max = 4, -- maximum zoom in value
zoom_out_min = -1, -- minimum zoom out value
-- Colors and style
osc_color = "#000000", -- accent color of the OSC and title bar
window_title_color = "#FFFFFF", -- color of the title in borderless/fullscreen mode
window_controls_color = "#FFFFFF", -- color of the window controls (close, minimize, maximize) in borderless/fullscreen mode
windowcontrols_close_hover = "#F45C5B", -- color of close window control on hover
windowcontrols_max_hover = "#F8BC3A", -- color of maximize window controls on hover
windowcontrols_min_hover = "#43CB44", -- color of minimize window controls on hover
title_color = "#FFFFFF", -- color of the title (above seekbar)
cache_info_color = "#FFFFFF", -- color of the cache information
seekbar_cache_color = "#FFFFFF", -- color of the cache ranges on the seekbar
seekbarfg_color = "#FF8232", -- color of the seekbar progress
seekbarbg_color = "#999999", -- color of the remaining seekbar
seek_handle_color = "#C96508", -- color of the seekbar handle
seek_handle_border_color = "#FF8232", -- inner border color drawn inside the seekbar handle (set to "" to disable)
volumebar_match_seek_color = false, -- match volume bar color with seekbar color (ignores side_buttons_color)
time_color = "#FFFFFF", -- color of the timestamps (below seekbar)
chapter_title_color = "#FFFFFF", -- color of the chapter title (above seekbar)
side_buttons_color = "#FFFFFF", -- color of the side buttons (audio, subtitles, playlist, etc.)
middle_buttons_color = "#FFFFFF", -- color of the middle buttons (skip, jump, chapter, etc.)
playpause_color = "#FFFFFF", -- color of the play/pause button
held_element_color = "#999999", -- color of the element when held down (pressed)
hover_effect_color = "#FF8232", -- color of a hovered button when hover_effect includes "color"
thumbnail_box_color = "#111111", -- color of the background for thumbnail box
thumbnail_box_outline = "#404040", -- color of the border outline for thumbnail box
nibble_color = "#FF8232", -- color of chapter nibbles on the seekbar
nibble_current_color = "#FFFFFF", -- color of the current chapter nibble on the seekbar
osc_fade_strength = 100, -- strength of the OSC background fade (0 to disable)
fade_blur_strength = 100, -- blur strength for the OSC alpha fade. caution: high values can take a lot of CPU time to render
fade_transparency_strength = 0, -- use with "fade_blur_strength=0" to create a transparency box
window_fade_strength = 100, -- strength of the window title bar fade (0 to disable)
window_fade_blur_strength = 100, -- blur strength for the window title bar. caution: high values can take a lot of CPU time to render
window_fade_transparency_strength = 0, -- use with "window_fade_blur_strength=0" to create a transparency box
thumbnail_box_padding = 4.5, -- thumbnail box padding around the image
thumbnail_box_radius = 4, -- round corner radius for thumbnail box border (0 to disable)
-- Button interaction settings
hover_effect = "size,glow,color,box", -- active button hover effects: "glow", "size", "color", "box"; can use multiple separated by commas
button_hover_size = 115, -- relative size of a hovered button if "size" effect is active
button_held_size = 100, -- relative size of a button when held/pressed. below 100 shrinks button when held down
button_held_box_alpha = 18, -- alpha of the hover background box when a button is held down
button_glow_amount = 5, -- glow intensity when "glow" hover effect is active
slider_hover_size = 100, -- relative size of a hovered slider handle
tooltip_hints = true, -- enable tooltips for most buttons. seek and volume tooltips are always enabled
-- Progress bar settings
seek_handle_size = 0.8, -- size ratio of the seek handle (range: 0 ~ 1)
seek_handle_border_size = 0.42, -- border thickness as a fraction of the handle radius
seek_handle_border_hover_size = 0.31, -- border thickness when handle is hovered (set equal to seek_handle_border_size to disable)
seekbar_height = "medium", -- seekbar height preset: "small", "medium", "large", "xlarge"
seekrange = true, -- show seek range overlay
seekrangealpha = 150, -- transparency of the seek range
livemarkers = true, -- update chapter markers on the seekbar when duration changes
seekbarkeyframes = false, -- use keyframes when dragging the seekbar
slider_rounded_corners = true, -- rounded corners seekbar slider
nibbles_style = "gap", -- chapter nibble style: "gap", "triangle", "bar", or "single-bar"
nibbles_top = true, -- top chapter nibbles above seekbar
nibbles_bottom = true, -- bottom chapter nibbles below seekbar
automatickeyframemode = true, -- automatically set keyframes for the seekbar based on video length
automatickeyframelimit = 600, -- videos longer than this (in seconds) will have keyframes on the seekbar
persistent_progress = false, -- always show a small progress line at the bottom of the screen
persistent_progress_height = 17, -- height of the persistent progress bar
persistent_buffer = false, -- show cached buffer status in the persistent progress line
-- Miscellaneous settings
visibility = "auto", -- only used at init to set visibility_mode(...)
visibility_modes = "never_auto_always",-- visibility modes to cycle through
tick_delay = 1 / 60, -- minimum interval between OSC redraws (in seconds)
tick_delay_follow_display_fps = false, -- use display FPS as the minimum redraw interval
-- Elements Position
-- Useful when adjusting font size or type
title_offset = 20, -- title vertical offset relative to seekbar
title_with_chapter_offset = 5, -- title vertical offset if a chapter title is below it
chapter_title_offset = 18, -- chapter title vertical offset relative to seekbar
chapter_above_title_offset = 3, -- chapter offset when shown above title
time_codes_offset = 0, -- time codes vertical offset relative to seekbar
tooltip_height_offset = 5, -- tooltip height position offset
portrait_window_trigger = 950, -- portrait window width trigger to move some elements
hide_volume_bar_trigger = 1150, -- hide volume bar trigger window width
osc_height = 60, -- osc height
-- Mouse commands
-- customize the button function based on mouse action
-- title above seekbar mouse actions
title_mbtn_left_command = "script-binding stats/display-page-5",
title_mbtn_mid_command = "show-text ${path}",
title_mbtn_right_command = "script-binding select/select-watch-history",
-- chapter title mouse actions
chapter_title_mbtn_left_command = "script-binding select/select-chapter",
chapter_title_mbtn_right_command = "show-text ${chapter-list} 3000",
-- playlist button mouse actions
playlist_mbtn_left_command = "script-binding select/select-playlist",
playlist_mbtn_right_command = "script-binding select/menu",
-- volume mouse actions
vol_ctrl_mbtn_left_command = "no-osd cycle mute",
vol_ctrl_mbtn_right_command = "script-binding select/select-audio-device",
vol_ctrl_wheel_down_command = "osd-msg add volume -5",
vol_ctrl_wheel_up_command = "osd-msg add volume 5",
volumebar_wheel_down_command = "osd-msg add volume -5",
volumebar_wheel_up_command = "osd-msg add volume 5",
-- audio button mouse actions
audio_track_mbtn_left_command = "script-binding select/select-aid",
audio_track_mbtn_mid_command = "cycle audio down",
audio_track_mbtn_right_command = "cycle audio",
audio_track_wheel_down_command = "cycle audio",
audio_track_wheel_up_command = "cycle audio down",
-- subtitle button mouse actions
sub_track_mbtn_left_command = "script-binding select/select-sid",
sub_track_mbtn_mid_command = "cycle sub down",
sub_track_mbtn_right_command = "cycle sub",
sub_track_wheel_down_command = "cycle sub",
sub_track_wheel_up_command = "cycle sub down",
-- play/pause button mouse actions
play_pause_mbtn_mid_command = "cycle-values loop-playlist inf no",
play_pause_mbtn_right_command = "cycle-values loop-file inf no",
-- chapter skip buttons mouse actions
chapter_prev_mbtn_left_command = "add chapter -1",
chapter_prev_mbtn_mid_command = "show-text ${chapter-list} 3000",
chapter_prev_mbtn_right_command = "script-binding select/select-chapter",
chapter_next_mbtn_left_command = "add chapter 1",
chapter_next_mbtn_mid_command = "show-text ${chapter-list} 3000",
chapter_next_mbtn_right_command = "script-binding select/select-chapter",
-- playlist skip buttons mouse actions
playlist_prev_mbtn_left_command = "playlist-prev",
playlist_prev_mbtn_mid_command = "show-text ${playlist} 3000",
playlist_prev_mbtn_right_command = "script-binding select/select-playlist",
playlist_next_mbtn_left_command = "playlist-next",
playlist_next_mbtn_mid_command = "show-text ${playlist} 3000",
playlist_next_mbtn_right_command = "script-binding select/select-playlist",
-- fullscreen button mouse actions
fullscreen_mbtn_left_command = "cycle fullscreen",
fullscreen_mbtn_right_command = "cycle window-maximized",
-- info button mouse actions
info_mbtn_left_command = "script-binding stats/display-page-1-toggle",
-- ontop (pin) button mouse actions
ontop_mbtn_left_command = "osd-msg cycle ontop",
-- screenshot button mouse actions
screenshot_mbtn_left_command = "osd-msg screenshot video",
-- loop file button mouse actions
file_loop_mbtn_left_command = "osd-msg cycle-values loop-file inf no",
file_loop_mbtn_right_command = "osd-msg cycle-values loop-playlist inf no",
-- speed button mouse actions
speed_mbtn_left_command = "osd-msg add speed 1",
speed_mbtn_right_command = "osd-msg set speed 1",
speed_wheel_down_command = "osd-msg add speed -0.25",
speed_wheel_up_command = "osd-msg add speed 0.25",
}
local osc_param = { -- calculated by osc_init()
playresy = 0, -- canvas size Y
playresx = 0, -- canvas size X
display_aspect = 1,
unscaled_y = 0,
areas = {},
video_margins = {
l = 0, r = 0, t = 0, b = 0, -- left/right/top/bottom
},
}
local icon_font = "modernz-icons"
local icon_themes = {
fluent = { prefix = "fluent_" },
material = { prefix = "material_" },
}
local function build_icons(theme_name, style)
local theme = icon_themes[theme_name] or icon_themes["fluent"]
local p = theme.prefix
local filled_suffix = (style ~= "outline") and "_filled" or ""
local outline_suffix = (style == "filled") and "_filled" or ""
local function f(name) return p .. name .. filled_suffix end
local function o(name) return p .. name .. outline_suffix end
return {
iconfont = icon_font,
window = {
maximize = "window_maximize",
unmaximize = "window_unmaximize",
minimize = "window_minimize",
close = "window_close",
},
play = f("play_arrow"),
pause = f("pause"),
replay = f("replay"),
previous = f("skip_previous"),
next = f("skip_next"),
rewind = f("fast_rewind"),
forward = f("fast_forward"),
jump = {
[5] = { f("replay_5"), f("forward_5") },
[10] = { f("replay_10"), f("forward_10") },
[30] = { f("replay_30"), f("forward_30") },
default = { f("skip_back"), f("skip_forward") },
},
audio = o("surround_sound"),
subtitle = o("subtitles"),
playlist = o("playlist_play"),
menu = o("more_vert"),
volume_mute = o("no_sound"),
volume_quiet = o("volume_mute"),
volume_low = o("volume_down"),
volume_high = o("volume_up"),
download = o("download"),
downloading = o("downloading"),
speed = o("speed"),
shuffle_on = o("shuffle_on"),
shuffle_off = o("shuffle"),
loop_on = o("repeat_on"),
loop_off = o("repeat"),
screenshot = o("photo_camera"),
ontop_on = o("pip"),
ontop_off = o("pip_exit"),
info = o("info"),
fullscreen = o("fullscreen"),
fullscreen_exit = o("fullscreen_exit"),
zoom_in = o("zoom_in"),
zoom_out = o("zoom_out"),
}
end
local function set_icon_theme()
icons = build_icons(user_opts.icon_theme, user_opts.icon_style)
end
--- localization
local language = {
["default"] = {
idle = "Drop files or URLs here to play",
na = "Not available",
unknown = "Unknown",
video = "Video",
audio = "Audio",
subtitle = "Subtitle",
no_subs = "No subtitles",
no_audio = "No audio tracks",
volume = "Volume",
muted = "Muted",
playlist = "Playlist",
no_playlist = "Playlist empty",
chapter = "Chapter",
fullscreen = "Fullscreen",
fullscreen_exit = "Exit fullscreen",
ontop = "Pin window",
ontop_disable = "Unpin window",
file_loop_enable = "Loop file on",
file_loop_disable = "Loop file off",
playlist_loop_enable = "Loop playlist on",
playlist_loop_disable = "Loop playlist off",
shuffle = "Shuffle playlist on",
unshuffle = "Shuffle playlist off",
speed_control = "Playback speed",
screenshot = "Screenshot",
stats_info = "Statistics",
cache = "Cache",
buffering = "Buffering",
zoom_in = "Zoom in",
zoom_out = "Zoom out",
download = "Download",
download_in_progress = "Download in progress",
downloading = "Downloading",
downloaded = "Already downloaded",
menu = "Menu",
},
}
local bidi = {
fsi = "\226\129\168", -- U+2068 first strong isolate
pdi = "\226\129\169", -- U+2069 pop directional isolate
}
-- locale JSON file handler
local function get_locale_from_json(path)
local expand_path = mp.command_native({'expand-path', path})
local file_info = utils.file_info(expand_path)
if not file_info or not file_info.is_file then
return nil
end
local json_file = io.open(expand_path, 'r')
if not json_file then
return nil
end
local json = json_file:read('*all')
json_file:close()
local json_table, parse_error = utils.parse_json(json)
if not json_table then
mp.msg.error("JSON parse error:" .. parse_error)
end
return json_table
end
-- load external locales only when default language is not used
local locale_file_loaded = false
local function load_locale_file()
if user_opts.language == "default" or locale_file_loaded then return end
locale_file_loaded = true
local external = get_locale_from_json("~~/script-opts/modernz-locale.json")
if external then
for lang, strings in pairs(external) do
if lang == "default" then
-- "default" is reserved
mp.msg.warn("Locale JSON: 'default' is a reserved language key and cannot be overridden. Skipping.")
elseif type(strings) == "table" then
language[lang] = strings
-- fill in any missing keys with the built-in defaults
for key, value in pairs(language["default"]) do
if strings[key] == nil then
strings[key] = value
end
end
else
mp.msg.warn("Locale data for language '" .. lang .. "' is not in the correct format.")
end
end
end
end
local locale
local function set_osc_locale()
locale = language[user_opts.language] or language["default"]
end
local function contains(list, item)
local t
if type(list) == "table" then
t = list
else
t = {}
for str in string.gmatch(list, '([^,]+)') do
t[#t + 1] = str:match("^%s*(.-)%s*$") -- trim spaces
end
end
for _, v in ipairs(t) do
if v == item then return true end
end
return false
end
local thumbfast = {
width = 0,
height = 0,
disabled = true,
available = false
}
local platform = mp.get_property("platform")
local tick_delay = 1 / 60
local window_control_box_width = 150
local is_december = os.date("*t").month == 12
local UNICODE_MINUS = string.char(0xe2, 0x88, 0x92) -- UTF-8 for U+2212 MINUS SIGN
local function osc_color_convert(color)
return color:sub(6,7) .. color:sub(4,5) .. color:sub(2,3)
end
local osc_styles
local seekbar_height_style
local hover_effects = { size = false, color = false, glow = false, box = false }
local function set_osc_styles()
local playpause_size = user_opts.playpause_size
local midbuttons_size = user_opts.midbuttons_size
local sidebuttons_size = user_opts.sidebuttons_size
hover_effects.size = contains(user_opts.hover_effect, "size")
hover_effects.color = contains(user_opts.hover_effect, "color")
hover_effects.glow = contains(user_opts.hover_effect, "glow")
hover_effects.box = contains(user_opts.hover_effect, "box")
local seekbar_presets = {
small = { radius = 1, height = 2 },
medium = { radius = 2, height = 4 },
large = { radius = 3, height = 6 },
xlarge = { radius = 4, height = 8 }
}
seekbar_height_style = seekbar_presets[user_opts.seekbar_height] or seekbar_presets.medium
osc_styles = {
osc_fade_bg = "{\\blur" .. user_opts.fade_blur_strength .. "\\bord" .. user_opts.osc_fade_strength .. "\\1c&H0&\\3c&H" .. osc_color_convert(user_opts.osc_color) .. "&}",
window_fade_bg = "{\\blur" .. user_opts.window_fade_blur_strength .. "\\bord" .. user_opts.window_fade_strength .. "\\1c&H0&\\3c&H" .. osc_color_convert(user_opts.osc_color) .. "&}",
window_control = "{\\1c&H" .. osc_color_convert(user_opts.window_controls_color) .. "&\\fs25\\fn" .. icons.iconfont .. "}",
window_title = "{\\bord1\\1c&H" .. osc_color_convert(user_opts.window_title_color) .. "&\\3c&H0&\\fs".. user_opts.window_title_font_size .."\\q2\\fn" .. user_opts.font .. "}",
title = "{\\bord1\\1c&H" .. osc_color_convert(user_opts.title_color) .. "&\\3c&H0&\\fs".. user_opts.title_font_size .."\\q2\\fn" .. user_opts.font .. "}",
chapter_title = "{\\bord1\\1c&H" .. osc_color_convert(user_opts.chapter_title_color) .. "&\\3c&H0&\\fs" .. user_opts.chapter_title_font_size .. "\\fn" .. user_opts.font .. "}",
seekbar_bg = "{\\1c&H" .. osc_color_convert(user_opts.seekbarbg_color) .. "&}",
seekbar_fg = "{\\blur1\\bord1\\1c&H" .. osc_color_convert(user_opts.seekbarfg_color) .. "&}",
thumbnail = "{\\bord1\\1c&H" .. osc_color_convert(user_opts.thumbnail_box_color) .. "&\\3c&H" .. osc_color_convert(user_opts.thumbnail_box_outline) .. "&}",
time = "{\\bord1\\1c&H" .. osc_color_convert(user_opts.time_color) .. "&\\3c&H0&\\fs" .. user_opts.time_font_size .. "\\fn" .. user_opts.font .. "}",
cache = "{\\bord1\\1c&H" .. osc_color_convert(user_opts.cache_info_color) .. "&\\3c&H0&\\fs" .. user_opts.cache_info_font_size .. "\\fn" .. user_opts.font .. "}",
tooltip = "{\\bord1\\1c&HFFFFFF&\\3c&H0&\\fs" .. user_opts.tooltip_font_size .. "\\fn" .. user_opts.font .. "}",
tooltip_box = "{\\1c&H" .. osc_color_convert(user_opts.osc_color) .. "&}",
speed = "{\\bord1\\1c&H" .. osc_color_convert(user_opts.side_buttons_color) .. "&\\3c&H0&\\fs" .. user_opts.speed_font_size .. "\\fn" .. user_opts.font .. "}",
volumebar_bg = "{\\1c&H999999&}",
volumebar_fg = "{\\blur1\\bord1\\1c&H" .. osc_color_convert(user_opts.side_buttons_color) .. "&}",
control_1 = "{\\1c&H" .. osc_color_convert(user_opts.playpause_color) .. "&\\fs" .. playpause_size .. "\\fn" .. icons.iconfont .. "}",
control_2 = "{\\1c&H" .. osc_color_convert(user_opts.middle_buttons_color) .. "&\\fs" .. midbuttons_size .. "\\fn" .. icons.iconfont .. "}",
control_3 = "{\\1c&H" .. osc_color_convert(user_opts.side_buttons_color) .. "&\\fs" .. sidebuttons_size .. "\\fn" .. icons.iconfont .. "}",
element_down = "{\\1c&H" .. osc_color_convert(user_opts.held_element_color) .. "&" .. string.format("\\fscx%s\\fscy%s", user_opts.button_held_size, user_opts.button_held_size) .. "}",
element_hover = "{" .. (hover_effects.color and "\\1c&H" .. osc_color_convert(user_opts.hover_effect_color) .. "&" or "") .. (hover_effects.size and string.format("\\fscx%s\\fscy%s", user_opts.button_hover_size, user_opts.button_hover_size) or "") .. "}",
hover_bg = "{\\1c&H" .. osc_color_convert(user_opts.hover_effect_color) .. "&}",
}
end
-- internal states, do not touch
local state = {
showtime = nil, -- time of last invocation (last mouse move)
touchtime = nil, -- time of last invocation (last touch event)
touchpoints = {}, -- current touch points
osc_visible = false, -- osc visibility
anistart = nil, -- time when the animation started
anitype = nil, -- current type of animation
animation = nil, -- current animation alpha
wc_visible = false, -- window controls visibility
wc_showtime = nil,
wc_anitype = nil,
wc_anistart = nil,
wc_animation = nil,
mouse_down_counter = 0, -- used for softrepeat
active_element = nil, -- nil = none, 0 = background, 1+ = see elements[]
active_event_source = nil, -- the "button" that issued the current event
tc_left_rem = not user_opts.timecurrent,-- if the left timecode should display current or remaining time
tc_ms = user_opts.timems, -- Should the timecodes display their time with milliseconds
screen_sizeX = nil, screen_sizeY = nil, -- last screen-resolution, to detect resolution changes to issue reINITs
initREQ = false, -- is a re-init request pending?
marginsREQ = false, -- is a margins update pending?
last_mouseX = nil, last_mouseY = nil, -- last mouse position, to detect significant mouse movement
last_touchX = -1, last_touchY = -1, -- last touch position
mouse_in_window = false,
fullscreen = false,
tick_timer = nil,
tick_last_time = 0, -- when the last tick() was run
hide_timer = nil,
demuxer_cache_state = nil,
idle_active = false,
audio_track_count = 0,
sub_track_count = 0,
playlist_count = 0,
playlist_pos = 0,
enabled = true,
input_enabled = true,
showhide_enabled = false,
windowcontrols_buttons = false,
windowcontrols_title = false,
windowcontrols_ontop = false,
dmx_cache = 0,
border = true,
window_maximized = false,
osd = mp.create_osd_overlay("ass-events"),
logo_osd = mp.create_osd_overlay("ass-events"),
new_file_flag = false, -- flag to detect new file starts
keeponpause_active = false, -- keeponpause bottombar active state
chapter_list = {}, -- sorted by time
chapter = -1, -- current chapter index
visibility_modes = {}, -- visibility_modes to cycle through
mute = false,
pause = false,
eof_reached = false,
volume = 0,
ontop = false,
speed = 1,
file_loop = false,
shuffled = false,
sliderpos = 0,
playtime_hour_force_init = false, -- used to force request_init() once
playing_and_seeking = false,
persistent_seekbar_element = nil,
seekbar_element = nil,
persistent_progress_toggle = user_opts.persistent_progress,
user_subpos = mp.get_property_number("sub-pos") or 100,
osc_adjusted_subpos = nil,
downloaded_once = false,
downloading = false,
file_size_bytes = 0,
file_size_normalized = "Approximating size...",
is_URL = false,
is_image = false,
url_path = "", -- used for yt-dlp downloading
}
local logo_lines = {
-- White border
"{\\c&HE5E5E5&\\p6}m 895 10 b 401 10 0 410 0 905 0 1399 401 1800 895 1800 1390 1800 1790 1399 1790 905 1790 410 1390 10 895 10 {\\p0}",
-- Purple fill
"{\\c&H682167&\\p6}m 925 42 b 463 42 87 418 87 880 87 1343 463 1718 925 1718 1388 1718 1763 1343 1763 880 1763 418 1388 42 925 42{\\p0}",
-- Darker fill
"{\\c&H430142&\\p6}m 1605 828 b 1605 1175 1324 1456 977 1456 631 1456 349 1175 349 828 349 482 631 200 977 200 1324 200 1605 482 1605 828{\\p0}",
-- White fill
"{\\c&HDDDBDD&\\p6}m 1296 910 b 1296 1131 1117 1310 897 1310 676 1310 497 1131 497 910 497 689 676 511 897 511 1117 511 1296 689 1296 910{\\p0}",
-- Triangle
"{\\c&H691F69&\\p6}m 762 1113 l 762 708 b 881 776 1000 843 1119 911 1000 978 881 1046 762 1113{\\p0}",
}
local santa_hat_lines = {
-- Pompoms
"{\\c&HC0C0C0&\\p6}m 500 -323 b 491 -322 481 -318 475 -311 465 -312 456 -319 446 -318 434 -314 427 -304 417 -297 410 -290 404 -282 395 -278 390 -274 387 -267 381 -265 377 -261 379 -254 384 -253 397 -244 409 -232 425 -228 437 -228 446 -218 457 -217 462 -216 466 -213 468 -209 471 -205 477 -203 482 -206 491 -211 499 -217 508 -222 532 -235 556 -249 576 -267 584 -272 584 -284 578 -290 569 -305 550 -312 533 -309 523 -310 515 -316 507 -321 505 -323 503 -323 500 -323{\\p0}",
"{\\c&HE0E0E0&\\p6}m 315 -260 b 286 -258 259 -240 246 -215 235 -210 222 -215 211 -211 204 -188 177 -176 172 -151 170 -139 163 -128 154 -121 143 -103 141 -81 143 -60 139 -46 125 -34 129 -17 132 -1 134 16 142 30 145 56 161 80 181 96 196 114 210 133 231 144 266 153 303 138 328 115 373 79 401 28 423 -24 446 -73 465 -123 483 -174 487 -199 467 -225 442 -227 421 -232 402 -242 384 -254 364 -259 342 -250 322 -260 320 -260 317 -261 315 -260{\\p0}",
-- Main cap
"{\\c&H0000F0&\\p6}m 1151 -523 b 1016 -516 891 -458 769 -406 693 -369 624 -319 561 -262 526 -252 465 -235 479 -187 502 -147 551 -135 588 -111 1115 165 1379 232 1909 761 1926 800 1952 834 1987 858 2020 883 2053 912 2065 952 2088 1000 2146 962 2139 919 2162 836 2156 747 2143 662 2131 615 2116 567 2122 517 2120 410 2090 306 2089 199 2092 147 2071 99 2034 64 1987 5 1928 -41 1869 -86 1777 -157 1712 -256 1629 -337 1578 -389 1521 -436 1461 -476 1407 -509 1343 -507 1284 -515 1240 -519 1195 -521 1151 -523{\\p0}",
-- Cap shadow
"{\\c&H0000AA&\\p6}m 1657 248 b 1658 254 1659 261 1660 267 1669 276 1680 284 1689 293 1695 302 1700 311 1707 320 1716 325 1726 330 1735 335 1744 347 1752 360 1761 371 1753 352 1754 331 1753 311 1751 237 1751 163 1751 90 1752 64 1752 37 1767 14 1778 -3 1785 -24 1786 -45 1786 -60 1786 -77 1774 -87 1760 -96 1750 -78 1751 -65 1748 -37 1750 -8 1750 20 1734 78 1715 134 1699 192 1694 211 1689 231 1676 246 1671 251 1661 255 1657 248 m 1909 541 b 1914 542 1922 549 1917 539 1919 520 1921 502 1919 483 1918 458 1917 433 1915 407 1930 373 1942 338 1947 301 1952 270 1954 238 1951 207 1946 214 1947 229 1945 239 1939 278 1936 318 1924 356 1923 362 1913 382 1912 364 1906 301 1904 237 1891 175 1887 150 1892 126 1892 101 1892 68 1893 35 1888 2 1884 -9 1871 -20 1859 -14 1851 -6 1854 9 1854 20 1855 58 1864 95 1873 132 1883 179 1894 225 1899 273 1908 362 1910 451 1909 541{\\p0}",
-- Brim and tip pompom
"{\\c&HF8F8F8&\\p6}m 626 -191 b 565 -155 486 -196 428 -151 387 -115 327 -101 304 -47 273 2 267 59 249 113 219 157 217 213 215 265 217 309 260 302 285 283 373 264 465 264 555 257 608 252 655 292 709 287 759 294 816 276 863 298 903 340 972 324 1012 367 1061 394 1125 382 1167 424 1213 462 1268 482 1322 506 1385 546 1427 610 1479 662 1510 690 1534 725 1566 752 1611 796 1664 830 1703 880 1740 918 1747 986 1805 1005 1863 991 1897 932 1916 880 1914 823 1945 777 1961 725 1979 673 1957 622 1938 575 1912 534 1862 515 1836 473 1790 417 1755 351 1697 305 1658 266 1633 216 1593 176 1574 138 1539 116 1497 110 1448 101 1402 77 1371 37 1346 -16 1295 15 1254 6 1211 -27 1170 -62 1121 -86 1072 -104 1027 -128 976 -133 914 -130 851 -137 794 -162 740 -181 679 -168 626 -191 m 2051 917 b 1971 932 1929 1017 1919 1091 1912 1149 1923 1214 1970 1254 2000 1279 2027 1314 2066 1325 2139 1338 2212 1295 2254 1238 2281 1203 2287 1158 2282 1116 2292 1061 2273 1006 2229 970 2206 941 2167 938 2138 918{\\p0}",
}
--
-- Helper functions
--
local function kill_animation(anitype_key, anistart_key, animation_key)
state[anitype_key] = nil
state[anistart_key] = nil
state[animation_key] = nil
end
local function set_osd(osd, res_x, res_y, text, z)
if osd.res_x == res_x and osd.res_y == res_y and osd.data == text then
return
end
osd.res_x = res_x
osd.res_y = res_y
osd.data = text
osd.z = z
osd:update()
end
local function set_time_styles(timecurrent_changed, timems_changed)
if timecurrent_changed then
state.tc_left_rem = not user_opts.timecurrent
end
if timems_changed then
state.tc_ms = user_opts.timems
end
end
local function observe_cached(property, callback)
local key = property:gsub("-", "_")
mp.observe_property(property, "native", function (_, value)
state[key] = value
callback()
end)
end
-- scale factor for translating between real and virtual ASS coordinates
local function get_virt_scale_factor()
local w, h = mp.get_osd_size()
if w <= 0 or h <= 0 then
return 0, 0
end
return osc_param.playresx / w, osc_param.playresy / h
end
local function recently_touched()
if state.touchtime == nil then
return false
end
return state.touchtime + 1 >= mp.get_time()
end
-- return mouse position in virtual ASS coordinates (playresx/y)
local function get_virt_mouse_pos()
if recently_touched() then
local sx, sy = get_virt_scale_factor()
return state.last_touchX * sx, state.last_touchY * sy
elseif state.mouse_in_window then
local sx, sy = get_virt_scale_factor()
local x, y = mp.get_mouse_pos()
return x * sx, y * sy
else
return -1, -1
end
end
local function set_virt_mouse_area(x0, y0, x1, y1, name)
local sx, sy = get_virt_scale_factor()
mp.set_mouse_area(x0 / sx, y0 / sy, x1 / sx, y1 / sy, name)
end
local function scale_value(x0, x1, y0, y1, val)
local m = (y1 - y0) / (x1 - x0)
local b = y0 - (m * x0)
return (m * val) + b
end
-- returns the position of an object on a one-dimensional axis,
-- from 0..1 (object to the "left") to 1..0 (object to the "right"), taking margin into account.
local function get_align(align, frame, obj, margin)
return (frame / 2) + (((frame / 2) - margin - (obj / 2)) * align)
end
local text_measure_osd = mp.create_osd_overlay and mp.create_osd_overlay("ass-events") or nil
if text_measure_osd then
text_measure_osd.hidden = true
text_measure_osd.compute_bounds = true
end
local text_width_cache = {}
local function estimate_text_width(text, style)
if text == nil then return 0 end
text = tostring(text)
if #text == 0 then return 0 end
-- replace digits with '0' for consistency
local measure_text = text:gsub("%d", "0")
local cache_key = measure_text .. (style or "")
local width = 0
if text_width_cache[cache_key] then
return text_width_cache[cache_key]
end
if text_measure_osd and text_measure_osd.update then
text_measure_osd.res_x = osc_param.playresx
text_measure_osd.res_y = osc_param.playresy
text_measure_osd.data = (style or "") .. "{\\an7\\pos(0,0)}" .. measure_text
local bounds = text_measure_osd:update()
if bounds and bounds.x1 and bounds.x0 then
-- subtract side-bearing padding that libass adds even at bord0
local fs = tonumber((style or ""):match("\\fs(%d+%.?%d*)")) or 16
local bearing_correction = fs * 0.08 * 2
width = math.max(0, (bounds.x1 - bounds.x0) - bearing_correction)
end
end
text_width_cache[cache_key] = width
return width
end
-- width of the time codes element
local function get_time_codes_width()
local dur = mp.get_property_number("duration", 0)
local rt_sec = state.tc_left_rem and mp.get_property_number("playtime-remaining", 0) or mp.get_property_number("playback-time", 0)
local function time_fmt(s)
local has_h = (s >= 3600) or user_opts.time_format == "fixed"
local base = has_h and (s >= 36000 and "88" or "8") .. ":88:88" or (s >= 600 and "88" or "8") .. ":88"
return base .. (state.tc_ms and ".888" or "")
end
local prefix = state.tc_left_rem and (user_opts.unicodeminus and UNICODE_MINUS or "-") or ""
local w = estimate_text_width(prefix .. time_fmt(rt_sec) .. " / " .. time_fmt(dur), osc_styles.time)
return w ~= 0 and w or 120 + (state.tc_ms and 40 or 0)
end
-- returns hitbox spanning coordinates (top left, bottom right corner)
-- according to alignment
local function get_hitbox_coords(x, y, an, w, h)
local alignments = {
[1] = function () return x, y-h, x+w, y end,
[2] = function () return x-(w/2), y-h, x+(w/2), y end,
[3] = function () return x-w, y-h, x, y end,
[4] = function () return x, y-(h/2), x+w, y+(h/2) end,
[5] = function () return x-(w/2), y-(h/2), x+(w/2), y+(h/2) end,
[6] = function () return x-w, y-(h/2), x, y+(h/2) end,
[7] = function () return x, y, x+w, y+h end,
[8] = function () return x-(w/2), y, x+(w/2), y+h end,
[9] = function () return x-w, y, x, y+h end,
}
return alignments[an]()
end
local function get_element_hitbox(element)
return element.hitbox.x1, element.hitbox.y1, element.hitbox.x2, element.hitbox.y2
end
local function mouse_hit_coords(bX1, bY1, bX2, bY2)
local mX, mY = get_virt_mouse_pos()
return (mX >= bX1 and mX <= bX2 and mY >= bY1 and mY <= bY2)
end
local function mouse_hit(element)
return mouse_hit_coords(get_element_hitbox(element))
end
local function mouse_in_area(names)
if type(names) == "string" then names = {names} end
for _, name in ipairs(names) do
for _, cords in ipairs(osc_param.areas[name] or {}) do
if mouse_hit_coords(cords.x1, cords.y1, cords.x2, cords.y2) then
return true
end
end
end
return false
end
local function limit_range(min, max, val)
return math.max(min, math.min(max, val))
end
-- translate value into element coordinates
local function get_slider_ele_pos_for(element, val)
local ele_pos = scale_value(
element.slider.min.value, element.slider.max.value,
element.slider.min.ele_pos, element.slider.max.ele_pos,
val)
return limit_range(element.slider.min.ele_pos, element.slider.max.ele_pos, ele_pos)
end
-- translates global (mouse) coordinates to value
local function get_slider_value_at(element, glob_pos)
if element then
local val = scale_value(
element.slider.min.glob_pos, element.slider.max.glob_pos,
element.slider.min.value, element.slider.max.value,
glob_pos)
return limit_range(element.slider.min.value, element.slider.max.value, val)
end
-- fall back incase of loading errors
return 0
end
-- get value at current mouse position
local function get_slider_value(element)
return get_slider_value_at(element, get_virt_mouse_pos())
end
-- multiplies two alpha values, formular can probably be improved
local function mult_alpha(alphaA, alphaB)
return 255 - (((1-(alphaA/255)) * (1-(alphaB/255))) * 255)
end
local function add_area(name, x1, y1, x2, y2)
-- create area if needed
if osc_param.areas[name] == nil then
osc_param.areas[name] = {}
end
table.insert(osc_param.areas[name], {x1=x1, y1=y1, x2=x2, y2=y2})
end
local function ass_append_alpha(ass, alpha, modifier, inverse, anim_override)
local ar = {}
for ai, av in ipairs(alpha) do
av = mult_alpha(av, modifier)
local animpos = anim_override or state.animation
if animpos then
if inverse then
animpos = 255 - animpos
end
av = mult_alpha(av, animpos)
end
ar[ai] = av
end
ass:append(string.format("{\\1a&H%X&\\2a&H%X&\\3a&H%X&\\4a&H%X&}",
ar[1], ar[2], ar[3], ar[4]))
end
-- draw tooltip background box and label
local function draw_tooltip(ass, tx, ty, width, style, label, alpha)
local fs = user_opts.tooltip_font_size
local ph, pv = 5, 3
local box_h = fs + 2 * pv
local min_w = box_h + 2 * ph
local box_w = math.max(width + 2 * ph, min_w)
-- draw tooltip box
ass:new_event()
ass:append("{\\rDefault\\alpha&H4D&}")
ass:pos(tx - box_w / 2, ty - fs - pv)
ass:an(7)
ass:append(osc_styles.tooltip_box)
ass:draw_start()
ass:round_rect_cw(0, 0, box_w, box_h, box_h / 2)
ass:draw_stop()
-- add tooltip
ass:new_event()
ass:append("{\\rDefault}")
ass:pos(tx, ty)
ass:an(2)
ass:append(style)
if alpha then ass_append_alpha(ass, alpha, 0) end
ass:append(label)
end
local function ass_draw_cir_cw(ass, x, y, r)
ass:round_rect_cw(x-r, y-r, x+r, y+r, r)
end
local function ass_draw_rr_h_cw(ass, x0, y0, x1, y1, r1, hexagon, r2)
if hexagon then
ass:hexagon_cw(x0, y0, x1, y1, r1, r2)
else
ass:round_rect_cw(x0, y0, x1, y1, r1, r2)
end
end
local function get_hidetimeout()
if user_opts.visibility == "always" then
return -1 -- disable autohide
end
return user_opts.hidetimeout
end
local function get_touchtimeout()
if state.touchtime == nil then
return 0
end
return state.touchtime + (get_hidetimeout() / 1000) - mp.get_time()
end
local function cache_enabled()
return state.demuxer_cache_state and #state.demuxer_cache_state["seekable-ranges"] > 0
end
local function set_margin_offset(prop, offset)
if offset > 0 then
if not state[prop] then
state[prop] = mp.get_property_number(prop)
end
mp.set_property_number(prop, state[prop] + offset)
elseif state[prop] then
mp.set_property_number(prop, state[prop])
state[prop] = nil
end
end
local function reset_margins()
-- restore subtitle position if it was changed
if state.osc_adjusted_subpos ~= nil then
mp.set_property_number("sub-pos", state.user_subpos)
state.osc_adjusted_subpos = nil
end
set_margin_offset("osd-margin-y", 0)
end
local function update_margins()
local use_margins = get_hidetimeout() < 0 or user_opts.dynamic_margins
local top_vis = state.wc_visible
local bottom_vis = state.osc_visible