# How to Switch Between Twitch and YouTube in bilistream Configuration

> Easily switch between Twitch and YouTube in bilistream configuration by changing the Platform field in config.yaml. Restart the app to update your livestream source instantly.

- Repository: [InitCool/bilistream](https://github.com/limitcool/bilistream)
- Tags: how-to-guide
- Published: 2026-03-06

---

**Change the `Platform` field in [`config.yaml`](https://github.com/limitcool/bilistream/blob/main/config.yaml) to `"Twitch"`, `"Youtube"`, or `"YoutubePreviewLive"` and restart the application to instantly switch the upstream livestream source.**

bilistream is a Rust-based relay tool that forwards livestreams from external platforms to Bilibili. According to the limitcool/bilistream source code, the application determines which upstream service to pull from based on the `Platform` string value in your configuration file, requiring no code modifications to switch sources.

## How Platform Selection Works in bilistream

When bilistream starts, it loads [`config.yaml`](https://github.com/limitcool/bilistream/blob/main/config.yaml) via `config::load_config()` defined in [[`src/config.rs`](https://github.com/limitcool/bilistream/blob/main/src/config.rs)](https://github.com/limitcool/bilistream/blob/main/src/config.rs). The parsed `Config` struct contains a `platform: String` member (lines 15‑16) that stores your selected upstream service.

The platform selection logic resides in [[`src/plugins/live.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/live.rs)](https://github.com/limitcool/bilistream/blob/main/src/plugins/live.rs) within the `select_live` function. This function matches the configuration string against supported platform identifiers:

```rust
match cfg.platform.as_str() {
    "Youtube" => Ok(Box::new(Youtube::new(...))),
    "Twitch"  => Ok(Box::new(Twitch::new(...))),
    "YoutubePreviewLive" => { … },
    _ => Err("unknown platform".into()),
}

```

- **If `Platform` = `"Twitch"`** → Constructs a `Twitch` object from [[`src/plugins/twitch.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/twitch.rs)](https://github.com/limitcool/bilistream/blob/main/src/plugins/twitch.rs).
- **If `Platform` = `"Youtube"`** → Constructs a `Youtube` object from [[`src/plugins/youtube.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/youtube.rs)](https://github.com/limitcool/bilistream/blob/main/src/plugins/youtube.rs).
- **If `Platform` = `"YoutubePreviewLive"`** → Resolves the upcoming live ID before creating a `Youtube` instance.

The `BiliLive` configuration section remains unchanged regardless of platform selection, as it always provides the Bilibili push credentials.

## Platform-Specific Configuration Requirements

Each platform requires distinct configuration fields in [`config.yaml`](https://github.com/limitcool/bilistream/blob/main/config.yaml).

### Twitch Configuration

When switching to Twitch, you must provide the channel identifier:

- **`Twitch.Room`**: The Twitch channel name or ID (e.g., `maximilian_dood`).

### YouTube Configuration

YouTube requires API authentication to fetch stream data:

- **`Youtube.Room`**: The YouTube channel ID or livestream ID.
- **`Youtube.AccessToken`**: A valid YouTube Data API access token.

### YouTubePreviewLive Configuration

This mode automatically detects upcoming scheduled livestreams:

- **`YoutubePreviewLive.ChannelId`**: The YouTube channel ID to monitor for upcoming broadcasts.

## Configuration Examples

### Switching to Twitch

Set `Platform` to `"Twitch"` and define the `Twitch.Room` field:

```yaml

# config.yaml

Interval: 60
Platform: Twitch          # <-- Set to Twitch

BiliLive:
  SESSDATA: <your-sessdata>
  bili_jct: <your-bili-jct>
  DedeUserID: 2235894
  DedeUserID__ckMd5: <hash>
  Room: 660428
  BiliRtmpUrl: rtmp://live-push.bilivideo.com/live-bvc/
  BiliRtmpKey: "?streamname=..."
Twitch:
  Room: maximilian_dood   # <-- Twitch channel name/ID

Youtube:
  Room: UC1zFJrfEKvCixhsjNSb1toQ
  AccessToken: <youtube-token>

```

After editing, restart the container or binary. The `select_live` function will match `"Twitch"` and pull from the Twitch API.

### Switching to YouTube

Set `Platform` to `"Youtube"` and ensure both YouTube fields are populated:

```yaml

# config.yaml

Interval: 60
Platform: Youtube         # <-- Set to Youtube

BiliLive:
  # (Bilibili credentials unchanged)

Twitch:
  Room:                     # Leave empty or remove

Youtube:
  Room: UC1zFJrfEKvCixhsjNSb1toQ   # YouTube channel or live ID

  AccessToken: <youtube-token>     # Valid API token

```

The `Youtube` plugin will now fetch the live URL via `yt-dlp` as implemented in [`src/plugins/youtube.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/youtube.rs).

### Switching to YouTubePreviewLive

For channels with scheduled upcoming streams, use the preview mode:

```yaml
Platform: YoutubePreviewLive
YoutubePreviewLive:
  ChannelId: UC1zFJrfEKvCixhsjNSb1toQ

```

This triggers `get_live_id_by_jump` to resolve the upcoming live ID before initializing the stream grabber.

## Key Source Files

Understanding these files helps clarify how bilistream handles platform switching:

- **[`src/config.rs`](https://github.com/limitcool/bilistream/blob/main/src/config.rs)**: Defines the `Config` struct and the `load_config()` function that deserializes [`config.yaml`](https://github.com/limitcool/bilistream/blob/main/config.yaml).
- **[`src/plugins/live.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/live.rs)**: Contains the `select_live` selector that instantiates the appropriate platform plugin based on the `Platform` string.
- **[`src/plugins/twitch.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/twitch.rs)**: Implements the `Live` trait for Twitch, including status checks and stream URL extraction via the Twitch API.
- **[`src/plugins/youtube.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/youtube.rs)**: Implements the `Live` trait for YouTube, handling token-based API calls and `yt-dlp` extraction.

## Summary

- Modify the **`Platform`** field in [`config.yaml`](https://github.com/limitcool/bilistream/blob/main/config.yaml) to switch sources instantly without rebuilding the binary.
- Valid values are **`"Twitch"`**, **`"Youtube"`**, or **`"YoutubePreviewLive"`** (case-sensitive as implemented in [`src/plugins/live.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/live.rs)).
- **Twitch** only requires `Twitch.Room`, while **YouTube** requires both `Youtube.Room` and `Youtube.AccessToken`.
- The **BiliLive** section remains constant across all platform configurations.
- Restart the application after modifying [`config.yaml`](https://github.com/limitcool/bilistream/blob/main/config.yaml) to reload the configuration via `config::load_config()`.

## Frequently Asked Questions

### What are the exact valid values for the Platform field in bilistream?

The `Platform` field accepts three case-sensitive string values as defined in [`src/plugins/live.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/live.rs): `"Twitch"`, `"Youtube"`, or `"YoutubePreviewLive"`. Any other value results in an "unknown platform" error. The match statement in the `select_live` function uses these exact strings to determine which plugin struct to instantiate.

### Do I need to restart bilistream after changing the Platform setting?

Yes, you must restart the bilistream container or binary after editing [`config.yaml`](https://github.com/limitcool/bilistream/blob/main/config.yaml). The configuration is loaded once at startup via `config::load_config()` in [`src/config.rs`](https://github.com/limitcool/bilistream/blob/main/src/config.rs). The application does not watch for file changes or hot-reload the configuration during runtime.

### Why does YouTube require an AccessToken while Twitch does not?

The YouTube implementation in [`src/plugins/youtube.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/youtube.rs) uses the YouTube Data API to resolve livestream URLs and metadata, which requires OAuth 2.0 authentication via the `AccessToken`. Conversely, the Twitch implementation in [`src/plugins/twitch.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/twitch.rs) uses public API endpoints or `yt-dlp` extraction methods that do not require user authentication tokens, only a channel identifier (`Twitch.Room`).

### What is the difference between Youtube and YoutubePreviewLive platforms?

`"Youtube"` connects to an active livestream specified by `Youtube.Room` (a specific live ID or channel currently streaming). `"YoutubePreviewLive"` uses `YoutubePreviewLive.ChannelId` to query a channel's upcoming scheduled broadcasts via `get_live_id_by_jump`, automatically resolving and connecting to the next scheduled livestream before it starts. Use the former for active streams and the latter for scheduled premieres or upcoming events.