Add configurable API URL support for Capsolver captcha solver
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_urlparameter to the Capsolver constructor with a default value of 'https://api.capsolver.com' - Updated the documentation to reflect the new parameter
- Modified the
create_taskandget_task_resultmethods 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.
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. |
|
twikit/_captcha/capsolver.py |
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon 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 issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon 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 dismisson 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 reviewto trigger a new review! - Generate a plan of action for an issue: Comment
@sourcery-ai planon 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.
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.
🪧 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
@coderabbitaiin 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
@coderabbitaiin 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 pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.
@izzzzzi Напиши в телеграм плиз: @unstable6
@izzzzzi Приветствую, добавляя api_url - вы желаете дать пользователям возможность втыкать свои апи? Если так,то на каждом(почти) каптча сервисе роуты,аргументы разные.Если вы желаете для создания локальных апи - capsolver не предоставляет таких возможностей
@dwqekc я использую 3-4 сервиса для решения капчи и у всех апи идентичное
@dwqekc я использую 3-4 сервиса для решения капчи и у всех апи идентичное
для поддержания объектирования либо делай абстракции либо реализации под все нужны тебе сервисы
ну или блин просто форк свой поддерживай)),тут мержи не быстро принимают)))))
но кстати, абстракции - тут мастхев можно в будущем di сделать короче более правильный чем щас обычно пихают))
Верхние уровни не будут знать о низших из за конечной реализации абстракции