twikit icon indicating copy to clipboard operation
twikit copied to clipboard

Add configurable API URL support for Capsolver captcha solver

Open izzzzzi opened this issue 9 months ago • 8 comments

Add support for custom API endpoints in Capsolver

This commit enhances the Capsolver class by adding support for custom API endpoints. Users can now specify an alternative API URL when initializing the Capsolver instance, allowing for greater flexibility when working with different Capsolver API providers or self-hosted solutions.

Key changes:

  • Added a new api_url parameter to the Capsolver constructor with a default value of 'https://api.capsolver.com'
  • Updated the documentation to reflect the new parameter
  • Modified the create_task and get_task_result methods to use the custom API URL
  • Added trailing slash handling to ensure proper URL formatting

Example usage:

# Standard API
solver = Capsolver(api_key='your_api_key')

# Custom API endpoint
solver = Capsolver(
    api_key='your_api_key',
    api_url='https://custom-api.capsolver.com'
)

Summary by Sourcery

New Features:

  • Add the ability to configure the Capsolver API URL.

Summary by CodeRabbit

  • New Features
    • Enabled users to specify a custom CAPTCHA service endpoint instead of relying solely on the default address.
    • Improved consistency in endpoint formatting for a more reliable integration experience.

izzzzzi avatar Mar 09 '25 00:03 izzzzzi

Reviewer's Guide by Sourcery

This pull request introduces the ability to configure the base URL for the Capsolver API. A new api_url parameter has been added to the Capsolver class constructor, allowing users to specify a custom API endpoint. The create_task and get_task_result methods have been updated to use the configured api_url. Trailing slash handling was added to ensure proper URL formatting.

Sequence diagram for get_task_result with custom API URL

sequenceDiagram
    participant User
    participant Capsolver
    participant Custom API

    User->>Capsolver: get_task_result(task_id)
    Capsolver->>Custom API: POST /getTaskResult with task_id
    Custom API-->>Capsolver: Response (solution or status)
    Capsolver-->>User: Response (solution or status)

File-Level Changes

Change Details Files
Added the ability to configure the base URL for the Capsolver API.
  • Added an api_url parameter to the Capsolver class constructor.
  • Set the default value of api_url to 'https://api.capsolver.com'.
  • Updated the create_task method to use the configured api_url.
  • Updated the get_task_result method to use the configured api_url.
  • Added trailing slash removal from the api_url to ensure proper URL formatting.
twikit/_captcha/capsolver.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an issue from a review comment by replying to it. You can also reply to a review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull request title to generate a title at any time. You can also comment @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment @sourcery-ai summary on the pull request to (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Mar 09 '25 00:03 sourcery-ai[bot]

Walkthrough

The update in twikit/_captcha/capsolver.py introduces a new parameter, api_url, in the Capsolver class. The parameter is added to the constructor signature and the class documentation, with a default value of 'https://api.capsolver.com'. Trailing slashes in the provided URL are removed upon initialization. Both the create_task and get_task_result methods now build their endpoint URLs dynamically using the api_url value instead of relying on hardcoded URLs.

Changes

File Changes
twikit/_captcha/capsolver.py - Added new api_url parameter to Capsolver constructor (default: 'https://api.capsolver.com')
- Updated class docstring to include API URL info
- Modified create_task and get_task_result methods to utilize api_url instead of hardcoded endpoints
- Implemented trailing slash removal in initialization

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant C as Capsolver
    participant A as API Server

    U->>C: Initialize Capsolver(api_url)
    U->>C: Call create_task(parameters)
    C->>A: POST {api_url}/create_task
    A-->>C: Respond with task_id
    U->>C: Call get_task_result(task_id)
    C->>A: GET {api_url}/get_task_result with task_id
    A-->>C: Respond with task result
    C-->>U: Return task result

Poem

Hopping through the code so light,
I’ve tweaked the URLs just right.
With a dash of slash removed,
My API calls are smoothly approved.
A rabbit’s hop in every byte, so bright!
🐇💻

✨ 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 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.

coderabbitai[bot] avatar Mar 09 '25 00:03 coderabbitai[bot]

@izzzzzi Напиши в телеграм плиз: @unstable6

TimurKutsenko avatar Mar 24 '25 14:03 TimurKutsenko

@izzzzzi Приветствую, добавляя api_url - вы желаете дать пользователям возможность втыкать свои апи? Если так,то на каждом(почти) каптча сервисе роуты,аргументы разные.Если вы желаете для создания локальных апи - capsolver не предоставляет таких возможностей

dwqekc avatar Apr 20 '25 15:04 dwqekc

@dwqekc я использую 3-4 сервиса для решения капчи и у всех апи идентичное

izzzzzi avatar Apr 24 '25 12:04 izzzzzi

@dwqekc я использую 3-4 сервиса для решения капчи и у всех апи идентичное

для поддержания объектирования либо делай абстракции либо реализации под все нужны тебе сервисы

dwqekc avatar Apr 24 '25 14:04 dwqekc

ну или блин просто форк свой поддерживай)),тут мержи не быстро принимают)))))

dwqekc avatar Apr 24 '25 14:04 dwqekc

но кстати, абстракции - тут мастхев можно в будущем di сделать короче более правильный чем щас обычно пихают))

Верхние уровни не будут знать о низших из за конечной реализации абстракции

dwqekc avatar Apr 24 '25 14:04 dwqekc