From 6c9286857ef8b314962b67f4a16a66e8c35531bc Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Mon, 14 Oct 2024 14:56:29 +0200 Subject: refactor(treewide): Combine the separate crates in one workspace --- src/videos/mod.rs | 66 ------------------------------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 src/videos/mod.rs (limited to 'src/videos/mod.rs') diff --git a/src/videos/mod.rs b/src/videos/mod.rs deleted file mode 100644 index 59baa8c..0000000 --- a/src/videos/mod.rs +++ /dev/null @@ -1,66 +0,0 @@ -// yt - A fully featured command line YouTube client -// -// Copyright (C) 2024 Benedikt Peetz -// SPDX-License-Identifier: GPL-3.0-or-later -// -// This file is part of Yt. -// -// You should have received a copy of the License along with this program. -// If not, see . - -use anyhow::Result; -use display::{format_video::FormatVideo, FormattedVideo}; -use futures::{stream::FuturesUnordered, TryStreamExt}; -use nucleo_matcher::{ - pattern::{CaseMatching, Normalization, Pattern}, - Matcher, -}; - -pub mod display; - -use crate::{ - app::App, - storage::video_database::{getters::get_videos, VideoStatus}, -}; - -pub async fn query(app: &App, limit: Option, search_query: Option) -> 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.first() { - val.to_formatted_video(app).await?; - } - - let limit = limit.unwrap_or(all_videos.len()); - - let all_video_strings: Vec = all_videos - .into_iter() - .take(limit) - .map(|vid| vid.to_formatted_video_owned(app)) - .collect::>() - .try_collect::>() - .await? - .into_iter() - .map(|vid| (&vid.colorize()).to_line_display()) - .collect(); - - if let Some(query) = search_query { - let mut matcher = Matcher::new(nucleo_matcher::Config::DEFAULT.match_paths()); - - let matches = Pattern::parse( - &query.replace(' ', "\\ "), - CaseMatching::Ignore, - Normalization::Smart, - ) - .match_list(all_video_strings, &mut matcher); - - matches - .iter() - .rev() - .for_each(|(val, key)| println!("{} ({})", val, key)); - } else { - println!("{}", all_video_strings.join("\n")) - } - - Ok(()) -} -- cgit 1.4.1