diff --git a/videoclip.lua b/videoclip.lua index 137c6aa..151b1c1 100644 --- a/videoclip.lua +++ b/videoclip.lua @@ -46,10 +46,6 @@ local allowed_presets = { ------------------------------------------------------------ -- Utility functions -function string:endswith(suffix) - return suffix == "" or self:sub(-#suffix) == suffix -end - local function remove_extension(filename) return filename:gsub('%.%w+$', '') end @@ -135,6 +131,22 @@ local function set_video_settings() end end +local function validate_config() + if not config.audio_bitrate:match('^%d+[kK]$') then + config.audio_bitrate = (tonumber(config.audio_bitrate) or 32) .. 'k' + end + + if not config.video_bitrate:match('^%d+[kKmM]$') then + config.video_bitrate = '1M' + end + + if not allowed_presets[config.preset] then + config.preset = 'faster' + end + + set_video_settings() +end + ------------------------------------------------------------ -- Provides interface for creating audio/video clips @@ -479,20 +491,8 @@ function Timings:validate() return self['start'] >= 0 and self['start'] < self['end'] end ------------------------------------------------------------- --- Validate config - -if not config.audio_bitrate:endswith('k') then - config.audio_bitrate = config.audio_bitrate .. 'k' -end - -if not allowed_presets[config.preset] then - config.preset = 'faster' -end - -set_video_settings() - ------------------------------------------------------------ -- Finally, set an 'entry point' in mpv +validate_config() mp.add_key_binding('c', 'videoclip-menu-open', main_menu.open)