From e888384af1214a2ba0f0ad49221b1e6b660b55dd Mon Sep 17 00:00:00 2001 From: Nitsud Yarg Date: Thu, 25 Jun 2026 20:39:53 -0700 Subject: [PATCH] flip flipping words flip --- fugashi_parser.py | 24 +++++++++++++++++------- subtitle_processor.py | 7 +++---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/fugashi_parser.py b/fugashi_parser.py index 91094ab..72ef555 100644 --- a/fugashi_parser.py +++ b/fugashi_parser.py @@ -131,23 +131,24 @@ def get_card_proficiency(query="deck:current"): # Anki queue mappings: # 0 = New, 1 = Learning, 2 = Review, 3 = Relearning + # https://www.w3.org/TR/webvtt1/#default-text-color if queue_state == 0: status = "New" - color = '' + color = 'red' elif queue_state == 1: status = "Learning" - color = 'orangered' + color = 'yellow' elif queue_state == 3: status = "Relearning" - color = 'yellow' + color = 'lime' elif queue_state == 2: # Review card split by 21-day threshold if interval >= 21: status = "Mature" - color = 'cyan' + color = 'magenta' else: status = "Young" - color = 'lime' + color = 'cyan' elif queue_state < 0: status = "Suspended" color = '' @@ -216,9 +217,15 @@ def should_ruby(surface, reading_hiragana): return True def build_ruby(surface: str, reading: str) -> str: - if not reading or surface == reading or not has_japanese(surface): + if not reading or not has_japanese(surface): return html.escape(surface) - return f"{html.escape(surface)}{html.escape(reading)}" + style_attr = '' + if proficiency_stats.get(surface): + if proficiency_stats[surface]['Color'] != '': + style_attr = f"style=\"color:{proficiency_stats[surface]['Color']}\"" + if surface == reading: + return f"{html.escape(surface)}" + return f"{html.escape(surface)}{html.escape(reading)}" def build_sub_cue(surface: str, reading: str) -> str: if not reading or not has_japanese(surface): @@ -417,6 +424,7 @@ def analyze(text: str, vocab: Dict[str, Dict]): tokens: List[TokenReading] = [] ruby_parts = [] + subtitle_parts = [] kana_parts = [] vocab_link_parts = [] @@ -452,6 +460,7 @@ def analyze(text: str, vocab: Dict[str, Dict]): tokens.append(token) ruby_parts.append(build_ruby(surface, reading)) + subtitle_parts.append(build_sub_cue(surface, reading)) kana_parts.append(build_kana(surface, reading)) predicate_chunks = chunk_predicates(tokens) @@ -461,6 +470,7 @@ def analyze(text: str, vocab: Dict[str, Dict]): "original_text": text, "kana_reading": "".join(kana_parts), "ruby_html": "".join(ruby_parts), + "sub_cue": "".join(subtitle_parts), "notes_link":"".join(vocab_link_parts), "token_readings": [asdict(t) for t in tokens], "predicate_chunks" : predicate_chunks, diff --git a/subtitle_processor.py b/subtitle_processor.py index 762cdfb..50ac979 100644 --- a/subtitle_processor.py +++ b/subtitle_processor.py @@ -70,11 +70,10 @@ def main(): 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["sub_cue"] + "\n" ) notes_lines.append (result['notes_link'] + "\n") - if lines[i] != result['ruby_html']: - lines[i] = result['ruby_html'] + "\n" # lost the new line + if lines[i] != result['sub_cue']: + lines[i] = result['sub_cue'] + "\n" # lost the new line # if lines[i] != result['kana_reading']: # lines[i] = result['kana_reading'] + "\n" # lost the new line else: