Batch sort subtitles by start times

drew007

drew007

King D/D/D
World Nobles
273
Awards
0
@dedsec @WhenMarkers @monkey d luffy @Semisu

Hey guys, thank you so much for the replies, I finally got some time to write the code and I hv uploaded it here. I am no pro at writing codes so please be gentle :p Both are .bat files and use windows cmd commands. This code can be used in Linux using grep and sed commands.

SortSubs file -
1. Removes "[Aegisub Extradata]" line and subsequent lines containing "Data:" (This is garbage anyway and many times not even there but kinda necessary to remove for the routine to work)
2. Sorts the lines in "Dialogue:" according to Start Times.

Aegisub file -
1. Removes "[Aegisub Extradata]" line, "Data:", "Comment:" and "File:" (for "Audio File:" and "Video File:" in "[Aegisub Project Garbage]")
2. Removes lines with same Start and End Time.
3. Sorts the lines in "Dialogue:" according to Start Times.

rundll32 user32.dll,MessageBeep at the end is for system beep that the batch is complete.

Goes without saying u can modify it to suit ur needs ^^ Hope u like it and feedback is appreciated ^^
 

Attachments

Last edited:
WhenMarkers

WhenMarkers

⚔ Secretary of Time ⚔
World Nobles
733
Awards
0
NEET Main Office
@dedsec @WhenMarkers @monkey d luffy @Semisu

Hey guys, thank you so much for the replies, I finally got some time to write the code and I hv uploaded it here. I am no pro at writing codes so please be gentle :p Both are .bat files and use windows cmd commands. This code can be used in Linux using grep and sed commands.

SortSubs file -
1. Removes "[Aegisub Extradata]" line and subsequent lines containing "Data:" (This is garbage anyway and many times not even there but kinda necessary to remove for the routine to work)
2. Sorts the lines in "Dialogue:" according to Start Times.

Aegisub file -
1. Removes "[Aegisub Extradata]" line, "Data:", "Comment:" and "File:" (for "Audio File:" and "Video File:" in "[Aegisub Project Garbage]")
2. Removes lines with same Start and End Time.
3. Sorts the lines in "Dialogue:" according to Start Times.

rundll32 user32.dll,MessageBeep at the end is for system beep that the batch is complete.

Goes without saying u can modify it to suit ur needs ^^ Hope u like it and feedback is appreciated ^^
now this is what i've been waiting.. haha. it's a nice script btw.. :giggle:
 
drew007

drew007

King D/D/D
World Nobles
273
Awards
0
UPDATE: Sorry for this but I found a case where the sort command shows error if a line input is too large (default 4096). I hv fixed it by setting it to max possible 65535 and updated the scripts. U can now use the updated ones ^^ Hopefully no more such/similar cases arise :p
 
drew007

drew007

King D/D/D
World Nobles
273
Awards
0
Ok so this one is updated to work with Linux systems too ^^
The scripts function the same as above but with more features mentioned later. [ Rename the Text files to .sh files and use Unix (LF) EOL if not already before running them. ]

Sorry for the long post and hope its useful to someone ^^ Feedback is appreciated and as always goes without saying u can modify it to suit ur needs ^^

For Windows users, to run these scripts install Cygwin (default install is more than enough and add it to PATH) and then run the scripts by command ---> sh Aegisub.sh

IMP Note : The PATH of Cygwin needs to be before system 32 so that commands like sort (which hv same name in both Win and Linux) work properly as intended. U can install the packages needed using Git for WIndows and GnuWin32 but they are seriously outdated. On the plus side u can use most Linux commands in cmd/Powershell itself if u get Cygwin.

(Both cmd and Powershell work, but Powershell is recommended as my tests showed it to be faster :p, probably cuz win sort is so limited.)

For Linux just sh Aegisub.sh should be just fine.

Features added :

1. The scripts for cases where the Layer Number is above 9 (difficult to implement in above Win only scripts)

2. The sort can sort by Layer Number, Start Time, End Time, Style, Name/Actor, MarginL, MarginR, MarginV and Effect

sort -t',' -k 2 -----------------> 2 is for Start Time (In line 14)

1 for Layer Number, 3 End Time and so on.

3. This works for both subtitles in both Windows and Linux format EOL (CRLF and LF)

4. Faster than the above script.
 

Attachments

Last edited:
WhenMarkers

WhenMarkers

⚔ Secretary of Time ⚔
World Nobles
733
Awards
0
NEET Main Office
Ok so this one is updated to work with Linux systems too ^^
The scripts function the same as above but with more features mentioned later. [ Rename the Text files to .sh files and use Unix (LF) EOL if not already before running them. ]

Sorry for the long post and hope its useful to someone ^^ Feedback is appreciated and as always goes without saying u can modify it to suit ur needs ^^

For Windows users, to run these scripts install Cygwin (default install is more than enough and add it to PATH) and then run the scripts by command ---> sh Aegisub.sh

IMP Note : The PATH of Cygwin needs to be before system 32 so that commands like sort (which hv same name in both Win and Linux) work properly as intended. U can install the packages needed using Git for WIndows and GnuWin32 but they are seriously outdated. On the plus side u can use most Linux commands in cmd/Powershell itself if u get Cygwin.

(Both cmd and Powershell work, but Powershell is recommended as my tests showed it to be faster :p, probably cuz win sort is so limited.)

For Linux just sh Aegisub.sh should be just fine.
now trying this one :giggle:

You must be registered for see images attach
 
Top