From 19820db6d01d0f56808ea9e7eefdacb9a8601f5f Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Fri, 10 Mar 2023 21:56:51 +0100 Subject: [PATCH] feat(cli): add channel search --- cli/src/main.rs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 7e02812..e980dba 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -90,6 +90,9 @@ enum Commands { /// Sort search resulus #[clap(long)] order: Option, + /// Channel ID for searching channel videos + #[clap(long)] + channel: Option, /// YouTube Music search filter #[clap(long)] music: Option, @@ -607,18 +610,28 @@ async fn main() { length, date, order, + channel, music, } => match music { - None => { - let filter = search_filter::SearchFilter::new() - .item_type_opt(item_type.map(search_filter::ItemType::from)) - .length_opt(length.map(search_filter::Length::from)) - .date_opt(date.map(search_filter::UploadDate::from)) - .sort_opt(order.map(search_filter::Order::from)); - let mut res = rp.query().search_filter(&query, &filter).await.unwrap(); - res.items.extend_limit(rp.query(), limit).await.unwrap(); - print_data(&res, format, pretty); - } + None => match channel { + Some(channel) => { + if !rustypipe::validate::channel_id(&channel) { + panic!("invalid channel id") + } + let res = rp.query().channel_search(&channel, &query).await.unwrap(); + print_data(&res, format, pretty); + } + None => { + let filter = search_filter::SearchFilter::new() + .item_type_opt(item_type.map(search_filter::ItemType::from)) + .length_opt(length.map(search_filter::Length::from)) + .date_opt(date.map(search_filter::UploadDate::from)) + .sort_opt(order.map(search_filter::Order::from)); + let mut res = rp.query().search_filter(&query, &filter).await.unwrap(); + res.items.extend_limit(rp.query(), limit).await.unwrap(); + print_data(&res, format, pretty); + } + }, Some(MusicSearchCategory::All) => { let res = rp.query().music_search(&query).await.unwrap(); print_data(&res, format, pretty);