From 6cf59a167a8e3d97d40f408419cf5ee0d9d86471 Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Tue, 15 Aug 2023 22:37:55 +0200 Subject: [PATCH 1/3] fix: use visitor data for ordered channel videos tests: fix tests --- src/client/channel.rs | 5 +-- src/client/mod.rs | 11 ++++-- .../youtube__music_album_one_artist_intl.snap | 36 +++++++++---------- .../youtube__music_album_various_artists.snap | 4 +-- ...ube__music_album_various_artists_intl.snap | 5 +-- tests/youtube.rs | 24 ++++++++----- 6 files changed, 47 insertions(+), 38 deletions(-) diff --git a/src/client/channel.rs b/src/client/channel.rs index 7ec1be5..7091278 100644 --- a/src/client/channel.rs +++ b/src/client/channel.rs @@ -117,10 +117,7 @@ impl RustyPipeQuery { tab: ChannelVideoTab, order: ChannelOrder, ) -> Result, Error> { - let visitor_data = match tab { - ChannelVideoTab::Shorts => Some(self.get_visitor_data().await?), - _ => None, - }; + let visitor_data = Some(self.get_visitor_data().await?); self.continuation( order_ctoken(channel_id.as_ref(), tab, order), diff --git a/src/client/mod.rs b/src/client/mod.rs index d4e84ad..826919c 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -1563,9 +1563,14 @@ mod tests { fn t_get_visitor_data() { let rp = RustyPipe::new(); let visitor_data = tokio_test::block_on(rp.get_visitor_data()).unwrap(); + + // First part of visitor data must be 22 characters + // Example: CgthVjBVUDJrd2Q3dyi3te-mBg%3D%3D assert!( - visitor_data.ends_with("%3D") && visitor_data.len() == 32, - "got: {visitor_data}" - ); + visitor_data.starts_with("Cg") + && visitor_data.len() > 23 + && &visitor_data[22..23] == "-", + "invalid visitor data: {visitor_data}" + ) } } diff --git a/tests/snapshots/youtube__music_album_one_artist_intl.snap b/tests/snapshots/youtube__music_album_one_artist_intl.snap index 69f594d..5314034 100644 --- a/tests/snapshots/youtube__music_album_one_artist_intl.snap +++ b/tests/snapshots/youtube__music_album_one_artist_intl.snap @@ -22,7 +22,7 @@ MusicAlbum( TrackItem( id: "g0iRiJ_ck48", name: "[name]", - duration: Some(216), + duration: Some(217), cover: [], artists: [ ArtistId( @@ -43,7 +43,7 @@ MusicAlbum( TrackItem( id: "rREEBXp0y9s", name: "[name]", - duration: Some(224), + duration: Some(225), cover: [], artists: [ ArtistId( @@ -64,7 +64,7 @@ MusicAlbum( TrackItem( id: "zvU5Y8Q19hU", name: "[name]", - duration: Some(176), + duration: Some(177), cover: [], artists: [ ArtistId( @@ -85,7 +85,7 @@ MusicAlbum( TrackItem( id: "ARKLrzzTQA0", name: "[name]", - duration: Some(215), + duration: Some(216), cover: [], artists: [ ArtistId( @@ -106,7 +106,7 @@ MusicAlbum( TrackItem( id: "tstLgN8A_Ng", name: "[name]", - duration: Some(268), + duration: Some(269), cover: [], artists: [ ArtistId( @@ -127,7 +127,7 @@ MusicAlbum( TrackItem( id: "k2DjgQOY3Ts", name: "[name]", - duration: Some(202), + duration: Some(203), cover: [], artists: [ ArtistId( @@ -148,7 +148,7 @@ MusicAlbum( TrackItem( id: "azHwhecxEsI", name: "[name]", - duration: Some(185), + duration: Some(186), cover: [], artists: [ ArtistId( @@ -169,7 +169,7 @@ MusicAlbum( TrackItem( id: "_FcsdYIQ2co", name: "[name]", - duration: Some(226), + duration: Some(227), cover: [], artists: [ ArtistId( @@ -190,7 +190,7 @@ MusicAlbum( TrackItem( id: "27bOWEbshyE", name: "[name]", - duration: Some(207), + duration: Some(208), cover: [], artists: [ ArtistId( @@ -211,7 +211,7 @@ MusicAlbum( TrackItem( id: "riD_3oZwt8w", name: "[name]", - duration: Some(211), + duration: Some(212), cover: [], artists: [ ArtistId( @@ -232,7 +232,7 @@ MusicAlbum( TrackItem( id: "8GNvjF3no9s", name: "[name]", - duration: Some(179), + duration: Some(180), cover: [], artists: [ ArtistId( @@ -253,7 +253,7 @@ MusicAlbum( TrackItem( id: "YHMFzf1uN2U", name: "[name]", - duration: Some(218), + duration: Some(219), cover: [], artists: [ ArtistId( @@ -274,7 +274,7 @@ MusicAlbum( TrackItem( id: "jvV-z5F3oAo", name: "[name]", - duration: Some(277), + duration: Some(278), cover: [], artists: [ ArtistId( @@ -295,7 +295,7 @@ MusicAlbum( TrackItem( id: "u8_9cxlrh8k", name: "[name]", - duration: Some(204), + duration: Some(205), cover: [], artists: [ ArtistId( @@ -316,7 +316,7 @@ MusicAlbum( TrackItem( id: "gSvKcvM1Wk0", name: "[name]", - duration: Some(202), + duration: Some(203), cover: [], artists: [ ArtistId( @@ -337,7 +337,7 @@ MusicAlbum( TrackItem( id: "wQHgKRJ0pDQ", name: "[name]", - duration: Some(222), + duration: Some(223), cover: [], artists: [ ArtistId( @@ -358,7 +358,7 @@ MusicAlbum( TrackItem( id: "Ckz5i6-hzf0", name: "[name]", - duration: Some(177), + duration: Some(178), cover: [], artists: [ ArtistId( @@ -379,7 +379,7 @@ MusicAlbum( TrackItem( id: "y5zuUgyFqrc", name: "[name]", - duration: Some(220), + duration: Some(221), cover: [], artists: [ ArtistId( diff --git a/tests/snapshots/youtube__music_album_various_artists.snap b/tests/snapshots/youtube__music_album_various_artists.snap index 59714e0..0a335da 100644 --- a/tests/snapshots/youtube__music_album_various_artists.snap +++ b/tests/snapshots/youtube__music_album_various_artists.snap @@ -126,11 +126,11 @@ MusicAlbum( cover: [], artists: [ ArtistId( - id: None, + id: Some("UChm_d4qO8txdwS4YadlvpSw"), name: "Brave Girls", ), ], - artist_id: None, + artist_id: Some("UChm_d4qO8txdwS4YadlvpSw"), album: Some(AlbumId( id: "MPREb_8QkDeEIawvX", name: "<Queendom2> FINAL", diff --git a/tests/snapshots/youtube__music_album_various_artists_intl.snap b/tests/snapshots/youtube__music_album_various_artists_intl.snap index bff7311..8f3c587 100644 --- a/tests/snapshots/youtube__music_album_various_artists_intl.snap +++ b/tests/snapshots/youtube__music_album_various_artists_intl.snap @@ -1,5 +1,6 @@ --- source: tests/youtube.rs +assertion_line: 1396 expression: album --- MusicAlbum( @@ -126,11 +127,11 @@ MusicAlbum( cover: [], artists: [ ArtistId( - id: None, + id: Some("UChm_d4qO8txdwS4YadlvpSw"), name: "[name]", ), ], - artist_id: None, + artist_id: Some("UChm_d4qO8txdwS4YadlvpSw"), album: Some(AlbumId( id: "MPREb_8QkDeEIawvX", name: "[name]", diff --git a/tests/youtube.rs b/tests/youtube.rs index 0f448de..cc2f1c5 100644 --- a/tests/youtube.rs +++ b/tests/youtube.rs @@ -978,15 +978,10 @@ fn channel_more( } #[rstest] -#[case::videos("UCcdwLMPsaU2ezNSJU1nFoBQ", ChannelVideoTab::Videos, "XqZsoesa55w")] -#[case::shorts("UCcdwLMPsaU2ezNSJU1nFoBQ", ChannelVideoTab::Shorts, "k91vRvXGwHs")] -#[case::live("UCvqRdlKsE5Q8mf8YXbdIJLw", ChannelVideoTab::Live, "ojes5ULOqhc")] -fn channel_order( - #[case] id: &str, - #[case] tab: ChannelVideoTab, - #[case] most_popular: &str, - rp: RustyPipe, -) { +#[case::videos("UCcdwLMPsaU2ezNSJU1nFoBQ", ChannelVideoTab::Videos)] +#[case::shorts("UCcdwLMPsaU2ezNSJU1nFoBQ", ChannelVideoTab::Shorts)] +#[case::live("UCvqRdlKsE5Q8mf8YXbdIJLw", ChannelVideoTab::Live)] +fn channel_order_latest(#[case] id: &str, #[case] tab: ChannelVideoTab, rp: RustyPipe) { let latest = tokio_test::block_on(rp.query().channel_videos_tab_order( id, tab, @@ -1007,7 +1002,18 @@ fn channel_order( } } assert_next(latest, rp.query(), 15, 1); +} +#[rstest] +#[case::videos("UCcdwLMPsaU2ezNSJU1nFoBQ", ChannelVideoTab::Videos, "XqZsoesa55w")] +#[case::shorts("UCcdwLMPsaU2ezNSJU1nFoBQ", ChannelVideoTab::Shorts, "k91vRvXGwHs")] +#[case::live("UCvqRdlKsE5Q8mf8YXbdIJLw", ChannelVideoTab::Live, "ojes5ULOqhc")] +fn channel_order_popular( + #[case] id: &str, + #[case] tab: ChannelVideoTab, + #[case] most_popular: &str, + rp: RustyPipe, +) { let popular = tokio_test::block_on(rp.query().channel_videos_tab_order( id, tab, From d8e3841fb695ef760a950d30841272665d960737 Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Wed, 16 Aug 2023 01:37:20 +0200 Subject: [PATCH 2/3] feat: add channel videos sort by oldest --- src/param/mod.rs | 2 ++ tests/youtube.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) 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")] From 57628d1392e0a4268d74935a05258dd274631dc8 Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Wed, 16 Aug 2023 01:52:39 +0200 Subject: [PATCH 3/3] fix: adjust deobf helper object name regex --- src/client/mod.rs | 6 +----- src/deobfuscate.rs | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/client/mod.rs b/src/client/mod.rs index 826919c..ccb3020 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -1564,12 +1564,8 @@ mod tests { let rp = RustyPipe::new(); let visitor_data = tokio_test::block_on(rp.get_visitor_data()).unwrap(); - // First part of visitor data must be 22 characters - // Example: CgthVjBVUDJrd2Q3dyi3te-mBg%3D%3D assert!( - visitor_data.starts_with("Cg") - && visitor_data.len() > 23 - && &visitor_data[22..23] == "-", + visitor_data.starts_with("Cg") && visitor_data.len() > 23, "invalid visitor data: {visitor_data}" ) } diff --git a/src/deobfuscate.rs b/src/deobfuscate.rs index bc731ee..33cb494 100644 --- a/src/deobfuscate.rs +++ b/src/deobfuscate.rs @@ -152,7 +152,7 @@ fn get_sig_fn(player_js: &str) -> Result { + ";"; static HELPER_OBJECT_NAME_REGEX: Lazy = - Lazy::new(|| Regex::new(r#";([A-Za-z0-9_\$]{2})\...\("#).unwrap()); + Lazy::new(|| Regex::new(r#";([A-Za-z0-9_\$]{2,3})\...\("#).unwrap()); let helper_object_name = HELPER_OBJECT_NAME_REGEX .captures(&deobfuscate_function) .ok_or(DeobfError::Extraction("helper object name"))?