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: improved mediafusion validation and scrape logic #932

Merged
merged 1 commit into from
Dec 6, 2024

Conversation

mhdzumair
Copy link
Contributor

@mhdzumair mhdzumair commented Dec 6, 2024

Pull Request Check List

Resolves: #issue-number-here

  • Added tests for changed code.
  • Updated documentation for changed code.

Description:

Summary by CodeRabbit

  • New Features

    • Enhanced functionality of the Mediafusion scraper for improved user data encryption and streaming.
  • Bug Fixes

    • Improved error handling and logging for better clarity during operations.
  • Refactor

    • Updated payload structure with clearer naming conventions for better readability.
    • Streamlined URL construction and info hash handling for simplified code.

Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

Walkthrough

The changes in the Mediafusion scraper module focus on enhancing functionality and improving code readability. Key modifications include a structured initialization of rate_limit_params, clearer naming conventions in the payload for user data encryption, and refined error handling in the run method. Additionally, the scrape method has been updated to construct URLs conditionally based on scrape_type, and the handling of info_hash has been simplified by accessing stream.infoHash directly.

Changes

File Path Change Summary
src/program/services/scrapers/mediafusion.py - Improved initialization of rate_limit_params based on self.settings.ratelimit.
- Updated payload structure with clearer key names for user data encryption.
- Reformatted error handling in the run method for better readability.
- Modified URL construction in the scrape method with conditional checks for scrape_type.
- Simplified info_hash handling by accessing stream.infoHash directly.

Possibly related PRs

Suggested reviewers

  • dreulavelle
  • Gaisberg
  • davidemarcoli

🐇 "In the code where the scrapers play,
Improvements made, brightening the way.
With clearer names and structures so neat,
The Mediafusion scraper can't be beat!
Errors handled with a graceful touch,
A hop of joy, we celebrate this much!" 🌟


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>, 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 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
Contributor

@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

🧹 Outside diff range and nitpick comments (3)
src/program/services/scrapers/mediafusion.py (3)

64-79: Document configuration options

The payload configuration is well-structured, but could benefit from documentation explaining:

  • Why None is included in the resolutions list
  • The implications of empty torrent_sorting_priority
  • The available options for nudity_filter and certification_filter

Consider adding docstrings or comments explaining these configuration choices.


151-158: LGTM! Consider extracting the rate limit message constant

The rate limit check is well-implemented with proper defensive programming. Consider extracting "rate-limit exceeded" as a constant for maintainability.

+RATE_LIMIT_EXCEEDED_MESSAGE = "rate-limit exceeded"
+
 if (
     not hasattr(stream, "description")
     and hasattr(stream, "title")
-    and "rate-limit exceeded" in stream.title
+    and RATE_LIMIT_EXCEEDED_MESSAGE in stream.title
 ):

161-163: Document the series title transformation

The code splits the raw title for series, but the reasoning isn't clear. Please add a comment explaining:

  • Why this transformation is needed for series
  • What the expected format of raw_title is before/after the split
 if scrape_type == "series":
+    # Extract the main title part before the episode information
     raw_title = raw_title.split("/")[0]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 42829a2 and 3a8bdc4.

📒 Files selected for processing (1)
  • src/program/services/scrapers/mediafusion.py (6 hunks)
🔇 Additional comments (4)
src/program/services/scrapers/mediafusion.py (4)

86-92: LGTM! Clean and well-structured request handling

The request execution is well-implemented with proper parameter specification and response type handling.


122-124: LGTM! Clear and contextual error logging

The multi-line format improves readability while maintaining all necessary context.


168-170: LGTM! Improved logging format

The multi-line logging format enhances readability while providing useful metrics about found streams.


37-41: Verify the rate limit configuration

The rate limit of 1 call per 10 seconds seems quite restrictive and might impact performance. Please confirm if these values align with the service's requirements.

None,
],
"max_streams_per_resolution": 100,
"live_search_streams": True,
Copy link
Member

Choose a reason for hiding this comment

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

@mhdzumair what is live search streams?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you enable this, it will fetch the streams from mediafusion scraper with time limit. Also note that, it's not going to fetch from scrapers every time. If you disable this, mediafusion will only respond with existing db data.

description_split = stream.description.replace("📂 ", "")
raw_title = description_split.split("\n")[0]
info_hash = re.search(r"info_hash=([A-Za-z0-9]+)", stream.url).group(1)
if scrape_type == "series":
raw_title = raw_title.split("/")[0]
Copy link
Member

Choose a reason for hiding this comment

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

hmm..

In previous updates I've been pretty back and forth on this one.. Do we want the torrent or do we want the file in these scenarios.. We would prefer the torrent I think because it would have more episodes that might be needed from that same torrent.

Copy link
Member

Choose a reason for hiding this comment

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

I'll fix this one. Thanks man!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here it's providing the episode file name. If you preferred to get the episode file name, that's also fine.

Copy link
Member

@dreulavelle dreulavelle left a comment

Choose a reason for hiding this comment

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

Looks good!

@dreulavelle dreulavelle changed the title Improve MediaFusion scraping configs fix: improved mediafusion validation and scrape logic Dec 6, 2024
@dreulavelle dreulavelle merged commit eacfe06 into rivenmedia:main Dec 6, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants