@@ -91,16 +91,34 @@ def _enumerate_lectures(client: ICourseClient, db: Database,
9191
9292 # School system sometimes lists duplicate lectures; dedup the
9393 # raw list so the same logic produces the same outcome each run.
94- seen_sub_titles : set [str ] = set ()
94+ # When a sub_title appears more than once, keep the first one
95+ # that has playback; if none have playback, keep the first.
96+ seen_sub_titles : dict [str , dict ] = {}
9597 deduped = []
9698 for lec in lectures :
9799 title = lec .get ("sub_title" , "" )
98- if title and title in seen_sub_titles :
99- reporter . course_dedup_skip ( title , lec [ "sub_id" ] )
100+ if not title :
101+ deduped . append ( lec )
100102 continue
101- if title :
102- seen_sub_titles .add (title )
103- deduped .append (lec )
103+ existing = seen_sub_titles .get (title )
104+ if existing is None :
105+ # first occurrence — if it has playback, keep it;
106+ # otherwise tentatively store it and look for a
107+ # playback-capable duplicate.
108+ if lec .get ("has_playback" ):
109+ seen_sub_titles [title ] = lec
110+ deduped .append (lec )
111+ else :
112+ seen_sub_titles [title ] = lec
113+ deduped .append (lec )
114+ elif not existing .get ("has_playback" ) and lec .get ("has_playback" ):
115+ # replace the earlier no-playback entry with this one
116+ deduped .remove (existing )
117+ seen_sub_titles [title ] = lec
118+ deduped .append (lec )
119+ reporter .course_dedup_skip (title , existing ["sub_id" ])
120+ else :
121+ reporter .course_dedup_skip (title , lec ["sub_id" ])
104122 lectures = deduped
105123
106124 known_processed = db .get_processed_sub_ids (course_id )
0 commit comments