Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mp = require 'mp'
- local default_visibility = 'auto'
- local visibility_by_extension = default_visibility
- local is_paused = false
- local music_mode = false
- local music_mode_timer = mp.add_periodic_timer(1, function ()
- local chapters = mp.get_property('chapters')
- local playlist_count = 0
- if chapters and tonumber(chapters) == 0 then
- playlist_count = mp.get_property('playlist-count')
- if playlist_count and tonumber(playlist_count) > 1 then
- mp.command('script-message osc-playlist 1 no-osd')
- return
- end
- end
- mp.command('script-message osc-chapterlist 1 no-osd')
- end)
- music_mode_timer:stop()
- -- extensions for which osc will be always hidden
- local no_osc_extensions = { 'png', 'jpg', 'jpeg', 'bmp' }
- -- helper function ran on file load that determines whether osc should be hidden or not
- function determine_visibility_by_file_extension()
- local path = mp.get_property('path')
- if not path then
- visibility_by_extension = default_visibility
- return
- end
- local last_dot_pos = (path:reverse()):find('%.')
- if not last_dot_pos then
- visibility_by_extension = default_visibility
- return
- end
- local extension = (path:sub(-last_dot_pos+1))
- if not extension then
- visibility_by_extension = default_visibility
- return
- end
- for index, value in ipairs(no_osc_extensions) do
- if value == extension then
- visibility_by_extension = 'never'
- -- disable music mode automatically
- if music_mode then
- toggle_music_mode()
- end
- return
- end
- end
- visibility_by_extension = default_visibility
- end
- -- function that updates osc visibility based on file extension, pause state and music mode state
- function my_osc_visibility()
- local visibility = visibility_by_extension
- if (is_paused or music_mode) and visibility_by_extension ~= 'never' then
- visibility = 'always'
- end
- mp.command('script-message osc-visibility ' .. visibility .. ' no-osd')
- end
- function determine_and_update()
- determine_visibility_by_file_extension()
- my_osc_visibility()
- end
- -- update paused state and osc visibility on "paused" property change
- function on_pause(name, value)
- is_paused = value
- my_osc_visibility()
- end
- -- music mode function
- -- keeps chapterlist and osc always visible
- function toggle_music_mode()
- if music_mode then
- music_mode_timer:stop()
- music_mode = false
- mp.osd_message('Music mode: off')
- my_osc_visibility()
- -- don't apply music mode when in no-osc mode
- elseif visibility_by_extension ~= 'never' then
- -- call once before the timer proceeds
- -- mp.command('script-message osc-chapterlist 1 no-osd')
- mp.osd_message('Music mode: on')
- music_mode_timer:resume()
- music_mode = true
- my_osc_visibility()
- else
- mp.osd_message('Music mode unavailable for this file type', 5)
- end
- end
- mp.register_script_message('my_osc_visibility', my_osc_visibility)
- mp.register_script_message('toggle_music_mode', toggle_music_mode)
- mp.add_hook('on_preloaded', 50, determine_and_update)
- mp.observe_property('pause', 'bool', on_pause)
- -- always show osc when opening a new file
- -- useful for network streams - user can see what is happening in the background
- mp.add_hook('on_load', 50, function()
- mp.command('script-message osc-visibility always no-osd')
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement