How bilistream Supports YouTube Preview Live Streams: Complete Technical Guide
Yes, bilistream supports YouTube preview live streams through the special YoutubePreviewLive platform type, automatically resolving upcoming broadcast IDs and relaying live feeds to BiliBili once they start.
The bilistream project by limitcool is an open-source relay tool written in Rust that bridges live streaming platforms. When configured for YouTube preview live streams, it monitors channels showing "Coming soon" previews and automatically begins forwarding the stream to BiliBili the moment the broadcast goes live.
How bilistream Detects YouTube Preview Live Streams
The implementation in src/plugins/live.rs handles preview streams through a specific resolution flow when cfg.platform is set to "YoutubePreviewLive":
-
Retrieve the live video ID via
get_live_id_by_jumpinsrc/plugins/live.rs(lines 81-99). This function fetches the channel's "/live" page, extracts the embeddedytInitialDataJSON, and parses thevideoIdof the upcoming broadcast. -
Instantiate a standard YouTube handler by passing the resolved video ID to
Youtube::newinsrc/plugins/youtube.rs(lines 43-60). This creates a normalYoutubeinstance that queries stream status viaget_statusand retrieves the actual.m3u8URL usingyt-dlp. -
Periodic refresh in the main loop (
src/main.rs, lines 94-103). After each status check, the code detects the preview platform and refreshes the room ID by callingget_live_id_by_jumpagain, ensuring newly scheduled broadcasts are automatically detected without a restart.
Configuration for YouTube Preview Live Streams
To enable monitoring of preview streams, configure the Platform field and provide a ChannelId rather than a specific video ID:
Platform: YoutubePreviewLive # <‑‑ enable preview mode
Interval: 60 # check every 60 seconds
Youtube:
AccessToken: "<YOUR_API_KEY>" # required for YouTube API calls
YoutubePreviewLive:
ChannelId: "UCSJ4gkVC6NrvII8umztf0Ow" # channel to monitor
BiliLive:
SESSDATA: "<your sessdata>"
BiliRtmpUrl: "rtmp://live-push.biliapi.net/live/"
BiliRtmpKey: "<your rtmp key>"
Room: 123456
The ChannelId is the YouTube channel identifier (e.g., UCSJ4gkVC6NrvII8umztf0Ow), not the individual video ID.
Running the Relay
Execute the compiled binary to start monitoring:
cargo run --release
The runtime flow follows this sequence:
load_configinsrc/config.rsparses the configurationselect_liveresolves the current preview live video ID viaget_live_id_by_jump- The main loop periodically calls
r.get_status(); when it returnstrue, the system fetches the stream URL viayt-dlpand forwards it to BiliBili usingffmpeg
Debugging the Preview Resolver
For testing the preview detection logic independently, use this Rust snippet:
use bilistream::plugins::get_live_id_by_jump;
#[tokio::main]
async fn main() {
let video_id = get_live_id_by_jump("UCSJ4gkVC6NrvII8umztf0Ow")
.await
.expect("failed to get live id");
println!("Live video ID: {}", video_id);
}
This demonstrates exactly how bilistream extracts the upcoming broadcast ID from a channel's live page before the stream begins.
Key Implementation Files
The YouTube preview live stream support spans these critical source files:
src/plugins/live.rs– Containsselect_liveandget_live_id_by_jump, which resolve preview URLs by parsingytInitialDatafrom the channel's "/live" endpoint.src/plugins/youtube.rs– Implements theLivetrait for standard YouTube operations, includingget_statuschecks andyt-dlpintegration for.m3u8extraction.src/main.rs– Houses the main loop logic that triggers periodic refresh of preview live IDs when the platform type is detected.src/config.rs– Defines the configuration structures forPlatformandYoutubePreviewLivesettings.
Summary
- bilistream supports YouTube preview live streams natively via the
YoutubePreviewLiveplatform configuration. - The system extracts upcoming video IDs from channel pages using
get_live_id_by_jumpinsrc/plugins/live.rs. - Once live, the stream is handled by the standard
Youtubeimplementation insrc/plugins/youtube.rsusingyt-dlpfor URL resolution. - Configuration requires a
ChannelIdrather than a video ID, with automatic refresh handled in the main loop ofsrc/main.rs. - No manual intervention is needed when scheduled broadcasts transition from "Coming soon" previews to active live streams.
Frequently Asked Questions
How does bilistream handle scheduled YouTube broadcasts that haven't started yet?
When configured with Platform: YoutubePreviewLive, bilistream calls get_live_id_by_jump to scrape the channel's "/live" page and extract the upcoming videoId from the ytInitialData JSON. The system continues polling this endpoint, and once the broadcast begins, the status check returns active, triggering the relay to BiliBili.
What is the difference between Youtube and YoutubePreviewLive platform settings?
The Youtube platform requires a specific video ID for an active or upcoming stream, while YoutubePreviewLive only requires a ChannelId. The latter automatically resolves the current scheduled broadcast from the channel's live page, making it ideal for recurring scheduled streams or channels with rotating content.
Does bilistream require a YouTube API key for preview live streams?
Yes, the Youtube configuration section still requires an AccessToken (API key) because once the preview video ID is resolved, the system uses standard YouTube API calls via Youtube::new to check stream status and metadata before invoking yt-dlp for the actual stream URL.
Will bilistream automatically detect new broadcasts without restarting?
Yes. According to the main loop implementation in src/main.rs (lines 94-103), the code detects when YoutubePreviewLive is configured and periodically refreshes the room ID by re-invoking get_live_id_by_jump. This ensures that when one broadcast ends and a new preview appears, the system automatically adapts without requiring a process restart.
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 →