diff --git a/Cargo.toml b/Cargo.toml index e90bec6..a53fa70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/src/lib.rs b/src/lib.rs index bc19d4b..734bf08 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { + 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, diff --git a/src/main.rs b/src/main.rs index b62a284..86a7cad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,24 +19,34 @@ async fn main() -> Result<(), Box> { .expect("Failed to initialize logger"); // async fn main() -> Result<(), Box> { 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> { + let client = get_client().await?; + let is_live = client.is_live("spaceboy").await?; + info!("Is live: {}", is_live); Ok(()) }