@@ -781,7 +781,7 @@ def generate_section(
781781 if bar :
782782 fi = f"F{ ld .file_idx } " if ld .file_idx > 1 else ""
783783 bar .set_postfix_str (f"L{ lec_num } { fi } §{ ci } cached" )
784- return sec_file .read_text (encoding = "utf-8" )
784+ return sec_file .read_text (encoding = "utf-8" ), False
785785
786786 chunk_title = _chunk_title (chunk )
787787 fi_tag = f"F{ ld .file_idx } " if ld .file_idx > 1 else ""
@@ -841,7 +841,7 @@ def generate_section(
841841 heading = f"### { lec_num } .{ ci } { chunk_title } "
842842 content = f"{ heading } \n \n { draft } "
843843 sec_file .write_text (content , encoding = "utf-8" )
844- return content
844+ return content , True
845845
846846
847847def generate_lecture (
@@ -856,13 +856,16 @@ def generate_lecture(
856856 bar : tqdm | None = None ,
857857 force : bool = False ,
858858) -> str :
859- """Generate all sections for one lecture, saving each to sections_dir."""
859+ """Generate all sections for one lecture, saving each to sections_dir.
860+ Returns (merged_text, any_fresh) where any_fresh is True if at least
861+ one section was freshly generated (not loaded from cache)."""
860862 has_transcript = bool (ld .compact_by_idx )
863+ any_fresh = False
861864 chunks = [ld .slides [i :i + CHAPTER_SIZE ]
862865 for i in range (0 , len (ld .slides ), CHAPTER_SIZE )]
863866 parts : list [str ] = []
864867 for ci , chunk in enumerate (chunks , start = 1 ):
865- content = generate_section (
868+ content , fresh = generate_section (
866869 lec_num = lec_num ,
867870 lec_title = lec_title ,
868871 course_name = course_name ,
@@ -877,9 +880,10 @@ def generate_lecture(
877880 force = force ,
878881 )
879882 parts .append (content )
883+ any_fresh = any_fresh or fresh
880884 if bar :
881885 bar .update (1 )
882- return "\n \n " .join (parts )
886+ return "\n \n " .join (parts ), any_fresh
883887
884888
885889# ── Self-scoring ──────────────────────────────────────────────────────────────
@@ -1089,6 +1093,7 @@ def merge_sections(
10891093 out_path : Path ,
10901094 all_slides : list [SlideInfo ],
10911095 all_compact : list [dict ],
1096+ run_image_filter : bool = True ,
10921097) -> tuple [Path , dict ]:
10931098 """Read all saved section files and merge into one final Markdown note."""
10941099 from itertools import groupby
@@ -1141,9 +1146,12 @@ def merge_sections(
11411146 f"categories:\n - tech\n ---\n \n " )
11421147 full_notes = front + f"# { course_name } Notes\n \n " + "\n \n ------\n \n " .join (note_sections )
11431148
1144- # ── Image filter agent pass ────────────────────────────────────────────────
1145- tqdm .write (" Running image filter pass…" )
1146- full_notes , _ , _ = filter_images_pass (full_notes , out_path .parent , lectures )
1149+ # ── Image filter agent pass (only for newly generated content) ─────────────
1150+ if run_image_filter :
1151+ tqdm .write (" Running image filter pass…" )
1152+ full_notes , _ , _ = filter_images_pass (full_notes , out_path .parent , lectures )
1153+ else :
1154+ tqdm .write (" Skipping image filter (all sections from cache)." )
11471155
11481156 out_path .write_text (full_notes , encoding = "utf-8" )
11491157 tqdm .write (f"\n Merged → { out_path } ({ len (full_notes ):,} chars)" )
@@ -1196,10 +1204,11 @@ def generate_course_notes(
11961204 bar_format = "{l_bar}{bar}| {n_fmt}/{total_fmt} sections [{elapsed}<{remaining}]" )
11971205
11981206 # ── Phase 1: generate each section independently ──────────────────────────
1207+ any_new = False
11991208 for ld in lectures :
12001209 all_slides .extend (ld .slides )
12011210 all_compact .extend (ld .compact_slides )
1202- generate_lecture (
1211+ _ , fresh = generate_lecture (
12031212 lec_num = ld .num ,
12041213 lec_title = ld .title ,
12051214 course_name = course_name ,
@@ -1211,6 +1220,7 @@ def generate_course_notes(
12111220 bar = bar ,
12121221 force = force ,
12131222 )
1223+ any_new = any_new or fresh
12141224
12151225 bar .close ()
12161226
@@ -1223,6 +1233,7 @@ def generate_course_notes(
12231233 out_path = out_path ,
12241234 all_slides = all_slides ,
12251235 all_compact = all_compact ,
1236+ run_image_filter = any_new ,
12261237 )
12271238
12281239
@@ -1269,8 +1280,9 @@ def generate_per_video_notes(
12691280 for i in range (0 , len (ld .slides ), CHAPTER_SIZE )]
12701281
12711282 parts : list [str ] = []
1283+ any_fresh = False
12721284 for ci , chunk in enumerate (chunks , start = 1 ):
1273- content = generate_section (
1285+ content , fresh = generate_section (
12741286 lec_num = lec_num ,
12751287 lec_title = lec_title ,
12761288 course_name = course_name ,
@@ -1285,6 +1297,7 @@ def generate_per_video_notes(
12851297 force = force ,
12861298 )
12871299 parts .append (content )
1300+ any_fresh = any_fresh or fresh
12881301 bar .update (1 )
12891302 bar .close ()
12901303
@@ -1297,9 +1310,12 @@ def generate_per_video_notes(
12971310 heading = f"# { course_name } — Lecture { lec_num } : { lec_title } \n \n "
12981311 full_notes = front + heading + "\n \n " .join (parts )
12991312
1300- # Image filter
1301- tqdm .write (" Running image filter pass…" )
1302- full_notes , _ , _ = filter_images_pass (full_notes , out_dir , [ld ])
1313+ # Image filter (only for newly generated content)
1314+ if any_fresh :
1315+ tqdm .write (" Running image filter pass…" )
1316+ full_notes , _ , _ = filter_images_pass (full_notes , out_dir , [ld ])
1317+ else :
1318+ tqdm .write (" Skipping image filter (all sections from cache)." )
13031319
13041320 note_path .write_text (full_notes , encoding = "utf-8" )
13051321 tqdm .write (f" Saved → { note_path } ({ len (full_notes ):,} chars)" )
0 commit comments