Compare commits

...

3 commits

Author SHA1 Message Date
57628d1392 fix: adjust deobf helper object name regex
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-08-16 01:52:39 +02:00
d8e3841fb6 feat: add channel videos sort by oldest 2023-08-16 01:37:20 +02:00
6cf59a167a fix: use visitor data for ordered channel videos
tests: fix tests
2023-08-15 22:37:55 +02:00
8 changed files with 79 additions and 39 deletions

View file

@ -117,10 +117,7 @@ impl RustyPipeQuery {
tab: ChannelVideoTab, tab: ChannelVideoTab,
order: ChannelOrder, order: ChannelOrder,
) -> Result<Paginator<VideoItem>, Error> { ) -> Result<Paginator<VideoItem>, Error> {
let visitor_data = match tab { let visitor_data = Some(self.get_visitor_data().await?);
ChannelVideoTab::Shorts => Some(self.get_visitor_data().await?),
_ => None,
};
self.continuation( self.continuation(
order_ctoken(channel_id.as_ref(), tab, order), order_ctoken(channel_id.as_ref(), tab, order),

View file

@ -1563,9 +1563,10 @@ mod tests {
fn t_get_visitor_data() { fn t_get_visitor_data() {
let rp = RustyPipe::new(); let rp = RustyPipe::new();
let visitor_data = tokio_test::block_on(rp.get_visitor_data()).unwrap(); let visitor_data = tokio_test::block_on(rp.get_visitor_data()).unwrap();
assert!( assert!(
visitor_data.ends_with("%3D") && visitor_data.len() == 32, visitor_data.starts_with("Cg") && visitor_data.len() > 23,
"got: {visitor_data}" "invalid visitor data: {visitor_data}"
); )
} }
} }

View file

@ -152,7 +152,7 @@ fn get_sig_fn(player_js: &str) -> Result<String, DeobfError> {
+ ";"; + ";";
static HELPER_OBJECT_NAME_REGEX: Lazy<Regex> = static HELPER_OBJECT_NAME_REGEX: Lazy<Regex> =
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 let helper_object_name = HELPER_OBJECT_NAME_REGEX
.captures(&deobfuscate_function) .captures(&deobfuscate_function)
.ok_or(DeobfError::Extraction("helper object name"))? .ok_or(DeobfError::Extraction("helper object name"))?

View file

@ -29,6 +29,8 @@ pub enum ChannelOrder {
Latest = 1, Latest = 1,
/// Order videos with the highest number of views first /// Order videos with the highest number of views first
Popular = 2, Popular = 2,
/// Order videos with the earliest upload date first
Oldest = 4,
} }
impl ChannelVideoTab { impl ChannelVideoTab {

View file

@ -22,7 +22,7 @@ MusicAlbum(
TrackItem( TrackItem(
id: "g0iRiJ_ck48", id: "g0iRiJ_ck48",
name: "[name]", name: "[name]",
duration: Some(216), duration: Some(217),
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
@ -43,7 +43,7 @@ MusicAlbum(
TrackItem( TrackItem(
id: "rREEBXp0y9s", id: "rREEBXp0y9s",
name: "[name]", name: "[name]",
duration: Some(224), duration: Some(225),
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
@ -64,7 +64,7 @@ MusicAlbum(
TrackItem( TrackItem(
id: "zvU5Y8Q19hU", id: "zvU5Y8Q19hU",
name: "[name]", name: "[name]",
duration: Some(176), duration: Some(177),
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
@ -85,7 +85,7 @@ MusicAlbum(
TrackItem( TrackItem(
id: "ARKLrzzTQA0", id: "ARKLrzzTQA0",
name: "[name]", name: "[name]",
duration: Some(215), duration: Some(216),
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
@ -106,7 +106,7 @@ MusicAlbum(
TrackItem( TrackItem(
id: "tstLgN8A_Ng", id: "tstLgN8A_Ng",
name: "[name]", name: "[name]",
duration: Some(268), duration: Some(269),
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
@ -127,7 +127,7 @@ MusicAlbum(
TrackItem( TrackItem(
id: "k2DjgQOY3Ts", id: "k2DjgQOY3Ts",
name: "[name]", name: "[name]",
duration: Some(202), duration: Some(203),
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
@ -148,7 +148,7 @@ MusicAlbum(
TrackItem( TrackItem(
id: "azHwhecxEsI", id: "azHwhecxEsI",
name: "[name]", name: "[name]",
duration: Some(185), duration: Some(186),
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
@ -169,7 +169,7 @@ MusicAlbum(
TrackItem( TrackItem(
id: "_FcsdYIQ2co", id: "_FcsdYIQ2co",
name: "[name]", name: "[name]",
duration: Some(226), duration: Some(227),
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
@ -190,7 +190,7 @@ MusicAlbum(
TrackItem( TrackItem(
id: "27bOWEbshyE", id: "27bOWEbshyE",
name: "[name]", name: "[name]",
duration: Some(207), duration: Some(208),
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
@ -211,7 +211,7 @@ MusicAlbum(
TrackItem( TrackItem(
id: "riD_3oZwt8w", id: "riD_3oZwt8w",
name: "[name]", name: "[name]",
duration: Some(211), duration: Some(212),
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
@ -232,7 +232,7 @@ MusicAlbum(
TrackItem( TrackItem(
id: "8GNvjF3no9s", id: "8GNvjF3no9s",
name: "[name]", name: "[name]",
duration: Some(179), duration: Some(180),
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
@ -253,7 +253,7 @@ MusicAlbum(
TrackItem( TrackItem(
id: "YHMFzf1uN2U", id: "YHMFzf1uN2U",
name: "[name]", name: "[name]",
duration: Some(218), duration: Some(219),
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
@ -274,7 +274,7 @@ MusicAlbum(
TrackItem( TrackItem(
id: "jvV-z5F3oAo", id: "jvV-z5F3oAo",
name: "[name]", name: "[name]",
duration: Some(277), duration: Some(278),
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
@ -295,7 +295,7 @@ MusicAlbum(
TrackItem( TrackItem(
id: "u8_9cxlrh8k", id: "u8_9cxlrh8k",
name: "[name]", name: "[name]",
duration: Some(204), duration: Some(205),
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
@ -316,7 +316,7 @@ MusicAlbum(
TrackItem( TrackItem(
id: "gSvKcvM1Wk0", id: "gSvKcvM1Wk0",
name: "[name]", name: "[name]",
duration: Some(202), duration: Some(203),
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
@ -337,7 +337,7 @@ MusicAlbum(
TrackItem( TrackItem(
id: "wQHgKRJ0pDQ", id: "wQHgKRJ0pDQ",
name: "[name]", name: "[name]",
duration: Some(222), duration: Some(223),
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
@ -358,7 +358,7 @@ MusicAlbum(
TrackItem( TrackItem(
id: "Ckz5i6-hzf0", id: "Ckz5i6-hzf0",
name: "[name]", name: "[name]",
duration: Some(177), duration: Some(178),
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
@ -379,7 +379,7 @@ MusicAlbum(
TrackItem( TrackItem(
id: "y5zuUgyFqrc", id: "y5zuUgyFqrc",
name: "[name]", name: "[name]",
duration: Some(220), duration: Some(221),
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(

View file

@ -126,11 +126,11 @@ MusicAlbum(
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
id: None, id: Some("UChm_d4qO8txdwS4YadlvpSw"),
name: "Brave Girls", name: "Brave Girls",
), ),
], ],
artist_id: None, artist_id: Some("UChm_d4qO8txdwS4YadlvpSw"),
album: Some(AlbumId( album: Some(AlbumId(
id: "MPREb_8QkDeEIawvX", id: "MPREb_8QkDeEIawvX",
name: "Queendom2 FINAL", name: "Queendom2 FINAL",

View file

@ -1,5 +1,6 @@
--- ---
source: tests/youtube.rs source: tests/youtube.rs
assertion_line: 1396
expression: album expression: album
--- ---
MusicAlbum( MusicAlbum(
@ -126,11 +127,11 @@ MusicAlbum(
cover: [], cover: [],
artists: [ artists: [
ArtistId( ArtistId(
id: None, id: Some("UChm_d4qO8txdwS4YadlvpSw"),
name: "[name]", name: "[name]",
), ),
], ],
artist_id: None, artist_id: Some("UChm_d4qO8txdwS4YadlvpSw"),
album: Some(AlbumId( album: Some(AlbumId(
id: "MPREb_8QkDeEIawvX", id: "MPREb_8QkDeEIawvX",
name: "[name]", name: "[name]",

View file

@ -978,15 +978,10 @@ fn channel_more(
} }
#[rstest] #[rstest]
#[case::videos("UCcdwLMPsaU2ezNSJU1nFoBQ", ChannelVideoTab::Videos, "XqZsoesa55w")] #[case::videos("UCcdwLMPsaU2ezNSJU1nFoBQ", ChannelVideoTab::Videos)]
#[case::shorts("UCcdwLMPsaU2ezNSJU1nFoBQ", ChannelVideoTab::Shorts, "k91vRvXGwHs")] #[case::shorts("UCcdwLMPsaU2ezNSJU1nFoBQ", ChannelVideoTab::Shorts)]
#[case::live("UCvqRdlKsE5Q8mf8YXbdIJLw", ChannelVideoTab::Live, "ojes5ULOqhc")] #[case::live("UCvqRdlKsE5Q8mf8YXbdIJLw", ChannelVideoTab::Live)]
fn channel_order( fn channel_order_latest(#[case] id: &str, #[case] tab: ChannelVideoTab, rp: RustyPipe) {
#[case] id: &str,
#[case] tab: ChannelVideoTab,
#[case] most_popular: &str,
rp: RustyPipe,
) {
let latest = tokio_test::block_on(rp.query().channel_videos_tab_order( let latest = tokio_test::block_on(rp.query().channel_videos_tab_order(
id, id,
tab, tab,
@ -1007,7 +1002,18 @@ fn channel_order(
} }
} }
assert_next(latest, rp.query(), 15, 1); 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( let popular = tokio_test::block_on(rp.query().channel_videos_tab_order(
id, id,
tab, tab,
@ -1035,6 +1041,39 @@ fn channel_order(
assert_next(popular, rp.query(), 15, 1); 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] #[rstest]
#[case::not_exist("UCOpNcN46UbXVtpKMrmU4Abx")] #[case::not_exist("UCOpNcN46UbXVtpKMrmU4Abx")]
#[case::gaming("UCOpNcN46UbXVtpKMrmU4Abg")] #[case::gaming("UCOpNcN46UbXVtpKMrmU4Abg")]