Skip to content

Conversation

neo773
Copy link
Contributor

@neo773 neo773 commented Apr 2, 2025

a.mp4

/claim #12
/closes #12

Summary by CodeRabbit

  • New Features

    • Improved video retrieval functionality allows users to specify video types (e.g., all, video, or short) and control the number of results returned.
    • The output now clearly distinguishes between regular videos and YouTube Shorts for enhanced clarity.
  • Tests

    • Expanded test coverage ensures that video retrieval handles both regular videos and Shorts correctly.

@algora-pbc algora-pbc bot mentioned this pull request Apr 2, 2025
4 tasks
Copy link

coderabbitai bot commented Apr 2, 2025

Walkthrough

This pull request modifies the YouTube video retrieval functionality. The changes update the method signatures for fetching channel and playlist videos by adding a type parameter (for channels) and a limit parameter. A new data class, VideoIds, is introduced to encapsulate regular video and Shorts IDs. In parallel, the README and test cases are updated to reflect these interface changes and validate that video IDs and Shorts are returned separately.

Changes

Files Changed Change Summary
README.md Updated usage examples to include type (with values "all", "video", "short") and limit parameters; output examples now list regular videos and Shorts separately.
supadata/types.py, supadata/youtube.py Introduced new VideoIds data class to encapsulate video_ids and short_ids; updated _Channel.videos and _Playlist.videos methods to include new parameters and return a VideoIds object instead of a list.
tests/test_client.py Enhanced test cases to validate the new response format (separate video_ids and short_ids); added a dedicated test (test_youtube_channel_videos_with_type) to verify functionality when the type parameter is specified.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant CH as _Channel.videos
    participant API as YouTube API

    C->>CH: Call videos(id, limit, type)
    CH->>API: Send request with id, limit, type
    API-->>CH: Return response {videoIds, shortIds}
    CH->>C: Return VideoIds {video_ids, short_ids}
Loading
sequenceDiagram
    participant C as Client
    participant PL as _Playlist.videos
    participant API as YouTube API

    C->>PL: Call videos(id, limit)
    PL->>API: Send request with id, limit
    API-->>PL: Return response {videoIds, shortIds}
    PL->>C: Return VideoIds {video_ids, short_ids}
Loading

Assessment against linked issues

Objective Addressed Explanation
Support for type param in /youtube/channel/videos (#12)
Return types for channel/playlist videos updated to return an object (#12)
README update for type and response format (#12)
Updated test cases to validate separation of video and short IDs (#12)

Possibly related PRs

Suggested labels

🙋 Bounty claim

Suggested reviewers

  • rafalzawadzki

Poem

Oh, hops and bounds in code so neat,
With channels and playlists now complete.
Video IDs and Shorts split with glee,
A rabbit's dance of clarity.
Hop along, the changes are sweet! 🐇🎉

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
supadata/youtube.py (1)

317-347: 🛠️ Refactor suggestion

Playlist videos method should also support the type parameter

The videos method for playlists has been updated to return a VideoIds object, but unlike the channel method, it doesn't include the type parameter. For consistency, consider adding the same type filtering capability to playlists.

def videos(
    self, 
    id: str, 
    limit: Optional[int] = None
+   type: Literal["all", "video", "short"] = "all"
) -> VideoIds:
    """Get video IDs from a YouTube playlist.

    Args:
        id: YouTube Playlist ID
        limit: The limit of videos to be returned. None will
            return the default (30 videos)
+       type: The type of videos to fetch.
+           'all': Both regular videos and shorts (default)
+           'video': Only regular videos
+           'short': Only shorts

    Returns:
        VideoIds object containing lists of video IDs and short IDs

    Raises:
        SupadataError: If the API request fails
    """
    self._youtube._validate_limit(limit)
-   query_params = {"id": id}
+   query_params = {"id": id, "type": type}
    if limit:
        query_params["limit"] = limit
🧹 Nitpick comments (1)
README.md (1)

90-96: Playlist videos example missing the type parameter

The playlist videos example has been updated to include the limit parameter and show the new output format for both regular videos and shorts. However, it's missing the type parameter which should be added for consistency with the channel videos example.

# Get video IDs from a YouTube playlist
playlist_videos = supadata.youtube.playlist.videos(
    id="https://www.youtube.com/playlist?list=PLlaN88a7y2_plecYoJxvRFTLHVbIVAOoc",  # can be url or playlist id
+   type="all",  # 'all', 'video', or 'short'
    limit=50
)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2997ed0 and 3d00961.

📒 Files selected for processing (4)
  • README.md (1 hunks)
  • supadata/types.py (1 hunks)
  • supadata/youtube.py (5 hunks)
  • tests/test_client.py (4 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
supadata/youtube.py (2)
supadata/types.py (1)
  • VideoIds (260-275)
supadata/client.py (1)
  • _request (85-124)
tests/test_client.py (2)
supadata/youtube.py (3)
  • channel (173-177)
  • videos (235-270)
  • videos (317-347)
supadata/client.py (1)
  • Supadata (13-124)
🪛 Ruff (0.8.2)
supadata/youtube.py

4-4: typing.List imported but unused

Remove unused import: typing.List

(F401)

🔇 Additional comments (8)
supadata/types.py (1)

258-275: New data class looks good and follows existing patterns

The VideoIds class is well-designed to separate regular YouTube videos from Shorts, with appropriate defaults handling in __post_init__. The class documentation clearly explains its purpose and attributes.

tests/test_client.py (4)

430-450: Tests properly updated to handle new VideoIds return type

The test has been properly updated to check the new VideoIds structure, verifying both regular videos and shorts IDs are correctly retrieved and accessible through their respective attributes.


452-474: Good addition of type-specific test case

Adding a specific test for retrieving videos with type="video" ensures the type filtering parameter works correctly. The test correctly verifies that when using this filter, the short_ids list is empty.


485-485: Test URL correctly updated for type parameter

The mock URL in the error test case has been updated to include the new type=all parameter, maintaining consistency with the implementation.


505-526: Playlist video test correctly updated for new return type

The playlist video test has been properly updated to check for the new VideoIds structure, verifying both the video_ids and short_ids attributes.

supadata/youtube.py (2)

14-14: Good addition of VideoIds import

The import for the new VideoIds type has been correctly added to the imports from types.py.


235-270: Channel videos method updated with good support for different video types

The videos method has been enhanced to:

  1. Support filtering by video type (all, video, short)
  2. Return a structured VideoIds object instead of a flat list
  3. Include proper docstring updates explaining the new parameter

The implementation correctly uses the type parameter in the API request and parses the response into the new VideoIds structure.

README.md (1)

77-85: README updated with clear examples for channel videos

The example for retrieving channel videos has been updated with the new parameters and output format, clearly showing how to get both regular videos and shorts.


from datetime import datetime
from typing import Any, Callable, Dict, List
from typing import Any, Callable, Dict, List, Optional, Literal
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Import statement includes unused List type

The List type is imported but marked as unused by Ruff. However, it appears to be used in type annotations throughout the file, particularly in the new VideoIds return type.


🏁 Script executed:

#!/bin/bash
# Check if List is actually used in type annotations
grep -n "List\[" supadata/youtube.py

Length of output: 38


I'm going to run an additional shell script to search for any occurrences of both "VideoIds" and the generic usage of List in the file. This will help confirm whether List is indeed used in type annotations, as mentioned in the review comment.

Please run these commands and review the output. If the results show no usage of List in type annotations (or in any form), then the import is truly unused and should be removed. Otherwise, if there is usage that might not include the typical generic pattern (for example, if a type alias like VideoIds = List[str] exists), please verify that usage and consider updating the code or the review comment accordingly.


Action: Verify usage of the imported List in supadata/youtube.py

  • The current import statement on line 4 in supadata/youtube.py includes List but automated linting (via Ruff) marks it as unused.
  • Our initial grep -n "List\[" produced no results.
  • Please check the new script outputs:
    • If neither VideoIds nor any instance of List (as a whole word) is found in the file, it indicates that List is not used. In that case, removing the import should be the next step.
    • If there is indeed usage (possibly a declaration like VideoIds = List[str]), we need to update the import or adjust the usage so that Ruff no longer flags it as unused.

🏁 Script executed:

#!/bin/bash
echo "Searching for 'VideoIds' in supadata/youtube.py:"
grep -n "VideoIds" supadata/youtube.py

echo "Searching for generic 'List' usage (matching whole word) in supadata/youtube.py:"
grep -n "\bList\b" supadata/youtube.py

Length of output: 854


Actionable: Remove unused List import

After verifying with our grep commands, it’s clear that the List type appears only in the import statement (line 4) in supadata/youtube.py and is not otherwise used in any type annotations—even in the VideoIds return type. Please confirm whether VideoIds should leverage a generic list. If not, remove List from the import to satisfy Ruff.

  • File: supadata/youtube.py, Line: 4 – Remove List from the import statement.
🧰 Tools
🪛 Ruff (0.8.2)

4-4: typing.List imported but unused

Remove unused import: typing.List

(F401)

@neo773
Copy link
Contributor Author

neo773 commented Apr 4, 2025

@rafalzawadzki
Could I get a review on this?

@rafalzawadzki
Copy link
Contributor

@rafalzawadzki Could I get a review on this?

sorry for the delay! will try to get it done this weekend

@rafalzawadzki rafalzawadzki merged commit 351fa6e into supadata-ai:main Apr 6, 2025
1 check passed
@rafalzawadzki
Copy link
Contributor

great work! done ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Shorts
2 participants