From 7bb75ae7d99445f8660c4f7b68ddca2647aeb5b0 Mon Sep 17 00:00:00 2001 From: Nitsud Yarg Date: Fri, 15 May 2026 11:46:39 -0700 Subject: [PATCH] add ruby to a vtt file --- subtitle_processor.py | 53 +++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/subtitle_processor.py b/subtitle_processor.py index 4ca1f13..d4e0bee 100644 --- a/subtitle_processor.py +++ b/subtitle_processor.py @@ -32,7 +32,7 @@ def main(): 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: + with open("/run/media/deck/YF8SD/Video/Yu-Gi-Oh! Duel Monsters - 001.vtt", "r", encoding="utf-8") as f: lines = f.readlines() @@ -54,39 +54,42 @@ def main(): 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 + if lines[i] != result['ruby_html']: + lines[i] = result['ruby_html'] + "\n" # lost the new line + # if lines[i] != result['kana_reading']: + # lines[i] = result['kana_reading'] + "\n" # lost the new line else: #notes_lines.append("`" + lines[i].strip() + "`" + "\n") notes_lines.append(lines[i]) i+=1 ## Lookup vocab - for word in vocab: - #vocab_hash = hashlib.shake_256((word + dictionary_name).encode()).hexdigest(4) - if Path(destination_path.joinpath('vocab/' + word + '.md')).exists() == False: - definitions = anki_fields_term(word) - if definitions.get("fields"): - with open(destination_path.as_posix() + '/vocab/' + word + '.md', 'w') as vocab_note: - for entry in definitions.get("fields"): - vocab_note.write("\n") - print(entry['expression'], file=vocab_note) - #print(entry['furigana-plain'], file=vocab_note) - if entry['expression'] != entry['reading']: - print(entry['reading'], file=vocab_note) - print(entry['furigana'], file=vocab_note) - #print(f"Part of Speech: {entry['part-of-speech']}", file=vocab_note) - print(f"Frequency: {entry['frequency-average-rank']}", file=vocab_note) - #print(entry['glossary-plain-no-dictionary'], file=vocab_note) - vocab_note.write(entry['glossary-first']) - print("##### Other Definitions", file=vocab_note) - print(entry['glossary-plain-no-dictionary'], file=vocab_note) + if False: + for word in vocab: + #vocab_hash = hashlib.shake_256((word + dictionary_name).encode()).hexdigest(4) + if Path(destination_path.joinpath('vocab/' + word + '.md')).exists() == False: + definitions = anki_fields_term(word) + if definitions.get("fields"): + with open(destination_path.as_posix() + '/vocab/' + word + '.md', 'w') as vocab_note: + for entry in definitions.get("fields"): + vocab_note.write("\n") + print(entry['expression'], file=vocab_note) + #print(entry['furigana-plain'], file=vocab_note) + if entry['expression'] != entry['reading']: + print(entry['reading'], file=vocab_note) + print(entry['furigana'], file=vocab_note) + #print(f"Part of Speech: {entry['part-of-speech']}", file=vocab_note) + print(f"Frequency: {entry['frequency-average-rank']}", file=vocab_note) + #print(entry['glossary-plain-no-dictionary'], file=vocab_note) + vocab_note.write(entry['glossary-first']) + print("##### Other Definitions", file=vocab_note) + print(entry['glossary-plain-no-dictionary'], file=vocab_note) - with open("subtitle.srt", "w", encoding="utf-8") as f: + with open("/run/media/deck/YF8SD/Video/Yu-Gi-Oh! Duel Monsters - 001.vtt", "w", encoding="utf-8") as f: f.writelines(lines) - with open("notestest-newchunks.md", "w", encoding="utf-8") as f: - f.writelines(notes_lines) + # with open("notestest-newchunks.md", "w", encoding="utf-8") as f: + # f.writelines(notes_lines) #vocab = load_vocab(args.vocab_file) #result = analyze(text, vocab)