Skip to content
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

fix/videos #3

Merged
merged 2 commits into from
Sep 4, 2024
Merged

fix/videos #3

merged 2 commits into from
Sep 4, 2024

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Sep 4, 2024

port pytube/pytube#1422

Summary by CodeRabbit

  • New Features

    • Introduced a property to check if a video is live.
    • Added new properties and methods for retrieving videos, shorts, and live streams from YouTube channels.
    • Enhanced channel class functionality with dynamic HTML URL handling and improved video extraction.
  • Bug Fixes

    • Improved URL formatting for channel names containing the "@" symbol.

@JarbasAl JarbasAl added the bug Something isn't working label Sep 4, 2024
Copy link

coderabbitai bot commented Sep 4, 2024

Walkthrough

The changes introduce new properties and methods to the Video and Channel classes in the pytube library, enhancing the ability to retrieve and manage video content, including live streams and shorts. Additionally, the channel_name function in extract.py is modified to improve URL formatting for channels with "@" symbols. These updates collectively enhance the functionality and usability of the library.

Changes

Files Change Summary
tutubo/pytube/__main__.py Added a new property is_live to the Video class to determine if a video is live based on its length.
tutubo/pytube/contrib/channel.py Introduced new properties (html_url, videos, shorts, live) in the Channel class for better content retrieval. Modified _extract_videos method to handle new JSON structure and updated metadata properties to set html_url.
tutubo/pytube/extract.py Modified the channel_name function to handle URLs with "@" symbols, changing how certain channel names are formatted.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Channel
    participant Video
    participant Extract

    User->>Channel: Request channel data
    Channel->>Channel: Fetch videos, shorts, live streams
    Channel->>Video: Check if video is live
    Video-->>Channel: Return live status
    Channel-->>User: Return channel content
Loading

🐰 In a world of streams and shorts so bright,
I hop with joy, oh what a sight!
Live videos now, just a hop away,
With channels and content, come join the play!
For every click, a new delight,
Celebrate the changes, oh what a night! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 resolve resolve all the CodeRabbit review comments.
  • @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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0828aad and 9db9d3e.

Files selected for processing (3)
  • tutubo/pytube/main.py (1 hunks)
  • tutubo/pytube/contrib/channel.py (7 hunks)
  • tutubo/pytube/extract.py (1 hunks)
Additional comments not posted (14)
tutubo/pytube/__main__.py (1)

383-385: LGTM!

The newly added is_live property method in the Video class looks good:

  • It correctly returns a boolean value indicating whether the video is live by checking if the length of the video is equal to zero.
  • The length property is derived from the vid_info dictionary.
  • The addition of this property expands the interface of the class to include live video detection without altering existing methods.

The code changes are approved.

tutubo/pytube/extract.py (1)

181-183: Verify the impact of the changes on the codebase.

The changes introduce a new conditional check to handle URLs with "@" symbols. If the URL contains "@", the function immediately returns a formatted string with the uri_identifier prefixed by "/@". This could impact how channel names are processed in the application.

Run the following script to verify the usage of channel_name function:

Verification successful

Changes verified successfully.

The changes to the channel_name function, which handle URLs with "@" symbols, have been verified. The function is used in tutubo/pytube/contrib/channel.py, and the returned value is directly used to construct a channel URL. There are no additional handling or processing of "/@" prefixed channel names, indicating that the change is self-contained and does not impact other parts of the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `channel_name` function in the codebase.

# Test 1: Search for the function calls. Expect: Occurrences of the function being called with URLs containing "@" symbol.
rg --type python -A 5 $'channel_name\('

# Test 2: Search for the usage of the returned value. Expect: Code handling the "/@" prefixed channel names.
rg --type python -A 5 $'\/@'

Length of output: 171


Script:

#!/bin/bash
# Description: Verify the usage of `channel_name` function in the codebase.

# Test 1: Search for the function calls. Expect: Occurrences of the function being called with URLs containing "@" symbol.
rg --type py -A 5 'channel_name\('

# Test 2: Search for the usage of the returned value. Expect: Code handling the "/@" prefixed channel names.
rg --type py -A 5 '/@'

Length of output: 2235

tutubo/pytube/contrib/channel.py (12)

77-94: LGTM!

The new html_url property looks good:

  • It provides easy access and modification of the _html_url attribute.
  • The setter clears the cache when the _html_url attribute is updated, ensuring that the cached data is consistent with the new URL.

163-196: LGTM!

The new _build_continuation_url method looks good:

  • It is well-documented with a clear description of its purpose and return value.
  • It encapsulates the logic for constructing the URL, headers, and data required for pagination, making it reusable and maintainable.
  • It uses the yt_api_key attribute to construct the URL, ensuring that the correct API key is used.
  • It includes the necessary headers and data for the request.

Line range hint 197-270: LGTM!

The modifications to the _extract_videos method look good:

  • It handles the new JSON structure for videos, shorts, and streams, ensuring that the correct data is extracted.
  • It extracts the visitor data and stores it in the _visitor_data attribute, which is required for sending the continuation token.
  • It handles the case where the JSON is directly sent by the server in a continuation response, ensuring that the data is extracted correctly.
  • It extracts the video IDs from the video data and returns them along with the continuation token, making it easy to retrieve the next page of videos.

271-293: LGTM!

The modifications to the views property look good:

  • It sets the html_url attribute to the about_url attribute to retrieve the "about" tab data, ensuring that the correct data is extracted.
  • It extracts the position of the "about" tab from the initial data, making it more reliable and maintainable.
  • It extracts the view count text from the "about" tab data and converts it to an integer, providing a convenient way to retrieve the view count.
  • It returns 0 if the view count text is not found, handling the case where the data is not available.

294-304: LGTM!

The modification to the title property looks good:

  • It sets the html_url attribute to the channel_url attribute before extracting the channel title, ensuring that the correct data is extracted.

305-314: LGTM!

The modification to the description property looks good:

  • It sets the html_url attribute to the channel_url attribute before extracting the channel description, ensuring that the correct data is extracted.

315-324: LGTM!

The modification to the length property looks good:

  • It sets the html_url attribute to the channel_url attribute before extracting the channel videos count, ensuring that the correct data is extracted.

325-341: LGTM!

The modification to the last_updated property looks good:

  • It sets the html_url attribute to the videos_url attribute before extracting the date of the last uploaded video, ensuring that the correct data is extracted.
  • It returns None if the last updated text is not found, handling the case where the data is not available.

342-350: LGTM!

The modification to the thumbnail_url property looks good:

  • It sets the html_url attribute to the channel_url attribute before extracting the channel thumbnail URL, ensuring that the correct data is extracted.

454-463: LGTM!

The modification to the videos property looks good:

  • It sets the html_url attribute to the videos_url attribute before yielding YouTube objects of videos in the channel, ensuring that the correct data is extracted.

464-473: LGTM!

The new shorts property looks good:

  • It sets the html_url attribute to the shorts_url attribute before yielding YouTube objects of short videos in the channel, ensuring that the correct data is extracted.

474-483: LGTM!

The new live property looks good:

  • It sets the html_url attribute to the live_url attribute before yielding YouTube objects of live streams in the channel, ensuring that the correct data is extracted.

@JarbasAl JarbasAl merged commit fcae460 into dev Sep 4, 2024
1 check passed
@JarbasAl JarbasAl deleted the fix/videos branch September 4, 2024 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant