How to Configure Bilistream to Use Cookies for Twitch Streams

Bilistream supports Twitch cookie authentication by reading a Netscape-format cookie file path from the Cookies field in your YAML configuration and passing it to yt-dlp via the --cookies argument.

Bilistream is an open-source streaming bridge that relays live content from Twitch and YouTube to Bilibili. To configure Bilistream to use cookies for Twitch streams, you specify a valid Netscape-format cookie file in the global configuration, enabling the tool to extract subscriber-only or age-restricted streams that require authentication.

Understanding the Configuration Structure

Bilistream reads runtime settings from a YAML file that deserializes into the Config struct defined in src/config.rs (lines 5-27). This struct contains an optional field that stores your cookie file path:

pub cookies: Option<String>,

The application loads these settings through the load_config() function (lines 88-94 in src/config.rs). When the cookies field contains a value, Bilistream makes that path available to all platform plugins, including the Twitch implementation.

The Twitch plugin, located in src/plugins/twitch.rs, handles the injection of cookies into the stream extraction process. Within the Twitch::ytdlp() method (lines 118-122), the code checks for the presence of the cookies configuration:

if let Some(cookies) = &self.config.cookies {
    command.arg("--cookies");
    command.arg(cookies);
}

When a cookie path exists, the plugin appends the --cookies argument followed by the file path to the yt-dlp command. This allows yt-dlp to send stored authentication cookies to Twitch's HTTP endpoints, bypassing restrictions that require a logged-in session.

Step-by-Step Configuration Guide

Follow these steps to enable cookie authentication for Twitch streams.

Export your Twitch authentication cookies—including auth-token and session-id—to a text file in Netscape cookie format. You can generate this file using browser extensions, yt-dlp itself, or other cookie export tools. Ensure the tokens are valid and unexpired.

Update Your config.yaml

Add the absolute or relative path to your cookie file under the top-level Cookies key in your Bilistream configuration. This field belongs at the root level of the YAML structure, parallel to BiliLive, Twitch, and Platform:

BiliLive:
  SESSDATA: "<your sessdata>"
  bili_jct: "<your bili_jct>"
  DedeUserID: "<your user id>"
  DedeUserID__ckMd5: "<md5>"
  Room: 123456
  BiliRtmpUrl: "rtmp://..."
  BiliRtmpKey: "key"

Twitch:
  Room: "twitch_channel_name"

Interval: 30
Platform: "twitch"

# 👉 Add this line – path to your Netscape-format cookie file

Cookies: "/path/to/twitch_cookies.txt"

Run Bilistream

Start the application normally. The Twitch plugin automatically detects the Cookies entry and forwards the file path to yt-dlp. The tool can now access authenticated Twitch streams without additional manual steps.

Technical Implementation Details

When Bilistream initializes, the entry point in src/main.rs invokes load_config() to parse the YAML into the Config struct. The application clones this configuration into the Twitch plugin instance, making the cookie path available during stream detection.

During execution, the Twitch::ytdlp() method constructs the command-line arguments for yt-dlp. If self.config.cookies is Some, it appends two arguments: first --cookies, then the path string. This sequence ensures yt-dlp loads the cookie jar before making HTTP requests to Twitch's stream endpoints.

The same cookie handling logic exists in src/plugins/youtube.rs, allowing you to reuse the configuration structure for YouTube authentication if needed.

Summary

  • The Config struct in src/config.rs defines an optional cookies field that stores the file path as a String.
  • The Twitch plugin in src/plugins/twitch.rs checks this field within Twitch::ytdlp() and appends --cookies <path> to the yt-dlp invocation.
  • You must provide a Netscape-format cookie file containing valid Twitch authentication tokens like auth-token.
  • Add the Cookies key at the root level of config.yaml with the absolute or relative path to your cookie file.

Frequently Asked Questions

Bilistream requires a Netscape-format cookie file, which is a plain text format that yt-dlp can parse. This file should include essential Twitch cookies such as auth-token and session-id. Most browser cookie export extensions or yt-dlp itself can generate this format.

Can I use the same cookies file for YouTube and Twitch?

Yes. The Cookies configuration is global, meaning the same file path is passed to both the Twitch plugin (src/plugins/twitch.rs) and the YouTube plugin (src/plugins/youtube.rs). If your cookie file contains entries for both domains, yt-dlp will automatically use the appropriate cookies for each platform.

Where do I place the Cookies entry in the YAML file?

The Cookies field must be placed at the top level of your config.yaml file, alongside other root-level keys like Platform, Interval, and BiliLive. It is not nested inside the Twitch section, as the Config struct treats it as a global setting available to all plugins.

Why are my subscriber-only streams still failing to load?

Ensure your cookie file is in Netscape format and contains unexpired authentication tokens. Verify that the file path specified in the Cookies field is correct and accessible by the Bilistream process. Additionally, confirm that your Twitch account has the necessary subscription or permission to view the restricted content, as cookies cannot bypass access requirements.

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 →