Skip to content

Instantly share code, notes, and snippets.

@Izaron
Created November 30, 2016 19:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Izaron/3b5f8319b1c17128dd3421dfed4d4db7 to your computer and use it in GitHub Desktop.
Save Izaron/3b5f8319b1c17128dd3421dfed4d4db7 to your computer and use it in GitHub Desktop.
from pysubs2 import *
import sys
def main(argv=sys.argv):
if len(argv) <= 2:
print("Usage: python subtitle-glue.py output-file input-files")
return
subs = SSAFile()
for i in range(2, len(argv)):
try:
new_subs = load(argv[i])
for ev in new_subs:
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()
@Izaron
Copy link
Author

Izaron commented Nov 30, 2016

Usage:

  1. 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.
  2. Download this file
  3. Run in terminal python subtitle-glue.py output-file input-files. Count of input files may be from 1 to infinity.
    Example: python subtitle-glue.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