How to Switch Between Twitch and YouTube in bilistream Configuration
Change the Platform field in 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 via config::load_config() defined in [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) within the select_live function. This function matches the configuration string against supported platform identifiers:
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 aTwitchobject from [src/plugins/twitch.rs](https://github.com/limitcool/bilistream/blob/main/src/plugins/twitch.rs). - If
Platform="Youtube"→ Constructs aYoutubeobject from [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 aYoutubeinstance.
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.
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:
# 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:
# 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.
Switching to YouTubePreviewLive
For channels with scheduled upcoming streams, use the preview mode:
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: Defines theConfigstruct and theload_config()function that deserializesconfig.yaml.src/plugins/live.rs: Contains theselect_liveselector that instantiates the appropriate platform plugin based on thePlatformstring.src/plugins/twitch.rs: Implements theLivetrait for Twitch, including status checks and stream URL extraction via the Twitch API.src/plugins/youtube.rs: Implements theLivetrait for YouTube, handling token-based API calls andyt-dlpextraction.
Summary
- Modify the
Platformfield inconfig.yamlto switch sources instantly without rebuilding the binary. - Valid values are
"Twitch","Youtube", or"YoutubePreviewLive"(case-sensitive as implemented insrc/plugins/live.rs). - Twitch only requires
Twitch.Room, while YouTube requires bothYoutube.RoomandYoutube.AccessToken. - The BiliLive section remains constant across all platform configurations.
- Restart the application after modifying
config.yamlto reload the configuration viaconfig::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: "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. The configuration is loaded once at startup via config::load_config() in 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 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 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.
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:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →