How biliTickerBuy Automatically Opens the Payment URL: A Technical Deep Dive

biliTickerBuy automatically opens the payment URL by checking the auto_open_payment_url configuration flag and calling Python's webbrowser.open() method when the order succeeds or a terminal rule exposes a payment link.

The open-source ticketing tool biliTickerBuy streamlines the Bilibili ticket purchasing process by optionally launching your default browser immediately when a payment URL becomes available. This automation eliminates the need to manually copy order links, reducing checkout friction during high-demand ticket releases. Understanding how biliTickerBuy automatically opens the payment URL requires examining the configuration system and the core purchase logic implemented in the repository.

Configuration Flag That Controls Auto-Open

The BuyConfig Data Class

In interface/config.py, the BuyConfig data class defines the boolean field that governs this behavior at line 51:

auto_open_payment_url: bool = True

This default value of True means that, unless explicitly disabled, the system will automatically attempt to open the payment page in your default browser upon successful order creation.

CLI Option for Toggling

The app_cmd/config/BuyConfig.py file exposes this configuration through the command-line interface. Users can override the default setting using the --auto-open-payment-url flag or its negative counterpart --no-auto-open-payment-url, providing flexibility without requiring code modifications.

Order Creation Flow and Payment URL Logic

The actual browser invocation occurs within task/buy.py, specifically within two execution paths: the standard success path and the terminal rule exception handler.

Successful Order Path

When the purchase loop successfully creates an order (indicated by errno == 0), the system extracts the order ID, constructs the payment URL, and conditionally opens it. Lines 726-733 in task/buy.py implement this logic:

payment_url = get_order_detail_url(order_id)
if config.auto_open_payment_url:
    webbrowser.open(payment_url)

The get_order_detail_url() function builds the complete payment URL from the order ID, while webbrowser.open() launches the system default browser with that URL.

Terminal Rule Exception Path

Even when the purchase aborts due to a terminal rule that still exposes a payment link, the same auto-open logic applies. Lines 780-787 in task/buy.py handle this scenario:

payment_url = get_order_detail_url(order_id)
if config.auto_open_payment_url:
    webbrowser.open(payment_url)

This ensures users can complete payment even when the automated purchasing logic encounters terminal conditions that require manual intervention.

How to Enable or Disable Auto-Open

You can control this behavior via command-line arguments or programmatic configuration.

Via CLI with default enabled:

btb buy --tickets-info '{"detail": "..."}'

Via CLI explicitly disabled:

btb buy --tickets-info '{"detail": "..."}' --no-auto-open-payment-url

Via Python API:

from app_cmd.config.BuyConfig import BuyConfig
from task.buy import Buy

cfg = BuyConfig(auto_open_payment_url=False)
Buy(config=cfg).buy()

Summary

  • Configuration-driven: The auto_open_payment_url boolean in interface/config.py (line 51) controls the feature, defaulting to True.
  • Dual execution paths: Both successful orders (lines 726-733) and terminal rule exceptions (lines 780-787) in task/buy.py implement the same conditional browser opening logic.
  • Standard library usage: The implementation relies on Python's built-in webbrowser.open() method for cross-platform browser compatibility.
  • CLI flexibility: Users can toggle the behavior using --auto-open-payment-url or --no-auto-open-payment-url flags without modifying source code.

Frequently Asked Questions

Can I disable the automatic browser opening in biliTickerBuy?

Yes. You can disable this feature by passing the --no-auto-open-payment-url flag when running the buy command from the CLI, or by setting auto_open_payment_url=False when constructing the BuyConfig object programmatically in your Python scripts.

Which file contains the logic that opens the payment URL?

The core logic resides in task/buy.py, specifically between lines 726-733 for successful orders and lines 780-787 for terminal rule scenarios. Both locations check the configuration flag before calling webbrowser.open() to launch the system browser.

What happens if the automatic browser opening fails?

The code does not implement explicit error handling for webbrowser.open() failures. If the browser fails to launch, the payment URL has already been constructed using get_order_detail_url(order_id) and logged, allowing you to manually navigate to the order detail page using the extracted order ID.

Is the auto-open feature enabled by default?

Yes. According to the source code in interface/config.py at line 51, the auto_open_payment_url field defaults to True, meaning the browser will automatically open unless you explicitly disable this behavior via CLI flags or programmatic configuration.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →