diff --git a/src/param/mod.rs b/src/param/mod.rs index 60060bc..884a8c9 100644 --- a/src/param/mod.rs +++ b/src/param/mod.rs @@ -29,6 +29,8 @@ pub enum ChannelOrder { Latest = 1, /// Order videos with the highest number of views first Popular = 2, + /// Order videos with the earliest upload date first + Oldest = 4, } impl ChannelVideoTab { diff --git a/tests/youtube.rs b/tests/youtube.rs index cc2f1c5..6b54b00 100644 --- a/tests/youtube.rs +++ b/tests/youtube.rs @@ -1041,6 +1041,39 @@ fn channel_order_popular( assert_next(popular, rp.query(), 15, 1); } +#[rstest] +#[case::videos("UCcdwLMPsaU2ezNSJU1nFoBQ", ChannelVideoTab::Videos, "P2gDffkC0rY")] +#[case::live("UCvqRdlKsE5Q8mf8YXbdIJLw", ChannelVideoTab::Live, "aW43RH1kQ70")] +fn channel_order_oldest( + #[case] id: &str, + #[case] tab: ChannelVideoTab, + #[case] oldest: &str, + rp: RustyPipe, +) { + let videos = tokio_test::block_on(rp.query().channel_videos_tab_order( + id, + tab, + ChannelOrder::Oldest, + )) + .unwrap(); + + // Check oldest video + assert_eq!(videos.items.first().expect("no videos").id, oldest); + + // Upload dates should be in ascending order + let mut latest_items = videos.items.iter().peekable(); + while let (Some(v), Some(next_v)) = (latest_items.next(), latest_items.peek()) { + if !v.is_upcoming && !v.is_live && !next_v.is_upcoming && !next_v.is_live { + assert_gte( + next_v.publish_date.unwrap(), + v.publish_date.unwrap(), + "oldest video date", + ); + } + } + assert_next(videos, rp.query(), 15, 1); +} + #[rstest] #[case::not_exist("UCOpNcN46UbXVtpKMrmU4Abx")] #[case::gaming("UCOpNcN46UbXVtpKMrmU4Abg")]