How to Monitor bilistream Live Broadcast Status with Gotify: Complete Configuration Guide
Configure a Gotify endpoint in config.yaml and bilistream will automatically push notifications to your Gotify server whenever a monitored YouTube or Twitch channel begins broadcasting.
The bilistream application from the limitcool/bilistream repository continuously monitors live streaming platforms and can alert you via Gotify the moment a stream goes online. By implementing the Live trait for platform-specific adapters and integrating with the Gotify push API, bilistream bridges live status detection with instant mobile notifications. This guide explains the exact configuration and code paths required to enable live broadcast monitoring with Gotify notifications.
How bilistream Detects Live Broadcast Status
The core monitoring mechanism relies on the Live trait defined in src/plugins/live.rs. This trait abstracts live-status checking across multiple platforms:
#[async_trait]
pub trait Live {
async fn get_status(&self) -> Result<bool, Box<dyn Error>>;
fn room(&self) -> &str;
async fn get_real_m3u8_url(&self) -> Result<String, Box<dyn Error>>;
fn set_room(&mut self, room: &str);
}
Platform implementations (e.g., Youtube, Twitch) provide concrete logic for get_status, which returns true when a broadcast is active. The select_live factory function instantiates the appropriate adapter based on your configuration, allowing bilistream to poll r.get_status().await uniformly regardless of the underlying platform.
Configuring Gotify in bilistream
To receive push notifications, you must define a Gotify section in your config.yaml. The Config struct in src/config.rs declares this as an optional field:
pub struct Config {
pub gotify: Option<GotifyConfig>,
// ... other fields
}
Add the following to your configuration file:
Gotify:
Url: "https://your-gotify-server.com/message"
Token: "YOUR_GOTIFY_APP_TOKEN"
The GotifyConfig struct expects a url string pointing to your Gotify message endpoint and a token string containing your application token. When this configuration is present, bilistream initializes the notification pipeline; when absent, the application skips Gotify alerts and continues with stream recording only.
The Notification Workflow: From Status Check to Alert
The main event loop in src/main.rs orchestrates the monitoring and notification sequence. Every polling cycle executes the following logic:
- Status Check: Calls
r.get_status().await.unwrap_or(false)on the live platform adapter - Online Detection: When the result is
true, the stream is marked as live - Notification Trigger: If
cfg.gotifyisSome, bilistream invokessend_gotify_notification
if r.get_status().await.unwrap_or(false) {
tracing::info!("{}直播中", r.room());
if let Some(ref gotify_config) = cfg.gotify {
send_gotify_notification(
&gotify_config,
&format!("{}开始直播", r.room()),
"bilistream",
)
.await;
}
// ... ffmpeg and Bilibili upload logic follows
}
This implementation ensures notifications fire immediately upon broadcast detection, using the tracing crate to log successful dispatches or connection errors.
Gotify Client Implementation Details
The actual HTTP push logic resides in src/push.rs within the send_gotify_notification function:
pub async fn send_gotify_notification(
config: &GotifyConfig,
message: &str,
title: &str,
) {
match GotifyClient::new(config.url.as_str(), &config.token) {
Ok(client) => match client.create_message(message).with_title(title).await {
Ok(_) => tracing::info!("Gotify通知发送成功"),
Err(e) => tracing::error!("Gotify通知发送失败: {}", e),
},
Err(e) => tracing::error!("Gotify客户端创建失败: {}", e),
}
}
The function constructs a GotifyClient using your configured URL and token, then dispatches a message with the provided title. Error handling covers both client instantiation failures (invalid URL/token) and message transmission failures, ensuring bilistream remains stable even if your Gotify server is temporarily unreachable.
Summary
- Configuration: Add the
Gotifyblock toconfig.yamlwithUrlandTokenfields as defined insrc/config.rs - Monitoring: The
Livetrait insrc/plugins/live.rsstandardizes status checking across YouTube, Twitch, and other platforms viaget_status() - Triggering: The main loop in
src/main.rsevaluatesr.get_status().awaitand callssend_gotify_notification()only when the stream transitions to online - Delivery:
src/push.rshandles the Gotify HTTP API integration, formatting messages with the channel name and "bilistream" title
Frequently Asked Questions
What is the minimum configuration required to enable Gotify notifications in bilistream?
You must add a Gotify section to your config.yaml containing two fields: Url (your Gotify server message endpoint) and Token (your Gotify application token). The Config struct in src/config.rs parses these into a GotifyConfig instance; bilistream checks cfg.gotify.is_some() before attempting any push notifications.
Which live streaming platforms does bilistream support for Gotify alerts?
bilistream supports any platform implementing the Live trait in src/plugins/live.rs, including YouTube and Twitch. The select_live factory creates platform-specific instances (e.g., Youtube, Twitch) that each implement get_status(), allowing the same Gotify notification logic to work uniformly across different streaming services.
How does bilistream handle Gotify server errors or connectivity issues?
The send_gotify_notification function in src/push.rs uses match expressions to catch and log errors via the tracing crate. If the Gotify client fails to initialize or the message fails to send, bilistream logs the error with tracing::error!() but continues executing the main loop, ensuring that temporary notification failures do not interrupt the live stream recording process.
Can I customize the notification title and message format sent to Gotify?
Yes. The main loop in src/main.rs calls send_gotify_notification with a formatted message string: format!("{}开始直播", r.room()). You can modify this format string in the source code to include additional metadata such as the platform name or current timestamp. The title parameter ("bilistream" by default) can also be changed in the same function call.
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 →