Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASSWipe: Reuse the ASSInspector instance #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions ASSWipe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local LineCollection = require("a-mo.LineCollection")
local ASSTags = require("l0.ASSTags")
local Log = require("a-mo.Log")
local ConfigHandler = require("a-mo.ConfigHandler")
local ASSInspector = require("ASSInspector.Inspector")

local reportMsg = [[
Done. Processed %d lines in %d seconds.
Expand Down Expand Up @@ -50,7 +51,8 @@ function showDialog(sub, sel, res)
end
end

function process(sub, sel, res)
function process(sub, sel, res)
local assi = ASSInspector(sub)
local lines, linesToDelete, delCnt = LineCollection(sub,sel), {}, 0
local debugError, lineCnt = false, #lines.lines
local tagNames = table.insert(res.filterClips and ASS.tagNames.clips or {},
Expand All @@ -67,7 +69,7 @@ function process(sub, sel, res)
end

local data, oldText = ASS.parse(line), line.text
local oldBounds = data:getLineBounds(false)
local oldBounds = data:getLineBounds(assi, false)

if res.removeInvisible and oldBounds.w == 0 then
-- remove invisible lines
Expand All @@ -76,35 +78,35 @@ function process(sub, sel, res)
else
-- clean tags
data:cleanTags(res.cleanLevel)
local newBounds = data:getLineBounds()
local newBounds = data:getLineBounds(assi)

if res.filterClips or res.removeJunk then
data:modTags(tagNames, function(tag)
-- remove junk
if tag.instanceOf[ASSUnknown] then
if tag.instanceOf[ASSUnknown] then
stats.junk = stats.junk + 1
return false
end

-- filter clips
tag.disabled = true
if data:getLineBounds():equal(newBounds) then
if data:getLineBounds(assi):equal(newBounds) then
stats.clips = stats.clips + 1
return false
else tag.disabled = false end
end)
end

data:commit()

if oldText~=line.text then
if not newBounds:equal(oldBounds) then
debugError = true
Log.warn("Cleaning affected output on line #%d, rolling back...", line.humanizedNumber)
Log.warn("—— Before: %s\n—— After: %s\n—— Style: %s\n", oldText, line.text, line.styleRef.name)
line.text = oldText
else
stats.cleaned, stats.bytes = stats.cleaned+1, stats.bytes + #oldText - #line.text
else
stats.cleaned, stats.bytes = stats.cleaned+1, stats.bytes + #oldText - #line.text
end
aegisub.progress.set(100*i/lineCnt)
end
Expand All @@ -124,4 +126,4 @@ function process(sub, sel, res)
end
end

aegisub.register_macro(script_name, script_description, showDialog)
aegisub.register_macro(script_name, script_description, showDialog)