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

Fixed Zamunda provider search #8819

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

joncevski
Copy link
Contributor

@joncevski joncevski commented Feb 23, 2025

Fixes #
The search for the Zamunda provider was not working.

Proposed changes in this pull request:

  • added pattern for the search format

  • reformatted the logging instances

  • added wait for 2 seconds to prevent Flood Protection when searching for multiple episodes.

  • PR is based on the DEVELOP branch

  • Don't send big changes all at once. Split up big PRs into multiple smaller PRs that are easier to manage and review

  • Read contribution guide

Summary by CodeRabbit

  • New Features
    • Introduced a brief delay during search operations to help mitigate flooding issues and ensure smoother performance.
  • Refactor
    • Streamlined logging messages and enhanced error handling to provide clearer, more user-friendly feedback.

Copy link
Contributor

coderabbitai bot commented Feb 23, 2025

Walkthrough

The changes update the zamunda.py provider by simplifying logging in both the login and search methods, removing translation wrappers and using f-strings. A new regular expression pattern is introduced as a class attribute to search for a specific HTML table using re.search instead of a try-except block. Additionally, the time module is imported and a two-second delay is added in the search method to mitigate flood protection.

Changes

File Summary
sickchill/oldbeard/providers/zamunda.py Updated logging messages (removed translation wrappers and reformatted with f-strings), introduced a new regex pattern (self.pattern), swapped index() for re.search, added time import and a time.sleep(2) delay for flood protection.

Sequence Diagram(s)

sequenceDiagram
    participant C as Caller
    participant P as Provider
    C->>P: call search()
    alt HTML table found via regex
        P->>P: Process search results & log info
    else HTML table not found
        P->>P: Log debug message (table not found)
    end
    P->>P: Execute time.sleep(2) (delay for flood protection)
    P->>C: Return search results
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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: 1

🧹 Nitpick comments (1)
sickchill/oldbeard/providers/zamunda.py (1)

35-35: Consider making the table pattern more specific.

While the pattern will match the target table, it could be more specific to ensure robustness against future HTML changes.

-        self.pattern = r'<table[^>]*id=["\']zbtable["\'][^>]*>'
+        self.pattern = r'<table[^>]*(?:class="[^"]*responsivetable[^"]*"|id="zbtable")[^>]*>'
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 59ed527 and a04f9a4.

📒 Files selected for processing (1)
  • sickchill/oldbeard/providers/zamunda.py (7 hunks)
🔇 Additional comments (4)
sickchill/oldbeard/providers/zamunda.py (4)

2-2: LGTM!

The time module import is correctly added to support the flood protection delay.


55-55: LGTM!

The logging messages have been simplified while maintaining clarity and consistency.

Also applies to: 62-62, 66-66


83-83: LGTM!

The logging messages have been modernized using f-strings, improving readability while maintaining the same information.

Also applies to: 86-86, 90-90, 94-94, 104-104, 111-111, 120-120, 150-150


100-105: LGTM!

The table search logic has been improved by:

  • Using explicit pattern matching instead of try-except
  • Adding proper error handling with debug logging

Comment on lines 161 to 162
logger.debug("Waiting to prevent flood protection...")
time.sleep(2)
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider improving the flood protection mechanism.

The current implementation has two potential issues:

  1. The 2-second delay might be insufficient for some scenarios
  2. The delay at the end of the search won't help prevent flood protection during the search loop

Consider moving the delay inside the search loop and making the delay time configurable.

             for search_string in {*search_strings[mode]}:
+                logger.debug("Waiting to prevent flood protection...")
+                time.sleep(self.flood_protection_delay)  # Add this as a configurable class attribute
                 search_url = self.urls["search"] % quote_plus(search_string) + self.categories
                 logger.debug(f"Search String: {search_string}")

                 data = self.get_url(search_url, returns="text")
-        logger.debug("Waiting to prevent flood protection...")
-        time.sleep(2)

Also, add the delay configuration in __init__:

def __init__(self):
    super().__init__("Zamunda")
    self.flood_protection_delay = 2  # seconds

@BKSteve
Copy link
Collaborator

BKSteve commented Feb 28, 2025

Cutting out all the logger prefix _ removes the detail of the call DEBUG :: SEARCHQUEUE-DAILY-SEARCH :: [Zamunda] ::

-           logger.warning(_("Unable to connect to provider"))
+           logger.warning("Unable to connect to provider")

Also f strings aren't used and old style format is as this puts the data when using combining function of _ as above.

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