Ali Hashhash commited on
Commit
9f6836e
·
1 Parent(s): 2c06845

feat: add notes_routes.py with robust YouTube duration scraping and background task processing for note generation

Browse files
Files changed (1) hide show
  1. src/api/notes_routes.py +6 -6
src/api/notes_routes.py CHANGED
@@ -305,10 +305,10 @@ async def process_video_task(task_id: str, youtube_url: str, language: str, user
305
  if isinstance(seg, dict) and seg.get("key_insight"):
306
  key_points_list.append(seg["key_insight"])
307
 
308
- # Step 2: Generate the single primary category (keep in memory)
309
- from src.summarization.topic_classifier import get_primary_category
310
  raw_topics = summary_json.get("topics", [])
311
- category = get_primary_category(raw_topics) if raw_topics else "Education & Science"
312
 
313
  # Step 3: Combine everything into ONE single dictionary
314
  note_data = {
@@ -317,7 +317,7 @@ async def process_video_task(task_id: str, youtube_url: str, language: str, user
317
  "videoTitle": video_title,
318
  "notes": final_markdown,
319
  "thumbnail": f"https://img.youtube.com/vi/{video_id}/mqdefault.jpg" if video_id else "",
320
- "category": category,
321
  "keyPoints": key_points_list,
322
  "createdAt": datetime.utcnow(),
323
  "updatedAt": datetime.utcnow(),
@@ -328,8 +328,8 @@ async def process_video_task(task_id: str, youtube_url: str, language: str, user
328
  # The Flutter app will perform the final save after user edits.
329
  tasks[task_id]["status"] = "completed"
330
  tasks[task_id]["notes"] = final_markdown
331
- tasks[task_id]["topics"] = raw_topics
332
- tasks[task_id]["category"] = category
333
  tasks[task_id]["keyPoints"] = key_points_list
334
  logger.info(f"✅ Task {task_id} completed successfully!")
335
 
 
305
  if isinstance(seg, dict) and seg.get("key_insight"):
306
  key_points_list.append(seg["key_insight"])
307
 
308
+ # Step 2: Generate the categories (keep in memory)
309
+ from src.summarization.topic_classifier import classify_topics
310
  raw_topics = summary_json.get("topics", [])
311
+ categories = classify_topics(raw_topics) if raw_topics else ["Education & Science"]
312
 
313
  # Step 3: Combine everything into ONE single dictionary
314
  note_data = {
 
317
  "videoTitle": video_title,
318
  "notes": final_markdown,
319
  "thumbnail": f"https://img.youtube.com/vi/{video_id}/mqdefault.jpg" if video_id else "",
320
+ "category": categories,
321
  "keyPoints": key_points_list,
322
  "createdAt": datetime.utcnow(),
323
  "updatedAt": datetime.utcnow(),
 
328
  # The Flutter app will perform the final save after user edits.
329
  tasks[task_id]["status"] = "completed"
330
  tasks[task_id]["notes"] = final_markdown
331
+ tasks[task_id]["topics"] = categories
332
+ tasks[task_id]["category"] = categories
333
  tasks[task_id]["keyPoints"] = key_points_list
334
  logger.info(f"✅ Task {task_id} completed successfully!")
335