Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
2srt2ass standalone offline python version
from pysubs2 import *
import sys
def main(argv=sys.argv):
if len(argv) <= 2:
print("Usage: python styled-sub-merge.py output-file input-file1 input-file2")
return
subs = load("template.ass")
for i in range(2, 4):
try:
new_subs = load(argv[i])
style = style = "Default" if i == 2 else "Top"
for ev in new_subs:
ev.style = style
subs.append(ev)
except Exception as e:
print("Input file exception: " + str(e) + " (" + argv[i] + ")")
return
subs.sort()
output = argv[1]
try:
subs.save(output)
except Exception as e:
print("Output file exception: " + str(e) + " (" + output + ")")
return
print("Subtitles saved successfully at " + output)
if __name__ == "__main__":
main()
[Script Info]
ScriptType: v4.00+
Collisions: Normal
PlayDepth: 0
Timer: 100,0000
Video Aspect Ratio: 0
WrapStyle: 0
ScaledBorderAndShadow: no
[V4+ Styles]
Format: Name,Fontname,Fontsize,PrimaryColour,SecondaryColour,OutlineColour,BackColour,Bold,Italic,Underline,StrikeOut,ScaleX,ScaleY,Spacing,Angle,BorderStyle,Outline,Shadow,Alignment,MarginL,MarginR,MarginV,Encoding
Style: Default,Arial,16,&H00F9FFF9,&H00FFFFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,3,0,2,10,10,10,0
Style: Top,Arial,16,&H00F99999,&H00FFFFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,3,0,8,10,10,10,0
@s-tarasov

This comment has been minimized.

Copy link
Owner Author

@s-tarasov s-tarasov commented Nov 24, 2020

Usage:

Install http://pythonhosted.org/pysubs2/. Just use pip: pip install pysubs2. You can also clone the pysubs2 GitHub repository and install via python setup.py install.
Download this files
Run in terminal python styled-sub-merge.py output-file input-file1 input-file2
Example: python styled-sub-merge.py result.ass first-part.srt second-part.srt
Supported formats are SRT, ASS, SUB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment