add function to return if a channel is live

This commit is contained in:
OMGeeky
2024-06-04 18:14:13 +02:00
parent c1f7eeed43
commit ee3ff97d26
3 changed files with 35 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "twba-twitch-data"
version = "0.3.2"
version = "0.4.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@@ -97,6 +97,22 @@ pub fn convert_twitch_video_to_twitch_data_video(twitch_video: TwitchVideo) -> V
}
impl<'a> TwitchClient<'a> {
pub async fn is_live(&self, login: &str) -> Result<bool> {
use twitch_api::helix::streams::get_streams;
let login = login.into();
let logins = &[login];
let mut req = get_streams::GetStreamsRequest::user_logins(logins);
req.first = Some(1);
let no_stream_found = self
.client
.helix
.req_get(req, &self.token)
.await?
.data
.is_empty();
Ok(!no_stream_found)
}
pub async fn get_videos_from_login(
&self,
login: &str,

View File

@@ -19,24 +19,34 @@ async fn main() -> Result<(), Box<dyn Error>> {
.expect("Failed to initialize logger");
// async fn main() -> Result<(), Box<dyn Error>> {
println!("Starting!");
info!("Starting!");
sample().await?;
println!("Done! 1");
info!("Done! 1");
// get_channel_title_from_login("bananabrea").await?;
println!("Done! 2");
info!("Done! 2");
// get_video_ids_from_channel("bananabrea").await?;
println!("Done! 3");
info!("Done! 3");
// get_video_info_from_id("1674543458").await?;
// get_video_info_from_id("1677206253").await?;
println!("Done! 4");
info!("Done! 4");
// get_video_playlist("1677206253").await?;
println!("Done! 5");
info!("Done! 5");
// download_video("1768835851").await?;
// download_video("1835211564").await?;
// download_video("1792000647").await?;
// combine_parts_test("1792000647").await?;
println!("Done! 6");
println!("Done! 7");
println!("\n\nDone!");
info!("Done! 6");
is_channel_live().await?;
info!("Done! 7");
info!("\n\nDone!");
println!("DONE!");
Ok(())
}
async fn is_channel_live() -> Result<(), Box<dyn Error>> {
let client = get_client().await?;
let is_live = client.is_live("spaceboy").await?;
info!("Is live: {}", is_live);
Ok(())
}