fix: extract YouTube source URLs from index [2][5]#283
fix: extract YouTube source URLs from index [2][5]#283MCR-GLOBAL wants to merge 1 commit intoteng-lin:mainfrom
Conversation
YouTube sources store URL data at src[2][5] as [url, video_id, channel] while src[2][7] is null. Previously only [2][7] was checked, causing Source.url to always be None for YouTube sources. Adds YouTube URL fallback in all three extraction paths: list(), and both nested formats in Source.from_api_response(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis PR fixes YouTube source URL extraction in the NotebookLM API client by implementing multi-location fallback logic. The changes add checks for YouTube URLs at Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request updates the URL extraction logic for sources to accommodate different API response structures, specifically adding support for YouTube URLs and a fallback for HTTP links. Corresponding unit and integration tests have been included to verify the new extraction paths. I have no feedback to provide as there were no review comments to evaluate.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/unit/test_types.py (1)
164-198: Add a medium-nested companion case for the samesrc[2][5]fallback.This test covers the deeply nested branch well; adding one medium-nested case would guard both parsing branches in
Source.from_api_response()against future regressions.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/unit/test_types.py` around lines 164 - 198, Add a medium-nested companion test for the same src[2][5] fallback: create a new test (e.g., test_from_api_response_youtube_source_url_at_index5_medium_nesting) that builds a slightly different nesting shape which still places the YouTube tuple at index [2][5] of the source payload, call Source.from_api_response(...) and assert source.id == "src_yt2", source.url == "https://www.youtube.com/watch?v=dcWU-qD8ISQ" and source.kind == SourceType.YOUTUBE; this ensures Source.from_api_response handles both the deep and medium nesting branches.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/unit/test_types.py`:
- Around line 164-198: Add a medium-nested companion test for the same src[2][5]
fallback: create a new test (e.g.,
test_from_api_response_youtube_source_url_at_index5_medium_nesting) that builds
a slightly different nesting shape which still places the YouTube tuple at index
[2][5] of the source payload, call Source.from_api_response(...) and assert
source.id == "src_yt2", source.url ==
"https://www.youtube.com/watch?v=dcWU-qD8ISQ" and source.kind ==
SourceType.YOUTUBE; this ensures Source.from_api_response handles both the deep
and medium nesting branches.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 727bebb4-3f02-46c4-b779-1e6f46fdace3
📒 Files selected for processing (4)
src/notebooklm/_sources.pysrc/notebooklm/types.pytests/integration/test_sources.pytests/unit/test_types.py
Summary
Source.urlis alwaysNonefor YouTube sourcessrc[2][5]as[url, video_id, channel_name]whilesrc[2][7]isnull[2][5]) in all three extraction paths:SourcesAPI.list(), and both nested formats inSource.from_api_response()Test plan
test_from_api_response_youtube_source_url_at_index5— verifies deeply nested YouTube URL extractiontest_list_sources_youtube_url_at_index5— verifieslist()extracts YouTube URL fromsrc[2][5][7]path unchanged)🤖 Generated with Claude Code
Summary by CodeRabbit