move code to a function

This commit is contained in:
Ren Tatsumoto 2020-10-24 12:02:32 +03:00
parent 961c0e03c7
commit 90379c7e06

View file

@ -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)