53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
from fugashi_parser import *
|
|
|
|
# ---------- CLI ----------
|
|
|
|
def main():
|
|
# parser = argparse.ArgumentParser()
|
|
# parser.add_argument("--vocab-file", required=True)
|
|
# parser.add_argument("text", nargs="*")
|
|
# args = parser.parse_args()
|
|
|
|
vocab = load_vocab('foo.json')
|
|
|
|
with open("/run/media/deck/YF8SD/Video/[Retimed and Corrected] Yu-Gi-Oh! Duel Monsters - 001.srt", "r", encoding="utf-8") as f:
|
|
lines = f.readlines()
|
|
|
|
|
|
notes_lines = []
|
|
|
|
# Example: Modify the 3rd line (index 2)
|
|
#lines[2] = "This is the new subtitle text\n"
|
|
## First lien has some unicode bom bs
|
|
for i in range(len(lines)):
|
|
if re.fullmatch(r'\d+', lines[i].strip()) or i == 0:
|
|
notes_lines.append('##### ' + lines[i].strip() + " `" + lines[i+1].strip() + "`" + "\n")
|
|
i+=1
|
|
continue
|
|
if has_japanese(lines[i]):
|
|
print(lines[i])
|
|
result = analyze(lines[i],vocab)
|
|
print(result['kana_reading'])
|
|
notes_lines.append(result["ruby_html"] + "\n" )
|
|
notes_lines.append (result['notes_link'] + "\n")
|
|
if lines[i] != result['kana_reading']:
|
|
lines[i] = result['kana_reading'] + "\n" # lost the new line
|
|
else:
|
|
notes_lines.append("`" + lines[i].strip() + "`" + "\n")
|
|
|
|
with open("subtitle.srt", "w", encoding="utf-8") as f:
|
|
f.writelines(lines)
|
|
|
|
with open("notestest.md", "w", encoding="utf-8") as f:
|
|
f.writelines(notes_lines)
|
|
|
|
#vocab = load_vocab(args.vocab_file)
|
|
#result = analyze(text, vocab)
|
|
#save_vocab('foo.json', vocab)
|
|
|
|
#result["vocab_file"] = args.vocab_file
|
|
#print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |