Jump to content

[solved] Automation script to remove select tags in Aegisub


Moodkiller

Recommended Posts

Im looking to remove the tags \an* and \pos(*.*,*.*) where * = any number, from a subtitle script. Aegisub has an automation function with a "Strip tags" option...
This removes everything within the curly brackets { } for a select line, so I thought it would easy enough to modify this and get it remove the before mentioned tags.
 
Here is the original code (for striping all the tags):
 

local tr = aegisub.gettextscript_name = tr"Strip tags"script_description = tr"Remove all override tags from selected lines"script_author = "Thomas Goyne"script_version = "1"function strip_tags(subs, sel)    for _, i in ipairs(sel) do        local line = subs[i]        line.text = line.text:gsub("{[^}]+}", "")        subs[i] = line    end    aegisub.set_undo_point(tr"strip tags")endaegisub.register_macro(script_name, script_description, strip_tags)

Im pretty sure the line

line.text = line.text:gsub("{[^}]+}", "")

is the one that needs to be modified. I tried replacing it with this for now

line.text = line.text:gsub("\an5", "")

Note: I used 5 as I dont know if wildcards are supported (Im sure they are) and becuase the actual tag I want removed is \an5.
 
Unfortunately this doesn't work. The line stays unmodified after using the script through Aegisub. I haven't attempted removing \pos() yet
 


Solution:

 

To summarize:

line.text = line.text:gsub("\\an5", "")line.text = line.text:gsub("\\pos%b()", "")
Does exactly what I was looking for. 
Thanks again JF

 

Source

Edited by Moodkiller
Link to comment
Share on other sites

Pretty sure you have to escape your escape character ('\').

Edit: Brackets are evil.

 

Didnt think it would matter seen as it is inside inverted commas? 

 

Pre-post edit:

Haha holy shit it works!! Just left with the \ now... One step closer :)

 

Real edit: Spelling

Edited by Moodkiller
Link to comment
Share on other sites

Originally this:




 line.text = line.text:gsub("an5", "")
line.text = line.text:gsub("pos", "")

which left me with the \ and the pos tag's co-ordinates I.e. \pos(100,100) became \(100.100)

 


And then I changed it to this:




 line.text = line.text:gsub("an5", "an8")
 line.text = line.text:gsub("pos", "")

As ultimately I wanted the location of the subtitle to be in the top center position/anchored. 


 




In the end what I was hoping for this to achieve, isnt so, but thats a different topic altogether.


Link to comment
Share on other sites

That edit... I was just about to post the code that I used, but see you changed it to what I got to work :).


 


Thanks for the link, that'll definitely come in handy. 


 


To summarize:




line.text = line.text:gsub("\\an5", "")
line.text = line.text:gsub("\\pos%b()", "")

Does exactly what I was looking for. 


Thanks again JF



 


Link to comment
Share on other sites

You know, unanimated has scripts for almost anything you may need http://unanimated.xtreemhost.com/ts/scripts.htm so just learn to use them.

I thought I linked his site to you already.

 

You want "Script Cleanup" script.

 

Thanks, I will have a better look through there. I didnt realise he had scripts as well. The page I think you linked to me last time around was the basics of typesetting? I think. 

 

The Script Cleanup script: 

Script Cleanup

delete comments

delete tags

delete commented or empty lines

clear actor / effect field

raise dialogue layer by 5

clean up tags / remove garbage / round numbers

delete specific tags or groups of related tags (colours, alphas, rotations...)

remove linebreaks

 

 

I assume the "delete tags" will be the one to use. 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...
Please Sign In