globals.lua (7191B)
1 -------------------------------------------------------------------------------------------------------- 2 ------------------------------------------Variable Setup------------------------------------------------ 3 -------------------------------------------------------------------------------------------------------- 4 -------------------------------------------------------------------------------------------------------- 5 6 local mp = require 'mp' 7 local o = require 'modules.options' 8 9 ---@class globals 10 local globals = {} 11 12 --sets the version for the file-browser API 13 globals.API_VERSION = "1.9.0" 14 15 ---gets the current platform (in mpv v0.36+) 16 ---in earlier versions it is set to `windows`, `darwin` or `other` 17 ---@type 'windows'|'darwin'|'linux'|'android'|'freebsd'|'other'|string|nil 18 globals.PLATFORM = mp.get_property_native('platform') 19 if not globals.PLATFORM then 20 local _ = {} 21 if mp.get_property_native('options/vo-mmcss-profile', _) ~= _ then 22 globals.PLATFORM = 'windows' 23 elseif mp.get_property_native('options/macos-force-dedicated-gpu', _) ~= _ then 24 globals.PLATFORM = 'darwin' 25 end 26 return 'other' 27 end 28 29 --the osd_overlay API was not added until v0.31. The expand-path command was not added until 0.30 30 assert(mp.create_osd_overlay, "Script requires minimum mpv version 0.33") 31 32 globals.ass = mp.create_osd_overlay("ass-events") 33 globals.ass.res_y = 720 / o.scaling_factor_base 34 35 local BASE_FONT_SIZE = 25 36 37 --force file-browser to use a specific text alignment (default: top-left) 38 --uses ass tag alignment numbers: https://aegi.vmoe.info/docs/3.0/ASS_Tags/#index23h3 39 globals.ASS_ALIGNMENT_MATRIX = { 40 top = {left = 7, center = 8, right = 9}, 41 center = {left = 4, center = 5, right = 6}, 42 bottom = {left = 1, center = 2, right = 3}, 43 } 44 45 globals.ALIGN_X = o.align_x == 'auto' and mp.get_property('osd-align-x', 'left') or o.align_x 46 globals.ALIGN_Y = o.align_y == 'auto' and mp.get_property('osd-align-y', 'top') or o.align_y 47 48 globals.style = { 49 global = ([[{\an%d}]]):format(globals.ASS_ALIGNMENT_MATRIX[globals.ALIGN_Y][globals.ALIGN_X]), 50 51 -- full line styles 52 header = ([[{\r\q2\b%s\fs%d\fn%s\c&H%s&}]]):format((o.font_bold_header and "1" or "0"), o.scaling_factor_header*BASE_FONT_SIZE, o.font_name_header, o.font_colour_header), 53 body = ([[{\r\q2\fs%d\fn%s\c&H%s&}]]):format(BASE_FONT_SIZE, o.font_name_body, o.font_colour_body), 54 footer_header = ([[{\r\q2\fs%d\fn%s\c&H%s&}]]):format(o.scaling_factor_wrappers*BASE_FONT_SIZE, o.font_name_wrappers, o.font_colour_wrappers), 55 56 --small section styles (for colours) 57 multiselect = ([[{\c&H%s&}]]):format(o.font_colour_multiselect), 58 selected = ([[{\c&H%s&}]]):format(o.font_colour_selected), 59 playing = ([[{\c&H%s&}]]):format(o.font_colour_playing), 60 playing_selected = ([[{\c&H%s&}]]):format(o.font_colour_playing_multiselected), 61 warning = ([[{\c&H%s&}]]):format(o.font_colour_escape_chars), 62 63 --icon styles 64 indent = ([[{\alpha&H%s}]]):format('ff'), 65 cursor = ([[{\fn%s\c&H%s&}]]):format(o.font_name_cursor, o.font_colour_cursor), 66 cursor_select = ([[{\fn%s\c&H%s&}]]):format(o.font_name_cursor, o.font_colour_multiselect), 67 cursor_deselect = ([[{\fn%s\c&H%s&}]]):format(o.font_name_cursor, o.font_colour_selected), 68 folder = ([[{\fn%s}]]):format(o.font_name_folder), 69 selection_marker = ([[{\alpha&H%s}]]):format(o.font_opacity_selection_marker), 70 } 71 72 ---@type State 73 globals.state = { 74 list = {}, 75 selected = 1, 76 hidden = true, 77 flag_update = false, 78 keybinds = nil, 79 80 parser = nil, 81 directory = nil, 82 directory_label = nil, 83 prev_directory = '', 84 empty_text = 'Empty Directory', 85 co = nil, 86 87 multiselect_start = nil, 88 initial_selection = nil, 89 selection = {} 90 } 91 92 ---@class ParserRef 93 ---@field id string 94 ---@field index number? 95 96 ---@type table<number,Parser>|table<string,Parser>|table<Parser,ParserRef>> 97 --the parser table actually contains 3 entries for each parser 98 --a numeric entry which represents the priority of the parsers and has the parser object as the value 99 --a string entry representing the id of each parser and with the parser object as the value 100 --and a table entry with the parser itself as the key and a table value in the form { id = %s, index = %d } 101 globals.parsers = {} 102 103 --this table contains the parse_state tables for every parse operation indexed with the coroutine used for the parse 104 --this table has weakly referenced keys, meaning that once the coroutine for a parse is no-longer used by anything that 105 --field in the table will be removed by the garbage collector 106 ---@type table<thread,ParseState> 107 globals.parse_states = setmetatable({}, { __mode = "k"}) 108 109 ---@type Set<string> 110 globals.extensions = {} 111 112 ---@type Set<string> 113 globals.sub_extensions = {} 114 115 ---@type Set<string> 116 globals.audio_extensions = {} 117 118 ---@type Set<string> 119 globals.parseable_extensions = {} 120 121 ---This table contains mappings to convert external directories to cannonical 122 --locations within the file-browser file tree. The keys of the table are Lua 123 --patterns used to evaluate external directory paths. The value is the path 124 --that should replace the part of the path than matched the pattern. 125 --These mappings should only applied at the edges where external paths are 126 --ingested by file-browser. 127 ---@type table<string,string> 128 globals.directory_mappings = {} 129 130 ---@class CurrentFile 131 ---@field directory string? 132 ---@field name string? 133 ---@field path string? 134 ---@field original_path string? 135 globals.current_file = { 136 directory = nil, 137 name = nil, 138 path = nil, 139 original_path = nil, 140 } 141 142 ---@type List 143 globals.root = {} 144 145 ---@class (strict) History 146 ---@field list string[] 147 ---@field size number 148 ---@field position number 149 globals.history = { 150 list = {}, 151 size = 0, 152 position = 0, 153 } 154 155 ---@class (strict) DirectoryStack 156 ---@field stack string[] 157 ---@field position number 158 globals.directory_stack = { 159 stack = {}, 160 position = 0, 161 } 162 163 164 --default list of compatible file extensions 165 --adding an item to this list is a valid request on github 166 globals.compatible_file_extensions = { 167 "264","265","3g2","3ga","3ga2","3gp","3gp2","3gpp","3iv","a52","aac","adt","adts","ahn","aif","aifc","aiff","amr","ape","asf","au","avc","avi","awb","ay", 168 "bmp","cue","divx","dts","dtshd","dts-hd","dv","dvr","dvr-ms","eac3","evo","evob","f4a","flac","flc","fli","flic","flv","gbs","gif","gxf","gym", 169 "h264","h265","hdmov","hdv","hes","hevc","jpeg","jpg","kss","lpcm","m1a","m1v","m2a","m2t","m2ts","m2v","m3u","m3u8","m4a","m4v","mk3d","mka","mkv", 170 "mlp","mod","mov","mp1","mp2","mp2v","mp3","mp4","mp4v","mp4v","mpa","mpe","mpeg","mpeg2","mpeg4","mpg","mpg4","mpv","mpv2","mts","mtv","mxf","nsf", 171 "nsfe","nsv","nut","oga","ogg","ogm","ogv","ogx","opus","pcm","pls","png","qt","ra","ram","rm","rmvb","sap","snd","spc","spx","svg","thd","thd+ac3", 172 "tif","tiff","tod","trp","truehd","true-hd","ts","tsa","tsv","tta","tts","vfw","vgm","vgz","vob","vro","wav","weba","webm","webp","wm","wma","wmv","wtv", 173 "wv","x264","x265","xvid","y4m","yuv" 174 } 175 176 ---@class BrowserAbortError 177 globals.ABORT_ERROR = { 178 msg = "browser is no longer waiting for list - aborting parse" 179 } 180 181 return globals