""" * Version: 0.1.0.0.0 """ import sys, pathlib, re import pingcap.pe.flash.util as util import pingcap.pe.flash.ai_editor as editor import pingcap.pe.flash.util_srt as util_srt if __name__ == "__main__": input_srt_file_path = sys.argv[1] # Stage 1 parsed_srt_file_path = sys.argv[1].split(".")[0] + "_parsed_srt_to_paragraph.md" print(util.speak_title("Parsing SRT content to a Markdown file ...")) fr = open(input_srt_file_path, "r") lines = fr.read() fr.close() f = open(parsed_srt_file_path, "w") cache = util_srt.process_srt_to_paragraph(lines) f.write(cache["paragraph"]) f.close() # Refine the original SRT refined_srt_file_path = parsed_srt_file_path.replace( "_parsed_srt_to_paragraph.md", "_refined.srt" ) wr = open(refined_srt_file_path, "w") append = False first = True for line in lines.split("\n"): if re.match("^[0-9]*$", line): append = False if first: wr.write(line + "\n") first = False else: wr.write("\n" + line + "\n") elif re.match("^[0-9][0-9]:[0-9][0-9]:[0-9][0-9],[0-9][0-9][0-9]", line): wr.write(line + "\n") elif re.match("^$", line): wr.write("\n\n") else: if not append: wr.write(line.replace("\xa0", "")) append = True else: wr.write(" " + line.replace("\xa0", "")) wr.close() print( util.speak_result("parsed_srt_to_paragraph_file_path: " + parsed_srt_file_path) ) # Stage 2 sentences_file_path = sys.argv[1].split(".")[0] + "_parsed_srt_to_sentences.md" print(util.speak_title("Parsing paragraph to sentences to a Markdown file ...")) f = open(sentences_file_path, "w") cache = util_srt.split_en_paragraph_to_sentences(cache) sentences = [] for k in cache.keys(): if k.startswith("S-"): sentences += [cache[k]] f.write("\n\n".join(sentences)) f.close() # Stage 3 timestamp_sentences_file_path = ( sys.argv[1].split(".")[0] + "_parsed_srt_to_timestamp_sentences.md" ) print( util.speak_title( "Parsing paragraph to timestamp sentences to a Markdown file ..." ) ) f = open(timestamp_sentences_file_path, "w") timestamp_sentences = [] for k in cache.keys(): if k.startswith("TS-"): timestamp_sentences += [cache[k]] f.write("\n\n".join(timestamp_sentences)) f.close() # Stage 4 ja_sentences_file_path = ( sys.argv[1].split(".")[0] + "_translated_srt_en2ja_sentences.md" ) print(util.speak_title("Translating sentences to a Markdown file ...")) cache = util_srt.translate_sentence_en2ja(cache) f = open(ja_sentences_file_path, "w") ja_sentences = [] for k in cache.keys(): if k.startswith("JS-"): ja_sentences += [cache[k]] f.write("\n\n".join(ja_sentences)) f.close() # Stage 5 enja_sentences_file_path = ( sys.argv[1].split(".")[0] + "_workbench_srt_en2ja_sentences.md" ) print(util.speak_title("Generating workbench file to a Markdown file ...")) f = open(enja_sentences_file_path, "w") enja_sentences = [] for k in cache.keys(): if k.startswith("EJS-"): enja_sentences += [cache[k]] f.write("\n\n".join(enja_sentences)) f.close() print(util.speak_title("sentences")) for k in cache.keys(): if k.startswith("S-"): print(cache[k]) print(util.speak_title("ja sentences")) for k in cache.keys(): if k.startswith("JS-"): print(cache[k]) print(util.speak_title("time-sentences")) for k in cache.keys(): if k.startswith("TS-"): print(cache[k]) print(util.speak_title("enja sentences")) for k in cache.keys(): if k.startswith("EJS-"): print(cache[k]) print(util.speak_result("workbench_file_path: " + enja_sentences_file_path))