Skip to content

Instantly share code, notes, and snippets.

@The0x539
Created June 27, 2020 22:39
Show Gist options
  • Save The0x539/ec3b8f3241942d3fb972b8055d3e05c9 to your computer and use it in GitHub Desktop.
Save The0x539/ec3b8f3241942d3fb972b8055d3e05c9 to your computer and use it in GitHub Desktop.
-- Copyright (c) 2020, The0x539 <[email protected]>
--
-- Permission to use, copy, modify, and distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
local tr = aegisub.gettext
script_name = tr"Set min-max timestamps"
script_description = tr"Set all lines in selection to have the same (earliest+latest) start/end times"
script_author = "The0x539"
script_version = "1"
function minmax(subs, sel, _)
aegisub.progress.title("Min-Max Timestamps")
local earliest, latest = math.huge, 0
aegisub.progress.task("Determining earliest/latest timestamps")
for n, i in ipairs(sel) do
aegisub.progress.set(100 * (n - 1)/(#sel - 1))
earliest = math.min(earliest, subs[i].start_time)
latest = math.max(latest, subs[i].end_time)
end
aegisub.progress.set("Applying timestamps")
for n, i in ipairs(sel) do
aegisub.progress.set(100 * (n - 1)/(#sel - 1))
local line = subs[i]
line.start_time = earliest
line.end_time = latest
subs[i] = line
end
aegisub.set_undo_point(tr"minmax timestamps")
end
aegisub.register_macro(script_name, script_description, minmax)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment