diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-24 11:24:17 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-24 11:45:25 +0200 |
commit | 4eeb519ae5398b5b5f5c7d9938e3887cac2c9faf (patch) | |
tree | 57340831cbb5d2f1842cf5c8a7c8fad4a00ba29d | |
parent | fix(contrib/config.toml): Correct typo in config key (diff) | |
download | yt-4eeb519ae5398b5b5f5c7d9938e3887cac2c9faf.tar.gz yt-4eeb519ae5398b5b5f5c7d9938e3887cac2c9faf.zip |
feat(videos): Allow limiting the number of videos to show
-rw-r--r-- | src/cli.rs | 4 | ||||
-rw-r--r-- | src/main.rs | 7 | ||||
-rw-r--r-- | src/videos/mod.rs | 7 |
3 files changed, 14 insertions, 4 deletions
diff --git a/src/cli.rs b/src/cli.rs index 4e64657..3b13bdf 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -139,6 +139,10 @@ pub enum VideosCommand { /// An optional search query to limit the results #[arg(action = ArgAction::Append)] search_query: Option<String>, + + /// The number of videos to show + #[arg(short, long)] + limit: Option<usize>, }, /// Get detailed information about a video diff --git a/src/main.rs b/src/main.rs index 28a0b38..57e711d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -102,8 +102,11 @@ async fn main() -> Result<()> { } } Command::Videos { cmd } => match cmd { - VideosCommand::List { search_query } => { - videos::query(&app, search_query) + VideosCommand::List { + search_query, + limit, + } => { + videos::query(&app, limit, search_query) .await .context("Failed to query videos")?; } diff --git a/src/videos/mod.rs b/src/videos/mod.rs index 5bf34e3..b51e469 100644 --- a/src/videos/mod.rs +++ b/src/videos/mod.rs @@ -20,16 +20,19 @@ use crate::{ storage::video_database::{getters::get_videos, VideoStatus}, }; -pub async fn query(app: &App, search_query: Option<String>) -> Result<()> { - let all_videos = get_videos(app, &VideoStatus::ALL, None).await?; +pub async fn query(app: &App, limit: Option<usize>, search_query: Option<String>) -> Result<()> { + let all_videos = get_videos(app, VideoStatus::ALL, None).await?; // turn one video to a color display, to pre-warm the hash shrinking cache if let Some(val) = all_videos.get(0) { val.to_color_display(app).await?; } + let limit = limit.unwrap_or(all_videos.len()); + let all_video_strings: Vec<String> = all_videos .into_iter() + .take(limit) .map(|vid| vid.to_color_display_owned(app)) .collect::<FuturesUnordered<_>>() .try_collect() |