Skip to content

Instantly share code, notes, and snippets.

@tophf
Created May 4, 2014 00:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tophf/19aac84becdeeeb003d9 to your computer and use it in GitHub Desktop.
Save tophf/19aac84becdeeeb003d9 to your computer and use it in GitHub Desktop.
export script_name = 'Delete keyframe'
export script_description = 'Delete keyframe from a loaded "keyframe format v1" file'
aegisub.register_macro script_name, script_description, (subs) ->
local kf_file
error 'Load video first.' if not aegisub.frame_from_ms 0
info_section_scanned = false
for line in *subs
if line.class=='info'
info_section_scanned = true
if line.key=='Keyframes File'
kf_file = line.value
if not kf_file\find '[/\\]'
kf_file = aegisub.decode_path '?script/'..kf_file
break
elseif info_section_scanned
error 'No keyframes file specified in the [Info] section, try saving the subtitles first.'
f = io.open kf_file,'r'
error 'Cannot read from '..kf_file if not f
txt = f\read '*all'
f\close!
i,j = txt\find '\n'..aegisub.active_frame!..'\n'
i,j = txt\find '\n'..aegisub.active_frame! if not i
aegisub.cancel! if not i
f = io.open kf_file,'w'
error 'Cannot write to '..kf_file if not f
f\write txt\sub(1,i)..txt\sub(j+1)
f\close!
aegisub.close_keyframes!
aegisub.load_keyframes kf_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment