-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrt2docx.py
87 lines (61 loc) · 2.13 KB
/
srt2docx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding: utf-8 -*-
"""Script to convert SRT files to DOCX files with tables
Example of end state:
- https://docs.google.com/document/d/1MqnG5MWRbjZBke9ja5CN-rJGijJnWBrRJa6lLOxMvRQ/edit
SRT format docs
- https://en.wikipedia.org/wiki/SubRip
DOCX docs
- https://python-docx.readthedocs.io/en/latest/
Example:
$ python srt2docx.py
Todo:
* Option to go directly to google docs
* Option to combine all files into one docx
* add recursion option glob.glob('**/*.txt', recursive=True)
* add better error handling
This script reads settings from a srt2docx_settings.yaml file in the same directory as the
script file. Edit this file to personalize the settings. This only has to be done once.
Generally there is a make file distributed with this script and can be executed as
follows:
% make setup
otherwise run the following to initialize the environment:
% python -m venv pyenv
% source ./pyenv/bin/activate
% pip install -r requirements.txt
Then activate the environment:
% activate env with: source ./pyenv/bin/activate
Then in a directory containing the files to be processed run:
$ python srt2docx.py
Output files will have the same name as input files but with the .docx extension.
@Author: Scott Dillman <[email protected]>
@Date: 2024-06-25 22:47
"""
import srt2docx_funcs
import argparse
from loguru import logger
import inspect
import os
## argument parser
parser = argparse.ArgumentParser(
prog="srt2docx",
epilog="Please contact [email protected] with problems/issues",
description="Convert srt files to tables in docx",
)
## update me on major changes
__version__ = "0.1.3"
__contact__ = "[email protected]"
__web__ = "https://dreamcyclesetudios.com"
## main entry point
def main():
parser.add_argument(
"-v",
"--version",
action="version",
version="%(prog)s " + __version__ + " | {} | {}".format(__contact__, __web__),
)
parser.parse_args()
## do any init we need
logger.info("Script started: [{}]".format(os.path.realpath(inspect.stack()[0][1])))
srt2docx_funcs.init(__version__)
if __name__ == "__main__":
main()