feat(youtube): add support for new endpoints#11
feat(youtube): add support for new endpoints#11rafalzawadzki merged 2 commits intosupadata-ai:mainfrom
Conversation
|
💵 To receive payouts, sign up on Algora, link your Github account and connect with Stripe. |
WalkthroughThe changes add support for new YouTube endpoints in the Supadata SDK. The implementation includes methods to retrieve metadata for videos, channels, and playlists, as well as lists of video IDs from channels and playlists. The SDK’s public API is updated via new and reintroduced data types and classes. Method signatures now include type hints, and validations are in place. Updates in the README and test suite ensure documentation and coverage for the new endpoints. Changes
Sequence Diagram(s)sequenceDiagram
participant C as Client
participant YT as YouTube
participant RH as RequestHandler
C->>YT: Call video("video_id")
YT->>RH: Send API request for video metadata
RH-->>YT: Return video metadata dict
YT-->>C: Return YoutubeVideo object
Assessment against linked issues
Poem
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🧰 Additional context used🧬 Code Definitions (2)tests/test_client.py (3)
supadata/client.py (2)
🔇 Additional comments (27)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 3
🔭 Outside diff range comments (1)
supadata/youtube.py (1)
214-223:⚠️ Potential issueCorrect
_validate_limitcheck.Currently,
isinstance(limit, int)in the condition will raise an error even for valid integers. Also address the typo "amout" → "amount."if limit is None: return - elif isinstance(limit, int) or limit <= 0 or limit > 5000: + elif not isinstance(limit, int) or limit <= 0 or limit > 5000: raise SupadataError( error="invalid-request", message="Invalid limit provided", - details="You provided a limit in an invalid format or amout.", + details="You provided a limit in an invalid format or amount.", )
🧹 Nitpick comments (5)
supadata/types.py (2)
183-183: Fix typo in docstringThere's a typo in the attribute name documentation.
- subcriber_count: Number of subscribers + subscriber_count: Number of subscribers
202-202: Fix typos in docstringThere are a couple of typos in the class and attribute documentation.
- """Youtube Plalist Details + """Youtube Playlist Details - description: Plalist Description + description: Playlist DescriptionAlso applies to: 206-206
supadata/youtube.py (3)
114-126: Remove or convert the unassigned dictionary literal.A literal dictionary expression is flagged by static analysis as a no-op. Either remove it or embed it in a docstring/example if intended for illustration.
- { - "id": "pEfrdAtAmqk", - "duration": 1002, - "description": "The programming iceberg is complete roadmap to the loved, ...", - "title": "God-Tier Developer Roadmap", - "channel": {"id": "UCsBjURrPoezykLs9EqgamOA", "name": "Fireship"}, - "tags": ["#iceberg", "#learntocode", "#programming"], - "thumbnail": "https://i.ytimg.com/vi/pEfrdAtAmqk/maxresdefault.jpg", - "upload_date": "2022-08-24T00:00:00.000Z", - "view_count": 7388353, - "like_count": 262086, - "transcript_languages": ["en"], - }🧰 Tools
🪛 Ruff (0.8.2)
114-126: Found useless expression. Either assign it to a variable or remove it.
(B018)
132-142: Typographical fix in docstring.Minor spelling fix needed: "cointaining" → "containing."
- YoutubeChannel cointaining the metadata + YoutubeChannel containing the metadata
147-172: Refine docstring & remove debugging print.
- The docstring’s wording is slightly redundant.
- Consider removing or converting the
- """Get a list of the IDs of the list of video IDs from a YouTube channel.""" + """Get a list of video IDs from a YouTube channel.""" - print("Response:", response) + # print("Response:", response) # or use logging.debug(...)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
README.md(1 hunks)supadata/__init__.py(2 hunks)supadata/types.py(7 hunks)supadata/youtube.py(5 hunks)tests/test_client.py(12 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
supadata/__init__.py
20-20: supadata.types.YoutubeChannel imported but unused; consider removing, adding to __all__, or using a redundant alias
(F401)
21-21: supadata.types.YoutubePlaylist imported but unused; consider removing, adding to __all__, or using a redundant alias
(F401)
22-22: supadata.types.YoutubeVideo imported but unused; consider removing, adding to __all__, or using a redundant alias
(F401)
supadata/youtube.py
114-126: Found useless expression. Either assign it to a variable or remove it.
(B018)
🔇 Additional comments (9)
README.md (1)
68-87: Good job on the documentation updates!The new examples for YouTube functionality are clear, concise, and follow the existing documentation style. They effectively demonstrate all the new endpoints added to the SDK.
supadata/types.py (1)
131-219: Well-structured and thoroughly documented data classesThe new data classes for YouTube entities are well-designed with appropriate types and comprehensive documentation. The optional description field in YoutubePlaylist is a good approach for handling potentially missing data.
tests/test_client.py (1)
272-441: Great test coverage for new YouTube endpointsThe tests for the new YouTube functionality are well-structured and thorough. They test both successful API calls and error handling scenarios for each endpoint. The mock responses are realistic and the assertions validate all important aspects of the returned objects.
supadata/youtube.py (6)
3-14: Imports look good.No issues identified. The necessary classes and types are properly imported.
20-20: Constructor type annotations.Great job specifying the callable signature for the request handler, ensuring clarity about expected arguments and return types.
28-30: Transcript method updates.All parameter types, request parameters, and chunk handling look correct and consistent with the rest of the code.
Also applies to: 44-45, 58-60
66-67: Translate method updates.The type hints and request structure are properly aligned, and chunk transformations are handled similarly to the transcript method. No issues found.
Also applies to: 81-85, 94-96, 99-100
101-112: Newvideomethod signature and docstring.Everything appears well-structured: typed parameter and docstring are clear, raising
SupadataErrorfor failed requests.
127-129: Consider handling invalid date strings.Wrap
datetime.fromisoformat(...)in a try-except block or verification logic to prevent unhandled exceptions ifupload_dateis malformed.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
supadata/types.py (1)
144-172: Inconsistency between docstring and implementation in YoutubeVideo class.The docstring mentions a
comment_countattribute (line 157) that isn't implemented in the class. Additionally, the attributesuploaded_dateandtranscript_languagesexist in the implementation but aren't documented in the docstring."""YouTube video details. Attributes: id: YouTube video ID title: Video title description: Video description duration: Duration of video in seconds channel: A dict containing the channel ID and channel name thumbnail: The URL of the video thumbnail view_count: Number of views like_count: Number of likes - comment_count: Number of comments tags: List of video tags + uploaded_date: The date when the video was uploaded + transcript_languages: List of available transcript languages """supadata/youtube.py (1)
176-199: Consider clarifying the docstring for playlist_videos method.The method's docstring description "Get a list of the IDs of the list of video IDs" is a bit redundant and could be clearer.
- """Get a list of the IDs of the list of video IDs from a YouTube playlist. + """Get a list of video IDs from a YouTube playlist.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
supadata/types.py(7 hunks)supadata/youtube.py(5 hunks)
🔇 Additional comments (14)
supadata/types.py (6)
4-5: Import additions look good.The added imports for
datetimeand additional typing options support the new YouTube-related classes and improve type hinting.
53-73: The updated Scrape class attributes are well documented.The addition of
description,og_url, andcount_charactersattributes enhances the data model with proper type annotations and clear documentation.
88-101: Good addition of description attribute to CrawlPage class.The addition of the
descriptionattribute to the CrawlPage class is consistent with the Scrape class update and properly documented.
130-142: Well-structured TypedDict for YouTube channel base information.Using TypedDict for the channel information that will be nested in other classes is a good design pattern.
174-197: Well-structured YoutubeChannel class.The YoutubeChannel class has appropriate attributes with clear type annotations and comprehensive documentation.
199-219: YoutubePlaylist class looks good.The implementation includes all necessary attributes with appropriate types. The optional description field with a default value of None is a good design choice.
supadata/youtube.py (8)
3-14: Imports properly include the new types and required modules.The updated imports properly include the required modules and the new YouTube-related types defined in the types.py file.
20-20: Improved type annotation for request_handler.The explicit typing for the request_handler parameter enhances code clarity and API documentation.
28-30: Improved formatting and type hints for existing methods.The reformatting of the
transcriptandtranslatemethods improves readability while maintaining functionality. The explicit type hints provide better documentation.Also applies to: 66-67, 81-85
101-117: Video method implementation looks good.The method properly handles the API interaction and datetime conversion for the uploaded_date field. The method signature includes appropriate type annotations.
118-133: Channel method implementation is well structured.The implementation is straightforward and appropriate, with clear parameter and return type annotations.
134-158: Channel_videos method handles pagination correctly.The method validates the limit parameter and constructs the query parameters appropriately. The return type annotation is accurate.
159-175: Playlist method properly handles date conversion.The method correctly extracts and converts the ISO format date string to a datetime object before creating the YoutubePlaylist instance.
200-208: Robust limit validation method with clear error messages.The
_validate_limitmethod provides comprehensive validation with appropriate error messages for invalid inputs.
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (1)
tests/test_client.py (1)
485-505:⚠️ Potential issueTest for invalid playlist ID when retrieving videos
There's an inconsistency in this test. The URL in the mock and the endpoint being called don't match.
The URL in the mock points to
/youtube/playlistbut the assertion is for callingplaylist_videos. The correct endpoint should be/youtube/playlist/videos:requests_mock.get( - f"{client.base_url}/youtube/playlist?id={playlist_id}", + f"{client.base_url}/youtube/playlist/videos?id={playlist_id}", status_code=404, json=mock_response, ) with pytest.raises(SupadataError) as exc_info: - client.youtube.playlist(playlist_id) + client.youtube.playlist_videos(playlist_id)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
README.md(1 hunks)supadata/__init__.py(2 hunks)supadata/types.py(7 hunks)supadata/youtube.py(5 hunks)tests/test_client.py(12 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- supadata/init.py
🔇 Additional comments (39)
README.md (1)
68-87: Added documentation is clear and conciseThe new examples clearly demonstrate how to use the newly added YouTube endpoint functions: video metadata, channel metadata, channel videos, playlist metadata, and playlist videos. The examples follow the existing pattern and are easy to understand.
supadata/types.py (10)
4-5: Good import organizationCorrectly importing datetime and expanding the typing imports to support the new classes.
7-14: Comprehensive import listAll necessary types are imported for the new YouTube functionality while maintaining the existing imports.
56-64: Updated Scrape class docstring is completeThe docstring for the Scrape class has been properly updated to include the new fields: description, og_url, and count_characters.
70-72: New fields added to Scrape classThe new fields match what's described in the docstring and follow the existing pattern.
89-96: Updated CrawlPage class docstringThe CrawlPage docstring has been updated to include the new description attribute.
101-101: Added description field to CrawlPageThe description field has been added to the CrawlPage class as documented.
130-142: Well-structured YoutubeChannelBaseDictThe YoutubeChannelBaseDict TypedDict is well-structured and documented. It will be reused in other YouTube-related classes, which is good for consistency.
144-170: Complete YoutubeVideo class implementationThe YoutubeVideo class is well-documented with all the necessary fields for video metadata. The use of proper types for each field is excellent.
173-196: Comprehensive YoutubeChannel classThe YoutubeChannel class is well-structured with all the necessary fields for channel data, and includes proper typing.
198-218: Well-implemented YoutubePlaylist classThe YoutubePlaylist class follows the same pattern as the other YouTube classes, with proper typing and documentation. Good use of Optional for the description field that might not always be available.
tests/test_client.py (12)
3-18: Appropriate imports for new classesThe imports have been updated to include the necessary imports for the new YouTube classes: YoutubeChannel, YoutubePlaylist, and YoutubeVideo. The datetime import is added to handle date fields in these classes.
172-180: Updated test for crawl resultsAdded description field to the test to match updated CrawlPage class structure.
193-194: Updated test for second page responseProperly updated the test for the second page of crawl results to include the description field.
272-303: Comprehensive test for the video endpointThis test covers all the necessary assertions for the YoutubeVideo class, including proper conversion of date strings to datetime objects. The test uses realistic mock data that closely resembles an actual API response.
305-324: Error handling test for invalid video IDGood test for handling invalid video IDs. The test verifies that the appropriate error is raised and that the error fields are populated correctly.
326-352: Thorough test for the channel endpointThe test covers all attributes of the YoutubeChannel class and uses realistic mock data. All assertions are properly set up to verify the correct behavior.
355-374: Test for invalid channel IDProper test for handling an invalid channel ID request. It verifies that the appropriate error is raised with the correct error details.
376-399: Good playlist endpoint testThe test for the playlist endpoint is comprehensive, covering all attributes of the YoutubePlaylist class including the datetime conversion.
401-421: Proper test for invalid playlist IDThe test correctly checks error handling for invalid playlist IDs.
424-441: Test for channel videos endpointGood test for retrieving video IDs from a channel. The test verifies that the response is a list and contains the expected video IDs.
443-463: Test for invalid channel ID when retrieving videosProper test for handling an invalid channel ID when retrieving videos. It validates that the appropriate error is raised with the correct error details.
465-483: Test for playlist videos endpointGood test for retrieving video IDs from a playlist. The test verifies that the response is a list and contains the expected video IDs.
supadata/youtube.py (16)
3-14: Appropriate importsThe import statements have been updated to include the necessary imports for the new YouTube functionality. Good use of typing for function signatures.
20-20: Improved type annotation for initAdded a more specific type annotation for the request_handler parameter, which improves code readability and helps with IDE autocompletion.
28-30: Better formatting for transcript method signatureImproved the formatting of the method signature for better readability.
44-45: Clean code formattingReorganized the params dictionary creation for better readability.
58-61: Consistent code formattingImproved the formatting of the list comprehension for better readability.
66-66: Better type annotation for translate methodImproved the type annotation for the translate method parameters.
81-85: Improved request formattingReorganized the request call for better readability.
94-97: Consistent formattingImproved the formatting of the list comprehension to match the style used earlier.
101-117: Well-implemented video methodThe video method is well-implemented with proper typing, docstring, and error handling. The method correctly transforms the uploaded_date from ISO format to a datetime object.
118-133: Well-implemented channel methodThe channel method is well-implemented with proper typing, docstring, and error handling.
134-158: Well-structured channel_videos methodThe channel_videos method is well-implemented with proper typing, docstring, error handling, and parameter validation. Good use of the _validate_limit helper method.
159-175: Well-implemented playlist methodThe playlist method is well-implemented with proper typing, docstring, and error handling. The method correctly transforms the last_updated field from ISO format to a datetime object.
176-199: Good implementation of playlist_videos methodThe playlist_videos method follows the same pattern as channel_videos, with proper typing, docstring, error handling, and parameter validation.
200-208: Well-implemented _validate_limit helperThe _validate_limit helper method is properly implemented with good error handling and appropriate limit validation. The error messages are clear and informative.
114-114:Details
❓ Verification inconclusive
Potential key error in video method
The code assumes the response will always contain an "upload_date" key, but if this key is missing or named differently in the API response, it would cause a KeyError.
Consider using a more defensive approach:
- uploaded_time = datetime.fromisoformat(response.pop("upload_date")) + uploaded_time = datetime.fromisoformat(response.pop("upload_date", None) or datetime.now().isoformat())Or handle the potential KeyError explicitly:
- uploaded_time = datetime.fromisoformat(response.pop("upload_date")) + try: + uploaded_time = datetime.fromisoformat(response.pop("upload_date")) + except KeyError: + # Log warning or use a default value + uploaded_time = datetime.now()
🏁 Script executed:
#!/bin/bash # Check if the API response always includes upload_date rg -A 5 -B 5 "upload_date|uploadDate" --include "*.py"Length of output: 498
Action: Verify API Response Field and Implement Defensive Handling
After attempting to search for “upload_date” via a ripgrep command we encountered an error (incorrect use of the--includeflag). This means we haven’t yet confirmed whether the API response always provides the “upload_date” field. Without definitive evidence that the key is always present in all API responses, it’s prudent to adopt a more defensive coding approach.Suggested next steps:
- Manually verify (or re-run with a corrected command) that the API response always includes “upload_date” (or “uploadDate”) across all relevant endpoints. For example, using:
rg -A5 -B5 --glob "*.py" "upload_date|uploadDate"- Update the code in
supadata/youtube.py(around line 114) to either provide a default fallback value or explicitly catch a potentialKeyError. For example:- uploaded_time = datetime.fromisoformat(response.pop("upload_date")) + try: + uploaded_time = datetime.fromisoformat(response.pop("upload_date")) + except KeyError: + # Log warning or handle as needed (using current datetime as fallback) + uploaded_time = datetime.now()or
- uploaded_time = datetime.fromisoformat(response.pop("upload_date")) + uploaded_time = datetime.fromisoformat(response.pop("upload_date", None) or datetime.now().isoformat())Please verify these changes within the context of your API responses to ensure they handle all cases correctly.
172-172:Details
❓ Verification inconclusive
Potential key error in playlist method
Similar to the video method, there's a risk of KeyError if "last_updated" is missing from the response.
Consider using a more defensive approach:
- last_updated = datetime.fromisoformat(response.pop("last_updated")) + try: + last_updated = datetime.fromisoformat(response.pop("last_updated")) + except KeyError: + # Log warning or use a default value + last_updated = datetime.now()
🏁 Script executed:
#!/bin/bash # Check if the API response always includes last_updated rg -A 5 -B 5 "last_updated|lastUpdated" --include "*.py"Length of output: 500
Action Required: Confirm and Fix Potential KeyError in Playlist Method
There’s a risk of a KeyError in the playlist method if the API response is missing the"last_updated"key. Although we attempted to verify the presence of this key with a search, the execution error with therg --includeflag means we couldn’t conclusively determine if every API response always provides this field. Please verify the API responses manually or via an updated search (for example, using--glob "*.py"instead of--include) to ensure that the key is reliably present. In the meantime, adopting a defensive coding approach is recommended. For instance, you can update the code in supadata/youtube.py (around line 172) as follows:- last_updated = datetime.fromisoformat(response.pop("last_updated")) + try: + last_updated = datetime.fromisoformat(response.pop("last_updated")) + except KeyError: + # Log warning or use a default value + last_updated = datetime.now()Please confirm the API behavior and adjust the handling as necessary.
rafalzawadzki
left a comment
There was a problem hiding this comment.
hi @LuizDMM thanks for contributing your solution!
mostly looks good, but I have two asks:
- Asserts seem to be different from mocks in the tests. Are they correct?
- Can you add namespaces for channel and playlist so we can accomplish dot notation like with other features? eg.
channel.videosinstead ofchannel_videos
Hey @rafalzawadzki, thank you for your feedback! I'll check all the tests and the namespace and get back to you. |
Fixes supadata-ai#9 fix(project): fix the tests and fix imports on __init__.py fix(supadata): Fix small typos in docstrings fix(supadata): Fix small typo in docstring fix(tests) fix function called in test fix(youtube): create inner classes to enable dot notation
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
supadata/youtube.py (1)
214-236: Clarify the videos method docstring.The docstring for
videosmethod in the_Playlistclass has redundant wording.- """Get a list of the IDs of the list of video IDs from a YouTube playlist. + """Get a list of video IDs from a YouTube playlist.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
README.md(1 hunks)supadata/__init__.py(2 hunks)supadata/types.py(7 hunks)supadata/youtube.py(5 hunks)tests/test_client.py(12 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- README.md
- supadata/init.py
🧰 Additional context used
🧠 Learnings (1)
supadata/youtube.py (3)
Learnt from: LuizDMM
PR: supadata-ai/py#11
File: supadata/youtube.py:157-157
Timestamp: 2025-03-17T19:09:54.600Z
Learning: In the Supadata library, API responses with camelCase keys (like "videoIds") are automatically converted to snake_case (like "video_ids") by the `Supadata._camel_to_snake` method before they're processed by class methods, so using snake_case keys in the code is the correct approach.
Learnt from: LuizDMM
PR: supadata-ai/py#11
File: supadata/youtube.py:157-157
Timestamp: 2025-03-17T19:09:54.600Z
Learning: In the Supadata library, API responses with camelCase keys (like "videoIds") are converted to snake_case (like "video_ids") by the `Supadata._camel_to_snake` method before they're processed by class methods.
Learnt from: LuizDMM
PR: supadata-ai/py#11
File: supadata/youtube.py:198-198
Timestamp: 2025-03-17T19:10:13.198Z
Learning: In the Supadata client, the `_camel_to_snake` method automatically converts API response keys from camelCase to snake_case, allowing methods to access data with snake_case keys (e.g., "video_ids") even though the API returns camelCase keys (e.g., "videoIds").
🧬 Code Definitions (3)
tests/test_client.py (4)
supadata/types.py (10) (10)
CrawlJob(120-127)CrawlPage(88-101)Map(77-84)Scrape(54-73)Transcript(26-37)TranscriptChunk(9-22)TranslatedTranscript(41-50)YoutubeChannel(174-195)YoutubePlaylist(199-218)YoutubeVideo(145-170)supadata/youtube.py (7) (7)
transcript(30-65)translate(67-101)video(103-118)channel(121-125)playlist(128-132)videos(166-189)videos(214-236)supadata/web.py (1) (1)
get_crawl_results(69-107)supadata/errors.py (1) (1)
SupadataError(8-31)
supadata/types.py (1)
supadata/youtube.py (1) (1)
channel(121-125)
supadata/youtube.py (2)
supadata/types.py (6) (6)
Transcript(26-37)TranscriptChunk(9-22)TranslatedTranscript(41-50)YoutubeChannel(174-195)YoutubePlaylist(199-218)YoutubeVideo(145-170)supadata/client.py (1) (1)
_request(84-123)
🔇 Additional comments (18)
supadata/types.py (4)
129-141: Well-structured TypedDict for channel base information.This is a good foundation for reusing channel information across different types like
YoutubeVideoandYoutubePlaylist. The TypedDict approach is the right choice for this scenario.
144-171: Comprehensive video type with complete attributes.The
YoutubeVideoclass correctly captures all necessary attributes for a YouTube video, including metadata and engagement metrics. The documentation is thorough and all fields are properly typed.
173-196: Well-defined YouTube channel dataclass.The
YoutubeChannelclass has a complete set of attributes needed to represent YouTube channels. All fields have appropriate types and the documentation clearly describes each attribute.
198-219: Good implementation of playlist dataclass with optional description.The
YoutubePlaylistclass is well-structured with appropriate types. Making the description optional is a good choice, as not all playlists have descriptions.tests/test_client.py (7)
272-303: Well-structured test for YouTube video retrieval.The test thoroughly validates the
videomethod by checking the return type and verifying that all properties from the mock response are correctly mapped to the corresponding fields in theYoutubeVideoobject.
305-324: Error handling test is correctly implemented.This test properly verifies that invalid video ID requests raise a
SupadataErrorwith the appropriate error details. The difference between mock response error messages and assertions is expected due to the gateway error handling inSupadata._handle_gateway_erroras explained in previous comments.
326-353: Good test for YouTube channel retrieval.The test thoroughly validates all fields of the returned
YoutubeChannelobject against the mock response, ensuring that the channel method works as expected.
355-374: Error handling test is correctly implemented.This test properly verifies that invalid channel ID requests raise a
SupadataErrorwith the appropriate error details. As previously discussed, the difference in error details is due to the gateway error handling in the client.
376-399: Thorough test for YouTube playlist retrieval.The test effectively validates the playlist method by checking all properties of the returned
YoutubePlaylistobject, including proper handling of the datetime conversion for thelast_updatedfield.
424-441: Good test for channel videos retrieval using namespace approach.The test correctly validates the namespace-based approach for retrieving channel videos (
client.youtube.channel.videos), which aligns with rafalzawadzki's feedback in the PR comments about using dot notation for namespace access.
465-483: Good test for playlist videos retrieval using namespace approach.The test correctly validates the namespace-based approach for retrieving playlist videos (
client.youtube.playlist.videos), which follows the same pattern as the channel videos implementation, maintaining consistency.supadata/youtube.py (7)
20-20: Good addition of type hints to the constructor.Adding type hints to the
request_handlerparameter improves code documentation and provides better IDE support. TheCallable[[str, str, Any], Dict[str, Any]]type accurately describes the expected function signature.
103-118: Well-implemented video metadata retrieval.The
videomethod correctly handles the YouTube video data retrieval, including the conversion of the upload date string to a datetime object. The method has good error handling, proper type hints, and comprehensive documentation.
120-132: Good implementation of namespace properties.The
channelandplaylistproperties implement the dot notation approach as requested in the PR feedback, allowing users to access features likechannel.videosinstead of usingchannel_videos. The lazy initialization pattern used here is efficient.
134-142: Proper limit validation.The
_validate_limitmethod provides a reusable validation function for limits across different endpoints, with appropriate error messages and handling of edge cases, including None values.
144-190: Well-structured Channel class implementation.The
_Channelinner class properly encapsulates channel-related functionality, with both metadata retrieval and video listing capabilities. The use of__call__to allow direct invocation is a nice design pattern.
189-189: Consistent use of snake_case for API response keys.Using
video_idskey is correct here. As noted in the retrieved learnings, the Supadata client automatically converts camelCase keys from the API response to snake_case via the_camel_to_snakemethod, so even though the API returnsvideoIds, it will be accessible asvideo_idsin the code.
236-236: Consistent use of snake_case for API response keys.Using
video_idskey is correct here, following the same pattern as in the Channel class. The_camel_to_snakemethod handles the conversion from the API's camelCase to snake_case internally.
|
Hey @rafalzawadzki, done! Just some comments about what I've done and your questions:
Just repeating myself from above, yes, the assertion is correct. The difference between the message from the API and the one in the exception is due to We can take a look at this and modify
Sure can, I added two inner classes to I hope these changes fix everything, but just let me know if you want me to change the handler of gateway error or anything else in the PR |
|
oo good find! this is a bug - the gateway should return Can you please fix that? I'll add a bonus to this bounty to compensate your extra effort. |
Sure, on it. |
|
Done! Fixed the message and the tests to reflect the change. Just let me know if any other change is needed. |
rafalzawadzki
left a comment
There was a problem hiding this comment.
thanks @LuizDMM! lgtm 🚀
|
/tip $10 |
|
@LuizDMM: You just got a $10 tip! 👉 Complete your Algora onboarding to collect your payment. |
|
🎉🎈 @LuizDMM has been awarded $10! 🎈🎊 |

Fixes #9
/claim #9
Requirements
Implemented the support for all required endpoints, in a pythonic and typed way. Implemented tests using the content from some real requests I made and all the tests are passing.
Summary by CodeRabbit
New Features
Bug Fixes
Tests