Crates.io | youtube_chat |
lib.rs | youtube_chat |
version | 0.2.1 |
source | src |
created_at | 2023-02-23 13:14:38.811802 |
updated_at | 2023-07-17 08:01:01.112386 |
description | provides Rust interface of fetching youtube live chat comments |
homepage | |
repository | https://github.com/lemolatoon/youtube_chat_rs |
max_upload_size | |
id | 792748 |
size | 42,239 |
url
or live_id
or channel_id
// pattern 1
let mut client = LiveClientBuilder::new()
.url("https://www.youtube.com/watch?v=jfKfPfyJRdk".to_string())
.unwrap()
.build();
// pattern 2
let mut client = LiveChatClientBuilder::new()
.live_id("jfKfPfyJRd".to_string())
.build();
// pattern 3
let mut client = LiveChatClientBuilder::new()
.channel_id("UCHVXbQzkl3rDfsXWo8xi2qw".to_string())
.build();
let mut client = LiveChatClientBuilder::new()
.url("https://www.youtube.com/watch?v=Dx5qFachd3A".to_string())
.unwrap()
.on_start(|_live_id| {})
.on_error(|_err| {})
.on_chat(|_chat_item| {})
.on_end(|| {})
.build();
client.start().await.unwrap();
client.execute().await;
execute
intervally if you want to fetch comments in real timeExample using tokio
use std::time::Duration;
use tokio::{task, time};
use youtube_chat::live_chat::LiveChatClientBuilder;
#[tokio::main]
async fn main() {
let mut client = LiveChatClientBuilder::new()
.url("https://www.youtube.com/watch?v=jfKfPfyJRdk".to_string())
.unwrap()
.on_chat(|chat_item| println!("{:?}", chat_item.message))
.on_error(|error| eprintln!("{:?}", error))
.build();
client.start().await.unwrap();
let forever = task::spawn(async move {
let mut interval = time::interval(Duration::from_millis(3000));
loop {
interval.tick().await;
client.execute().await;
}
});
forever.await.unwrap();
}