-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: extract YouTube source URL from src[2][5] in list() and from_api_response() #267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -102,12 +102,24 @@ async def list(self, notebook_id: str) -> list[Source]: | |||||||||||||||||||||||||||||||||||||||
| src_id = src[0][0] if isinstance(src[0], list) else src[0] | ||||||||||||||||||||||||||||||||||||||||
| title = src[1] if len(src) > 1 else None | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Extract URL if present (at src[2][7]) | ||||||||||||||||||||||||||||||||||||||||
| # Extract URL if present (at src[2][7] for web/PDF, src[2][5] for YouTube) | ||||||||||||||||||||||||||||||||||||||||
| url = None | ||||||||||||||||||||||||||||||||||||||||
| if len(src) > 2 and isinstance(src[2], list) and len(src[2]) > 7: | ||||||||||||||||||||||||||||||||||||||||
| url_list = src[2][7] | ||||||||||||||||||||||||||||||||||||||||
| if isinstance(url_list, list) and len(url_list) > 0: | ||||||||||||||||||||||||||||||||||||||||
| url = url_list[0] | ||||||||||||||||||||||||||||||||||||||||
| if len(src) > 2 and isinstance(src[2], list): | ||||||||||||||||||||||||||||||||||||||||
| if len(src[2]) > 7: | ||||||||||||||||||||||||||||||||||||||||
| url_list = src[2][7] | ||||||||||||||||||||||||||||||||||||||||
| if isinstance(url_list, list) and len(url_list) > 0: | ||||||||||||||||||||||||||||||||||||||||
| url = url_list[0] | ||||||||||||||||||||||||||||||||||||||||
| if not url and len(src[2]) > 5: | ||||||||||||||||||||||||||||||||||||||||
| yt_data = src[2][5] | ||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||
| isinstance(yt_data, list) | ||||||||||||||||||||||||||||||||||||||||
| and len(yt_data) > 0 | ||||||||||||||||||||||||||||||||||||||||
| and isinstance(yt_data[0], str) | ||||||||||||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||||||||||||
| url = yt_data[0] | ||||||||||||||||||||||||||||||||||||||||
| if not url and len(src[2]) > 0: | ||||||||||||||||||||||||||||||||||||||||
| if isinstance(src[2][0], str) and src[2][0].startswith("http"): | ||||||||||||||||||||||||||||||||||||||||
| url = src[2][0] | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+108
to
+122
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The extraction logic for
Suggested change
References
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Extract timestamp from src[2][2] - [seconds, nanoseconds] | ||||||||||||||||||||||||||||||||||||||||
| created_at = None | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -582,11 +582,19 @@ def from_api_response(cls, data: list[Any], notebook_id: str | None = None) -> " | |||||||||||||||||||||||||||
| source_id = entry[0][0] if isinstance(entry[0], list) else entry[0] | ||||||||||||||||||||||||||||
| title = entry[1] if len(entry) > 1 else None | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Try to extract URL if present | ||||||||||||||||||||||||||||
| # Try to extract URL if present (web/PDF at [2][7], YouTube at [2][5]) | ||||||||||||||||||||||||||||
| url = None | ||||||||||||||||||||||||||||
| if len(entry) > 2 and isinstance(entry[2], list): | ||||||||||||||||||||||||||||
| if len(entry[2]) > 7 and isinstance(entry[2][7], list): | ||||||||||||||||||||||||||||
| url = entry[2][7][0] if entry[2][7] else None | ||||||||||||||||||||||||||||
| if not url and len(entry[2]) > 5: | ||||||||||||||||||||||||||||
| yt_data = entry[2][5] | ||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||
| isinstance(yt_data, list) | ||||||||||||||||||||||||||||
| and len(yt_data) > 0 | ||||||||||||||||||||||||||||
| and isinstance(yt_data[0], str) | ||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||
| url = yt_data[0] | ||||||||||||||||||||||||||||
|
Comment on lines
588
to
+597
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The medium-nested parsing path is missing the fallback check for
Suggested change
References
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return cls(id=str(source_id), title=title, url=url, _type_code=None) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -598,6 +606,14 @@ def from_api_response(cls, data: list[Any], notebook_id: str | None = None) -> " | |||||||||||||||||||||||||||
| url_list = entry[2][7] | ||||||||||||||||||||||||||||
| if isinstance(url_list, list) and len(url_list) > 0: | ||||||||||||||||||||||||||||
| url = url_list[0] | ||||||||||||||||||||||||||||
| if not url and len(entry[2]) > 5: | ||||||||||||||||||||||||||||
| yt_data = entry[2][5] | ||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||
| isinstance(yt_data, list) | ||||||||||||||||||||||||||||
| and len(yt_data) > 0 | ||||||||||||||||||||||||||||
| and isinstance(yt_data[0], str) | ||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||
| url = yt_data[0] | ||||||||||||||||||||||||||||
| if not url and len(entry[2]) > 0: | ||||||||||||||||||||||||||||
| if isinstance(entry[2][0], str) and entry[2][0].startswith("http"): | ||||||||||||||||||||||||||||
| url = entry[2][0] | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate index-7 URL element type before assignment
At Line 110,
url_list[0]is accepted without a string check. A malformed payload can set a non-string URL and bypass the fallback chain.Proposed patch
🤖 Prompt for AI Agents