diff --git a/src/soundcloud/mod.rs b/src/soundcloud/mod.rs index 37e2e00..d90957e 100644 --- a/src/soundcloud/mod.rs +++ b/src/soundcloud/mod.rs @@ -15,7 +15,7 @@ pub struct SoundCloudConfig { /// Amount of items to query pub limit: Option, // Items to check - pub artists: HashMap, + pub artists: HashMap, // Output Template for yt-dlp pub output_format: Option, // Download comments diff --git a/src/youtube/mod.rs b/src/youtube/mod.rs index bb6cc9b..a9a606f 100644 --- a/src/youtube/mod.rs +++ b/src/youtube/mod.rs @@ -15,7 +15,7 @@ pub struct YouTubeConfig { /// Amount of videos to query limit: Option, // Channels to check - channels: HashMap, + channels: HashMap, // Format of the Thumbnail thumbnail_format: Option, // Output Template for yt-dlp diff --git a/src/yt_dlp/mod.rs b/src/yt_dlp/mod.rs index 5d7a81b..986d198 100644 --- a/src/yt_dlp/mod.rs +++ b/src/yt_dlp/mod.rs @@ -19,7 +19,7 @@ pub struct YtDlpConfig { /// Amount of items to query pub limit: Option, // Items to check - pub items: HashMap, + pub items: HashMap, // Format of the Thumbnail pub thumbnail_format: Option, // Output Template for yt-dlp @@ -73,6 +73,36 @@ impl YtDlpModule { root_dir, } } + + fn check_item(&self, item: &str, item_url: &str, cwd: &PathBuf) { + log::info!("Fetching \"{item}\" videos"); + match Self::get_latest_entries(item_url, self.config.limit.unwrap_or(10)) { + Ok(latest_videos) => { + for (video_title, video_url) in latest_videos { + if self.db.check_for_url(&video_url) { + log::trace!("Skipping \"{video_title}\" because it was already downloaded"); + } else { + match self.download(&video_url, cwd) { + Ok(()) => { + // mark as downloaded + self.db.insert_url(&video_url); + self.db.update_new_downloads(&self.name(), item, item_url); + log::info!("Downloaded \"{video_title}\""); + self.webhook_notify(&video_url, &video_title, item, true); + } + Err(e) => { + log::error!("Error downloading \"{video_title}\"; Reason: {e}"); + self.webhook_notify(&video_url, &video_title, item, false); + } + } + } + } + } + Err(e) => { + log::error!("Could not get videos from \"{item}\". Reason: {e}"); + } + } + } } impl Module for YtDlpModule { @@ -88,36 +118,23 @@ impl Module for YtDlpModule { log::info!("Running {} Module", self.name()); log::info!("Checking {} items", self.config.items.len()); for (item, item_url) in &self.config.items { - log::info!("Fetching \"{item}\" videos"); - match Self::get_latest_entries(item_url, self.config.limit.unwrap_or(10)) { - Ok(latest_videos) => { - for (video_title, video_url) in latest_videos { - if self.db.check_for_url(&video_url) { - log::trace!( - "Skipping \"{video_title}\" because it was already downloaded" - ); - } else { - match self.download(&video_url, &self.root_dir.join(item)) { - Ok(()) => { - // mark as downloaded - self.db.insert_url(&video_url); - self.db.update_new_downloads(&self.name(), item, item_url); - log::info!("Downloaded \"{video_title}\""); - self.webhook_notify(&video_url, &video_title, item, true); - } - Err(e) => { - log::error!( - "Error downloading \"{video_title}\"; Reason: {e}" - ); - self.webhook_notify(&video_url, &video_title, item, false); - } - } - } + match item_url { + toml::Value::String(item_url) => { + self.check_item(item, item_url, &self.root_dir.join(item)); + } + toml::Value::Array(_) => todo!(), + toml::Value::Table(cat) => { + let category = item; + for (item, item_url) in cat { + let item_url = item_url.as_str().unwrap(); + self.check_item( + item, + item_url, + &self.root_dir.join(category).join(item), + ); } } - Err(e) => { - log::error!("Could not get videos from \"{item}\". Reason: {e}"); - } + _ => {} } } log::info!(