-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
651d385
commit 0b7fac6
Showing
4 changed files
with
341 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
Oops, something went wrong.