""" * Version: 0.1.0.0.0 """ import sys, pathlib import pingcap.pe.flash.util as util import pingcap.pe.flash.util_en2ja as util_en2ja import pingcap.pe.flash.ai_editor as editor if __name__ == "__main__": input_srt_file_path = sys.argv[1] output_srt_file_path = sys.argv[1].split(".")[0] + "_en2ja.srt" temp_en_subtitle_content_file_path = output_srt_file_path.replace( "_en2ja.srt", "_extracted_en.md" ) temp_en2ja_subtitle_content_file_path = output_srt_file_path.replace( "_en2ja.srt", "_extracted_en2ja.md" ) print(util.speak_title("Adjusting SRT content to a new SRT file ...")) mode = "standard" en_1gram_list = util.load_1gram_terms_en("pe") if not pathlib.Path(temp_en_subtitle_content_file_path).is_file(): fr = open(input_srt_file_path, "r") lines = fr.read() fr.close() f = open(temp_en_subtitle_content_file_path, "w") write_lines = editor.extract_subtitle_sentences_from_srt(lines) f.write(write_lines) f.close() else: print(util.speak_title("Skip step 1 ...")) if not pathlib.Path(temp_en2ja_subtitle_content_file_path).is_file(): write_lines = [] fr = open(temp_en_subtitle_content_file_path, "r") lines = fr.read() fr.close() f = open(temp_en2ja_subtitle_content_file_path, "w") for line in lines.split("\n"): write_lines += [ line + " <=> " + util_en2ja.translate_en2ja_md_line( line, en_1gram_list, "silent", True, None ) ] f.write("\n".join(write_lines)) f.close() else: print(util.speak_title("Skip step 2 ...")) en_srt = open(input_srt_file_path, "r") en_extracted = open(temp_en_subtitle_content_file_path, "r") en2ja_extracted = open(temp_en2ja_subtitle_content_file_path, "r") en_srt_lines = en_srt.read() en_srt.close() en_extracted_lines = en_extracted.read() en_extracted.close() en2ja_extracted_lines = en2ja_extracted.read() en2ja_extracted.close() f = open(output_srt_file_path, "w") write_lines = editor.create_srt_en2ja(en_srt_lines, en2ja_extracted_lines) f.write(write_lines) f.close() if mode == "standard": print( util.speak_result( "extracted_en_subtitles_path: " + temp_en_subtitle_content_file_path ) ) print( util.speak_result( "extracted_en2ja_subtitles_path: " + temp_en2ja_subtitle_content_file_path ) ) print(util.speak_result("output_srt_path: " + output_srt_file_path))