Advertisement
Guest User

Untitled

a guest
Feb 14th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.47 KB | None | 0 0
  1. local mp = require 'mp'
  2.  
  3. -- extensions for which osc will be always hidden (and music mode will be disabled)
  4. local no_osc_extensions = { 'png', 'jpg', 'jpeg', 'bmp' }
  5. local default_visibility = 'auto'
  6.  
  7.  
  8. local visibility_by_extension = default_visibility
  9. local is_paused = false
  10. local music_mode = false
  11. local music_mode_timer = mp.add_periodic_timer(1, function ()
  12.         local chapters = mp.get_property_number('chapters', 0)
  13.         local playlist_count = 0
  14.         if chapters == 0 then
  15.             mp.command('script-message osc-playlist 1.00 no-osd')
  16.         else
  17.             mp.command('script-message osc-chapterlist 1.00 no-osd')
  18.         end
  19.     end)
  20. music_mode_timer:stop()
  21.  
  22. -- helper function ran on file load that determines whether osc should be hidden or not
  23. function determine_visibility_by_file_extension()
  24.     local path = mp.get_property('path')
  25.     if not path then
  26.         visibility_by_extension = default_visibility
  27.         return
  28.     end
  29.    
  30.     local last_dot_pos = (path:reverse()):find('%.')
  31.     if not last_dot_pos then
  32.         visibility_by_extension = default_visibility
  33.         return
  34.     end
  35.    
  36.     local extension = (path:sub(-last_dot_pos+1))
  37.     if not extension then
  38.         visibility_by_extension = default_visibility
  39.         return
  40.     end
  41.  
  42.     for index, value in ipairs(no_osc_extensions) do
  43.         if value == extension then
  44.             visibility_by_extension = 'never'
  45.             -- disable music mode automatically
  46.             if music_mode then
  47.                 toggle_music_mode()
  48.             end
  49.             return
  50.         end
  51.     end
  52.  
  53.     visibility_by_extension = default_visibility
  54. end
  55.  
  56. -- function that updates osc visibility based on file extension, pause state and music mode state
  57. function my_osc_visibility()
  58.     local visibility = visibility_by_extension
  59.     if (is_paused or music_mode) and visibility_by_extension ~= 'never' then
  60.         visibility = 'always'
  61.     end
  62.  
  63.     mp.command('script-message osc-visibility ' .. visibility .. ' no-osd')
  64. end
  65.  
  66. function determine_and_update()
  67.     determine_visibility_by_file_extension()
  68.     my_osc_visibility()
  69. end
  70.  
  71. -- update paused state and osc visibility on "paused" property change
  72. function on_pause(name, value)
  73.     is_paused = value
  74.     my_osc_visibility()    
  75. end
  76.  
  77. -- music mode function
  78. -- keeps chapterlist and osc always visible
  79. function toggle_music_mode()
  80.     if music_mode then
  81.         music_mode_timer:stop()
  82.         music_mode = false
  83.         mp.osd_message('Music mode: off')
  84.         my_osc_visibility()
  85.  
  86.     -- don't apply music mode when in no-osc mode
  87.     -- elseif visibility_by_extension ~= 'never' then
  88.     else
  89.         -- call once before the timer proceeds
  90.         -- mp.command('script-message osc-chapterlist 1 no-osd')
  91.         mp.osd_message('Music mode: on')
  92.         music_mode_timer:resume()
  93.         music_mode = true
  94.         my_osc_visibility()    
  95.     -- else
  96.     --     mp.osd_message('Music mode unavailable for this file type', 5)
  97.     end
  98. end
  99.  
  100. mp.register_script_message('my_osc_visibility', my_osc_visibility)
  101. mp.register_script_message('toggle_music_mode', toggle_music_mode)
  102.  
  103. mp.add_hook('on_preloaded', 50, determine_and_update)
  104. mp.observe_property('pause', 'bool', on_pause)
  105.  
  106. -- always show osc when opening a new file
  107. -- useful for network streams - user can see what is happening in the background
  108. mp.add_hook('on_load', 50, function()
  109.         mp.command('script-message osc-visibility always no-osd')
  110.     end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement