Advertisement
pushrbx

AegiSub script: Duplicate lines by frame

Mar 6th, 2014
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.40 KB | None | 0 0
  1. script_name = "Sor duplikálás képkockánként"
  2. script_description = "Képkockánként duplikál egy sort és az előző sor hosszával lépteti előre."
  3. script_author = "Hughes - isshotosho.info"
  4.  
  5. function table.shallow_copy(t)
  6.     local t2 = {}
  7.     for k,v in pairs(t) do
  8.         t2[k] = v
  9.     end
  10.     return t2
  11. end
  12.  
  13.  
  14. function dup(subtitles, selected_lines, active_line)
  15.     local result, line, duration = nil
  16.     -- lemasoljuk a kivalasztottak tablajat
  17.     -- mert minden table ertek adas referencia alapu
  18.     result = table.shallow_copy(selected_lines)
  19.    
  20.     -- i -> kivalasztott sor index
  21.     -- v -> kivalasztott sor szama
  22.     for i,v in pairs(selected_lines) do
  23.         local tempStart, tempEnd = 0
  24.         line = subtitles[v] -- line -> table object
  25.        
  26.         tempStart = aegisub.frame_from_ms(line.start_time)
  27.         tempEnd = aegisub.frame_from_ms(line.end_time)
  28.        
  29.         line.start_time = aegisub.ms_from_frame(tempStart + 1)
  30.         line.tempEnd = aegisub.ms_from_frame(tempEnd + 1)
  31.        
  32. --      duration = line.end_time - line.start_time
  33. --      line.start_time = duration + line.start_time
  34. --      line.end_time = duration + line.end_time
  35.         result[i] = line
  36.     end
  37.    
  38.     return result
  39. end
  40.  
  41. function duplicate_macro(subs, selected_lines, active_line)
  42.     -- i -> kivalasztott sor index
  43.     -- line -> table object
  44.     aegisub.set_undo_point("duplicateAndShift")
  45.     aegisub.progress.task('Sorok duplikálása...')
  46.  
  47.     for i,line in pairs(dup(subs, selected_lines, active_line)) do
  48.         subs.insert(selected_lines[i] + i, line)
  49.     end
  50.    
  51.     -- allitsuk be a kivalasztott sorokat
  52.     local result = {}
  53.     for k,v in pairs(selected_lines) do
  54.         result[#result+1] = k+v
  55.     end
  56.     aegisub.progress.task('kész...')
  57.     aegisub.progress.set(100)
  58.     return result
  59. end
  60.  
  61. function duplicate_group_macro(subs, selected_lines, active_line)
  62.     aegisub.set_undo_point("duplicateAndShift")
  63.    
  64.     -- duplikáljuk
  65.     subs.insert(selected_lines[#selected_lines] + 1, unpack(dup(subs, selected_lines, active_line)))
  66.     local result = {}
  67.    
  68.     -- csoportosítsunk
  69.     for i = 1, #selected_lines do
  70.         result[#result + 1] = selected_lines[#selected_lines] + i
  71.     end
  72.    
  73.     return result
  74. end
  75.  
  76. function validate(subtitles, selected_lines)
  77.     if #selected_lines > 0 and aegisub.video_size() then
  78.         return true
  79.     end
  80.    
  81.     return false
  82. end
  83.  
  84. aegisub.register_macro(script_name, script_description, duplicate_macro, validate)
  85. aegisub.register_macro(script_name .. " és csoportosítás", script_description, duplicate_group_macro, validate)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement