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,
order: ChannelOrder,
) -> Result<Paginator<VideoItem>, 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),

View file

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

View file

@ -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 {

View file

@ -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(

View file

@ -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",

View file

@ -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]",

View file

@ -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,
@ -1035,6 +1041,39 @@ fn channel_order(
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")]