Skip to content

Commit

Permalink
finally, something that works
Browse files Browse the repository at this point in the history
  • Loading branch information
decahedron1 committed Jan 28, 2024
1 parent 651d385 commit 0b7fac6
Show file tree
Hide file tree
Showing 4 changed files with 341 additions and 252 deletions.
50 changes: 42 additions & 8 deletions examples/youtube.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
use std::{env::args, future::IntoFuture};
use std::future::IntoFuture;

use brainrot::youtube;
use futures_util::StreamExt;
use brainrot::youtube::{self, YouTubeChatPageProcessor};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let (options, cont) = youtube::get_options_from_live_page("6DcXroWNDvk").await?;
let initial_chat = youtube::fetch_yt_chat_page(&options, cont).await?;
let subscriber = youtube::SignalerChannel::new_from_cont(&initial_chat).await?;
let (receiver, handle) = subscriber.spawn_event_subscriber().await?;
handle.into_future().await.unwrap();
let (options, cont) = youtube::get_options_from_live_page("S144F6Cifyc").await?;
let initial_chat = youtube::fetch_yt_chat_page(&options, &cont).await?;
let topic = initial_chat.continuation_contents.as_ref().unwrap().live_chat_continuation.continuations[0]
.invalidation_continuation_data
.as_ref()
.unwrap()
.invalidation_id
.topic
.to_owned();
let subscriber = youtube::SignalerChannel::new(topic).await?;
let (mut receiver, _handle) = subscriber.spawn_event_subscriber().await?;
tokio::spawn(async move {
let mut processor = YouTubeChatPageProcessor::new(initial_chat, &options).unwrap();
for msg in &processor {
println!("{}: {}", msg.author.display_name, msg.runs.iter().map(|c| c.to_string()).collect::<String>());
}

while receiver.recv().await.is_ok() {
match processor.cont().await {
Some(Ok(s)) => {
processor = s;
for msg in &processor {
println!("{}: {}", msg.author.display_name, msg.runs.iter().map(|c| c.to_string()).collect::<String>());
}

subscriber.refresh_topic(processor.signaler_topic.as_ref().unwrap()).await;
}
Some(Err(e)) => {
eprintln!("{e:?}");
break;
}
None => {
eprintln!("none");
break;
}
}
}
});
_handle.into_future().await.unwrap();
println!("???");
Ok(())
}
Loading

0 comments on commit 0b7fac6

Please sign in to comment.