# How bilistream Supports YouTube Preview Live Streams: Complete Technical Guide

> Discover how bilistream supports YouTube preview live streams using the YoutubePreviewLive platform. This guide explains how to resolve IDs and relay live feeds to BiliBili.

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

---

**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`](https://github.com/limitcool/bilistream/blob/main/src/plugins/live.rs) handles preview streams through a specific resolution flow when `cfg.platform` is set to `"YoutubePreviewLive"`:

1. **Retrieve the live video ID** via `get_live_id_by_jump` in [`src/plugins/live.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/live.rs) (lines 81-99). This function fetches the channel's "/live" page, extracts the embedded `ytInitialData` JSON, and parses the `videoId` of the upcoming broadcast.

2. **Instantiate a standard YouTube handler** by passing the resolved video ID to `Youtube::new` in [`src/plugins/youtube.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/youtube.rs) (lines 43-60). This creates a normal `Youtube` instance that queries stream status via `get_status` and retrieves the actual `.m3u8` URL using `yt-dlp`.

3. **Periodic refresh** in the main loop ([`src/main.rs`](https://github.com/limitcool/bilistream/blob/main/src/main.rs), lines 94-103). After each status check, the code detects the preview platform and refreshes the room ID by calling `get_live_id_by_jump` again, 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:

```yaml
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:

```bash
cargo run --release

```

The runtime flow follows this sequence:

- `load_config` in [`src/config.rs`](https://github.com/limitcool/bilistream/blob/main/src/config.rs) parses the configuration
- `select_live` resolves the current preview live video ID via `get_live_id_by_jump`
- The main loop periodically calls `r.get_status()`; when it returns `true`, the system fetches the stream URL via `yt-dlp` and forwards it to BiliBili using `ffmpeg`

## Debugging the Preview Resolver

For testing the preview detection logic independently, use this Rust snippet:

```rust
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`](https://github.com/limitcool/bilistream/blob/main/src/plugins/live.rs)** – Contains `select_live` and `get_live_id_by_jump`, which resolve preview URLs by parsing `ytInitialData` from the channel's "/live" endpoint.
- **[`src/plugins/youtube.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/youtube.rs)** – Implements the `Live` trait for standard YouTube operations, including `get_status` checks and `yt-dlp` integration for `.m3u8` extraction.
- **[`src/main.rs`](https://github.com/limitcool/bilistream/blob/main/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`](https://github.com/limitcool/bilistream/blob/main/src/config.rs)** – Defines the configuration structures for `Platform` and `YoutubePreviewLive` settings.

## Summary

- **bilistream** supports **YouTube preview live streams** natively via the `YoutubePreviewLive` platform configuration.
- The system extracts upcoming video IDs from channel pages using `get_live_id_by_jump` in [`src/plugins/live.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/live.rs).
- Once live, the stream is handled by the standard `Youtube` implementation in [`src/plugins/youtube.rs`](https://github.com/limitcool/bilistream/blob/main/src/plugins/youtube.rs) using `yt-dlp` for URL resolution.
- Configuration requires a `ChannelId` rather than a video ID, with automatic refresh handled in the main loop of [`src/main.rs`](https://github.com/limitcool/bilistream/blob/main/src/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`](https://github.com/limitcool/bilistream/blob/main/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.