From 7726acf5b6c0de3127706d406d8d1975a2325cf2 Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Tue, 4 Jun 2024 18:19:59 +0200 Subject: [PATCH] Add check if user is live (prevents partial downloads) --- Cargo.toml | 4 ++-- src/client.rs | 4 ++++ src/errors.rs | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8a3aa6d..962d2c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "twba-twitch-fetcher" -version = "0.1.1" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -twba-twitch-data = { version = "0.3", git = "https://github.com/OMGeeky/twitch_data.git" } +twba-twitch-data = { version = "0.4", git = "https://github.com/OMGeeky/twitch_data.git" } twba-common = { version = "0.2", git = "https://github.com/OMGeeky/twba.common.git" } tracing = "0.1" diff --git a/src/client.rs b/src/client.rs index deb3fd4..b9d65bd 100644 --- a/src/client.rs +++ b/src/client.rs @@ -34,6 +34,10 @@ impl<'a> FetcherClient<'a> { .await?; info!("Fetching videos for {} users", users.len()); for user in users { + if self.twitch_client.is_live(&user.twitch_name).await.map_err(FetcherError::CheckLiveError)? { + info!("User: {} is live, skipping fetching videos", user.twitch_name); + continue; + } match self.fetch_videos_for_user(&user).await { Ok(_) => { info!("Fetched videos for user: {}", user.twitch_name); diff --git a/src/errors.rs b/src/errors.rs index 62990d7..6575a58 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -14,4 +14,6 @@ pub enum FetcherError { CreateClientError(#[source] Box), #[error("Could not get videos: {0:?}")] GetVideosError(#[source] Box), + #[error("Could not get videos: {0:?}")] + CheckLiveError(#[source] Box), }